The author contends that Go's "go" (and indeed async blocks in a number of languages) which launch new concurrent objects which the parent block doesn't have to wait for, are a form of badly structured programming.
https://vorpus.org/blog/notes-on-structured-concurrency-or-go-statement-considered-harmful/
https://news.ycombinator.com/item?id=21537706
The structured concurrency described there reminds me of "par" blocks in some languages (Occam, Handel-C, XMOS XC), where each statement inside the block runs in parallel and the whole block waits until all statements inside have completed.They do have asynchronous request/response patterns, but things can't be started and left to carry on running how they want, like you might think of bacteria.
One antidote to unstructured concurrency is to use something like trio in order to make async job spawning a function of a context manager (called nursery in trio) so all job results will be collected when the nursery block ends.
* Automatically reclamation of storage of an unreachable future [Baker and Hewitt 1977] (e.g. process in Erlang). For example, an Erlang process can be orphaned if its Process Identifier becomes inaccessible.
* Language support for holes in the region of mutual exclusion of an Actor implementation. For example, in Erlang it is necessary for application programmers to explicitly code a message handler for each re-entry into the region of mutual exclusion potentially enabling cyberattacks from outside the process.
* Automatic cancellation of requests that have taken too long. For example, in Erlang it is necessary for application programmers to explicitly code a time-out for each message send that might take too long.
Has this ever actually happened? Surely with as many deploys as erlang has, it would have been observed. A casual google search of "orphaned erlang process" shows the parent comment in the top four results, and no other results that mention orphaned erlang processes.
My point about erlang is that it's great precisely because, like all great systems, it doesn't dogmatically adhere to the academic design, and rather makes compromises and is refined by practitioners.
> re-entry into the region of mutual exclusion potentially enabling cyberattacks from outside the process
Typically you run your erlang actors inside of a trusted system. The only way to give untrusted actors access to your system, is explicitly (so no one does it). There are warning signs all over the place around every place where that might happen (for example distributed erlang) and in prod you really really shouldn't deploy distributed erlang without tons of security in depth in a deeply buried vLAN, or, TLS (instructions provided in the standard libs).
The only realistic vectors of attacks on your actor system is by compromising the entry points, like the actors which live to process your TCP or TLS entry points, but you can bet that ericcson has taken a lot of effort to harden those systems and, in fact, the ericcson SSL system was not vulnerable to the Heartbleed attack (despite using OpenSSL) because there are some very smart engineers at ericcson, and also the language generally doesn't have buffer overflows.
BTW, thanks for coming to my stanford ee380 talk a couple of Februaries ago -- unfortunately I wasn't aware of what you looked like, so I didn't get that you were in the audience at the time.
https://papers.ssrn.com/abstract=3428114
PS. You are very welcome. Thanks for your EE380 talk!Determining this property of a program seems to me to be about as hard as the halting problem, since (1) an Erlang process can send its Pid to another process in a message, and (2) the VM/compiler can't tell a priori whether an erlang process will access its own Pid, or even send a message, in the future. I haven't read the paper you linked though, so I'm sure they found a way around this.
It's not well known but what we now call the actor model was pretty widespread in Windows programming in the 1990s. Partly because Visual Basic was like JavaScript: single threaded runtime, no shared memory. To aid developers in exploiting parallelism and using blocking APIs you could create parallel "workers" to use JS terminology (apartments in MS speak), but Windows gave you object oriented RPC between the workers. So it was an RPC layer on top of message passing. You could do asynchronous RPCs if you wanted to:
https://docs.microsoft.com/en-us/windows/win32/rpc/asynchron...
This was used to great effect in rather mundane programs like InstallShield, where the GUI ran in one worker and the install engine ran in an isolated (but in process) world, with the two communicating using RPCs/typed message passing.
Thanks for contributing to the thread, Professor Hewitt.
You are very welcome!
> Automatic cancellation of requests that have taken too long. For example, in Erlang it is necessary for application programmers to explicitly code a time-out for each message send that might take too long.
https://hexdocs.pm/elixir/GenServer.html#call/3
> timeout is an integer greater than zero which specifies how many milliseconds to wait for a reply, or the atom :infinity to wait indefinitely. The default value is 5000. If no reply is received within the specified time, the function call fails and the caller exits.
Likewise, links and monitors are used for lifetime concerns instead of reference counting actors like Pony or using a global tracing collector. This has some advantages and disadvantages but for the most part I personally find it far more practical than other models which are more like the classic actor model.
I.e., what is the interface of a promise?
There are two main operations that can be done with a promise. We can wait for it to complete, and then perform another action when it is complete, known as "when-blocks"; we can also send a message on top of another sent message, informally known as "promise pipelining".
When-blocks:
when (action) -> { doMoreStuff() }
Promise pipelining: promise<-add(4)<-subtract(3)
[0] https://groups.google.com/forum/#!topic/cap-talk/y1bEqOoeswEOn the other hand, a Future [Baker and Hewitt 1977] has the following well defined interface:
Future<t> *interface* resolve[] ↦ tI consider bullet 2 to be a feature of Erlang, not a bug. If a module implements a behavior you know it implements those functions, there's no checking needed. Yes, it increases your attack surface, but outside apps should not be messaging Erlang processes directly.
Bullet 3 seems like sugar. You can wrap the call in your own code that specifies a default timeout.
I'm not saying your concepts are wrong, they are interesting and a more complete/accurate Actor model implementation in Erlang could be a good thing. However, the points you specifically made about Erlang do not seem to me to be needed adds to the language.
Which is exactly what GenServer does. You rarely need to directly send a message to an Erlang process - that is usually done under some abstraction providing the properties that you need.
There is still no credible evidence that the actors system is better than the more traditional way of writing distributed apps, especially now that more and more languages offer an increasing amount of asynchronous approaches.
What do you recommend as a "traditional" way to implement scalable systems?
Very few, really. Maybe you can come up with a few (besides the Ericsson router), but they are a tiny, tiny minority of how we build scalable systems today, and even if some systems are built this way, it's still no evidence that using Akka or Erlang was the best technology.
> What do you recommend as a "traditional" way to implement scalable systems?
I'm not recommending anything, I'm just observing that a crushing majority of scalable systems in use today, reliably serving billions of people and billions of API calls, are built on traditional, imperative technologies (C, C++, Java, C#, JavaScript, etc...).
This past decade, these services have been supplemented by increasingly powerful threading (thread pool, fork join, work stealing, etc...) and asynchronous (coroutines, promises, futures, channels, etc...) approaches.
The actor model has so far completely failed to prove itself as an improvement over these traditional approaches.
I also happen to think the actor model is terrible to debug, deeply violates encapsulation, and often forces developers to forego static typing, but that's more of a personal opinion than an observation.
Yeah, it's a small fraction because it's a rare language, but it's responsible for an outsized number of highly-scalable systems: WhatsApp, several massive ad companies, several massive trading systems, several large analytics companies. Plus most of the production XMPP systems that have been used at scale.
Look, I'm not even an Erlang/Elixir programmer, but it's pretty clearly a great technology for building scalable, fault-tolerant systems.
> I also happen to think the actor model is terrible to debug, deeply violates encapsulation, and often forces developers to forego static typing, but that's more of a personal opinion than an observation.
I mostly work in statically-typed functional programming languages at work, so I'm sympathetic to this complaint. But Erlang has the concept of fail-fast and fault tolerance that make the lack of type safety not as big of a deal as it normally would be.
> But Erlang has the concept of fail-fast and fault tolerance that make the lack of type safety not as big of a deal as it normally would be.
That "fail fast" / "let it crash" thing that Erlang brags about has never been convincing to me. First, because you still need to implement all these supervisors yourself anyway so the complexity is still there. Second, it's an admission that because of its lack of static typing, Erlang developers are just throwing their hands in the air and try to make pass what is a fundamental flaw in the language (that you can't effectively and exhaustively catch errors) as a strength.
Besides, Erlang doesn't have the monopoly on "let it crash": plenty of languages have better ways to catch and recover from errors, either through exceptions or algebraic data types that allow the compiler to make sure you have covered all the error cases.
Have you implemented an erlang/elixir supervisor? It's not hard. It would probably take me about 60 seconds.
> Besides, Erlang doesn't have the monopoly on "let it crash": plenty of languages have better ways to catch and recover from errors, either through exceptions or algebraic data types that allow the compiler to make sure you have covered all the error cases.
Simply handling the error is not the primary reason for "let it crash". The reason for let it crash is to have the remainder of the system continue to make forward progress and with minimal disruption.
I think if anything the greatest thing about let it crash is that I can have a relatively green junior put something into prod without worrying that an uncaught error will bring down the whole system.
Erlang is indeed Smalltalk done right, but, as the OP wrote on the blog, it is not only about messaging and is about the additional constraints.
We've seen REST principles used within a single computer in the AppleScript system and protocol, for example, where you could think of applications running on a single computer as being individual computers in their own right and you need to be able to manipulate them using messages that talk using representations of objects in these applications. For example, "window 1" could be a representation for the first window in an application according to some internal ordering in it.
We also see REST-like interfaces at various system boundaries - for example, addressing textures on a GPU when preparing instructions on the host CPU. Databases too provide tables as resources and produce/consume representations of these tables to perform their functions. So it isn't surprising to see connectors to APIs exposed via ODBC or REST APIs to RDBMS tables as with PostgREST.
So the "InProcess-REST" is in principle understandable as an application architecture pattern, though with the caveat that I haven't gone into the specifics of the OP's work on this (expensive book, etc.).
In contrast to DLLs, shared data, COM+, ActiveX, plugins, and so forth.
Terrific observation. Thank you.
https://github.com/Web-Prolog/swi-web-prolog/raw/master/book...
Quoting from the introduction:
"In particular, we pick the features that make Erlang into an actor programming language, and on top of these we define the concept of a pengine – a programming abstraction in the form of a special kind of actor which closely mirrors the behaviour of a Prolog top-level."
And quoting from Section 1.3 of the current draft:
"Is the actor programming model compatible with the logic programming model, and does the combination of the two models make sense? Yes, we will try to show that the actor programming model of Web Prolog is able to co-exist harmoniously with its logic programming model, and that both models are usable in the same program, with actors used for modelling the reactive, deterministic interfaces to the user and other external entities, and with the non-deterministic component behaving as an actor, encapsulating the non-determinism."
Chapter 3 cites your work directly:
"Actors, as specified in (Hewitt et al., 1973), involve entities that have their own mailbox."
I’m actually working on a compiler/runtime for Erlang for WebAssembly, so I’m maybe more familiar than most with how it works in practice.
True, but with the SharedMemory browser API, things are looking up (but not yet implemented in all major browsers).
SharedArrayBuffer makes communication between schedulers essentially equivalent to non-browser environments, but support for it is still iffy at best due to Spectre. Luckily, that is a temporary problem, not a fundamental issue (SharedArrayBuffer being disabled that is, not Spectre).
In a single-threaded setting, there isn't any significant overhead that I'm aware of between a browser and non-browser environment, aside from any overhead potentially incurred by executing on the WebAssembly VM rather than directly on the host machine. Of course, running single-threaded is less than ideal for other reasons.
If you look at the various histories, it seem like Smalltalk 76 was the point at which the system was made practical, and Smalltalk 80 was a refinement of that. Alan himself has repeatedly said that he was not very happy with that version.
Thus the message passing model in Smalltalk-72 was closely tied to a particular machine model and programming language syntax that did not lend themselves to concurrency. SENDER was retained as part of the message-passing protocol, which is problematical for distributed systems. Also, although the system was bootstrapped on itself, the behavior of language constructs was defined (like Lisp) by an interpreter instead by their response to eval messages.
Actors appeared after I gave a talk at MIT about the very first Smalltalk.
There were several later ideas that were discussed at Parc but not taken up because of the whirl that was already going on. One of these was derived from McCarthy's "fluents" and "situations" (essentially a labeled states/layers idea for allowing concurrencies without race conditions -- this was done very well in David Reed's 1978 MIT thesis.
Another was not waiting for replies. This was in the original set of ideas -- via biology and OS techniques -- but never got implemented in a deep way. The hardware we had at Parc was tiny and Smalltalk was expressive enough to fit a lot into a little.
Another set of ideas that were completely missed appeared in LINDA by Gelernter. This (and the larger ideas around it) are very good ways to deal with larger scalings, etc.
Additional important influences in addition to SmallTalk-72 [Kay November 1972] were Petri nets, Planner [Hewitt 1969], capability systems [Dennis and van Horn], semaphores [Dijkstra], the lambda calculus, and Scott-Strachey semantics failure to integrate everything using the lambda calculus.
1-way message passing is most important for hardware systems in which there is near certainty that a message will be delivered and there is no need to wait for an acknowledgement of receipt.
Smalltalk-71 was never implemented (and never had its design finshed, so there is less that can be claimed about it). But, germane to this discussion, I really liked Carl Hewitt's PLANNER language, and the entire approach to "pattern directed invocation" as he called it -- this was kind of a superset of the later Prolog, and likely influenced Prolog quite a bit.
The PLANNER ideas could be used as the communications part of an object oriented language, and I thought this would be powerful in general, and also could make a big difference in what children could implement in terms of "reasoning systems" (not just imperative action systems).
For Smalltalk-72 I used a much more programmatic approach (Meta II) to recognize messages (that also allowed new syntax/languages to be defined as object protocols (to win the bet) but this was not done comprehensively enough to really use what was great about PLANNER.
There were a few subsequent attempts to combine objects with reasoning, but none of them that I'm aware of were done with end-users in mind.
I thought the subsequent ACTOR work by Carl and his colleagues produced really important theoretical results and designs, most of which we couldn't pragmatically use in the personal computing and interface work on the rather small Xerox Parc personal computers.
[1] Briot, Jean-Pierre. “Actalk: A Testbed for Classifying and Designing Actor Languages in the Smalltalk-80 Environment.” ECOOP (1989).
See the following: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3418003
Also actor systems are fundamentally stateful and don’t mesh well with FP. Are they better than threads? Of course, but it’s a low bar. Hopefully some abstraction will be discovered that offer significant improvement over actors, but I wouldn’t hold my breath. Stuff like futures are great and can solve some problem, but are not general enough to replace actors or threads.
def sum(x: DbInt, y: DbInt) = DbActor.get(x) + DbActor.get(y)
With Akka, none of this is possible. Once actorA received the Sum message, first it would have to send the Get messages to DbObject and update some record indicating I’m waiting for two Get responses while also saving who I’m supposed to send the data to. Then I need to have a big match statement and update the record whenever I get that specific response. Once I finally have received the two responses, I look up where to send my message, and then finally send my SumReturn() message.
It’s a total nightmare and it sucks big-time. A lot of Akka code just ends up being maintaining these large dictionaries keeping track of all the unfinished stuff I eventually need to send various actors when I finally receive all the ingredients.
And it starts to get really bad when you have hierarchical actor structure and one of the terminal actors needs some information held by the top nodes. Then I either need to forward the message up one by one maintaining state along the way, or find the parent of the parent of the parent and send the message directly. And if I do that, now my root actors are talking to everyone else, and the information partitioning advantages of the hierarchy are broken.
There’s one actor topology that really shines though: directed acyclic graphs. If I only send information one way, like a waterfall, actors work really really well. Great for bioinformatics or other ML/data science pipelines.
I don't think this is an Akka-specific thing. I work with NServiceBus, which implements long running processes using database-persisted sagas (sort of state machines), and we have exactly the same situation... NServiceBus even makes these big state-tracking dictionaries explicit (every saga has a corresponding "saga data" object).
I was just listening to this today morning, where I heard Joe mention in the podcast something similar on those lines (though I believe he even mentioned about prolog+concurrency was wat led to Erlang and Plex)
https://softwareengineeringdaily.com/2015/11/02/erlang-with-...
I disagree ...
In the Erlang model the messages are no longer just function calls with single dispatch. Imagine for example that method calls on String values would be asynchronous actor messages. That would be absolutely awful.
OOP isn't just about the actor model. OOP is also about encapsulation and polymorphism. In a static language, we're talking about row or subtyping polymorphism, i.e. methods of "ad hoc polymorphism".
And polymorphism and encapsulation transcend the actor model. I actually really hate the actor model, because asynchrony makes everything harder and actors are too low level, whereas OOP in general is passable as a paradigm in the right context.
> Bacteria continue to metabolize after sending chemical signals to their brethren after all!
I absolutely love the metabolism metaphor but it doesn't map directly to computer programs as we write them today.
Metabolic pathways form an intricate system:
https://upload.wikimedia.org/wikipedia/commons/a/a8/Human_Me...
Glycolysis, for example: starting from glucose at the top, we can follow its decomposition in the cell all the way to the mitochondrion.
This is similar to Unix pipelines. However, on Unix we must manually construct the pipeline:
find ~/notes | grep TODO
In a metabolism-like system, the mere existence of these programs would be enough to provoke computation. I'd write "~/notes" somewhere and the find and grep programs would somehow know the data was meant for them and automatically execute themselves.Enzymes are analogous to programs running in parallel. They are completely independent and don't interface directly with each other. They implement a process just like functions do. However, they don't explicitly call upon each other to perform a task.
Substrates and products are analogous to data of highly specific types. Catalysis occurs when substrate and enzyme come close enough to interact. The enzyme takes the substrate from a shared environment and releases the product into the same environment where the process repeats with other enzymes. This environment is most commonly the cytoplasm.
Enzymes determine whether their substrates are compatible by their chemical structure. This points towards structural typing. When glucokinase phosphorylates glucose, it becomes a different substrate: glucose 6-phosphate. Likewise, when a function adds a property to an object, it's structure changes and so does its type.
For example, let's take the following functions:
f : A -> B
g : B -> C
h : C -> D
In a metabolic system, there is no need to explicitly write code like: a = A(input())
h(g(f(a)))
Rather, they would immediately consume values of type A when they enter the system and the output would be a value of type D in the environment. The computer would fully metabolize data whenever it becomes available and go idle afterwards. As if the programming language's virtual machine was constantly processing all objects in the system: for object in objects:
for function in functions:
if function.argument.type == object.type:
result = function(object)
objects.add(result)
objects.remove(object)
break
It would be like polymerase chain reaction: throw DNA polymerase, nucleotides, some ions, the target DNA and its matching primers in a reaction tube, heat it up in a thermal cycler and the copying will begin happen because all the pieces are in place.1. https://en.wikipedia.org/wiki/Blackboard_system 2. https://en.wikipedia.org/wiki/Blackboard_(design_pattern)
The blackboard model isn't quite accurate though. Chemical signals have spatial locality, propagation delay, and half-lives. An asynchronous, peer-to-peer mesh network of actors would be a closer approximation to the bacterial signal model.
As I see it, It's not, but it’d be a decent platform to build an asynchronous smalltalk on top of. One key thing it is missing is a convenient syntax for defining processes (either via instantiable templates equivalent to “class” in many OOPLs or as singletons equivalent to “object” in Scala) in terms of the message handlers and local state (volatile state of the kind that would be held in the process dictionary and the kind of “transactionally updated” state that, in Erlang, would be carried in function args.)
So the convenient Syntax to define a process is a function declaration. Plus, calling "spawn" to start the process.
Of course, as other responders pointed out, there is also OTP, an established framework (not syntax) to define processes with predefined, battle-tested behaviours.
I think the big thing that Kay missed was asynchronicity. What Kay was thinking of when he coined the term "object oriented" -- rather than C++ -- was a sort of synchronous actor model in which the actor would always wait for a response after sending a message. This maps nicely onto function calls, but considerably more power can be had by letting the actor optionally continue doing stuff while awaiting a response. Bacteria continue to metabolize after sending chemical signals to their brethren after all!
As I've seen it said, Erlang is Smalltalk done right.