Erlang-style Concurrency for Other Languages

2019-01-31 13:54发布

问题:

What libraries exist for other programming languages to provide an Erlang-style concurrency model (processes, mailboxes, pattern-matching receive, etc.)?

Note: I am specifically interested in things that are intended to be similar to Erlang, not just any threading or queueing library.

回答1:

Message Passing Interface (MPI) (http://www-unix.mcs.anl.gov/mpi/) is a highly scalable and robust library for parallel programming, geared original towards C but now available in several flavors http://en.wikipedia.org/wiki/Message_Passing_Interface#Implementations. While the library doesn't introduce new syntax, it provides a communication protocol to orchestrate the sharing of data between routines which are parallelizable.

Traditionally, it is used in large cluster computing rather than on a single system for concurrency, although multi-core systems can certainly take advantage of this library.

Another interesting solution to the problem of parallel programming is OpenMP, which is an attempt to provide a portable extension on various platforms to provide hints to the compiler about what sections of code are easily parallelizable.

For example (http://en.wikipedia.org/wiki/OpenMP#Work-sharing_constructs):

#define N 100000
int main(int argc, char *argv[])
{
  int i, a[N];
  #pragma omp parallel for
  for (i=0;i<N;i++) 
     a[i]= 2*i;
  return 0;
}

There are advantages and disadvantages to both, of course, but the former has proven to be extremely successful in academia and other heavy scientific computing applications. YMMV.



回答2:

Ulf Wiger had a great post recently on this topic - here are the properties he defines as required before you can call something "Erlang Style Concurrency":

  • Fast process creation/destruction
  • Ability to support >> 10 000 concurrent processes with largely unchanged characteristics.
  • Fast asynchronous message passing.
  • Copying message-passing semantics (share-nothing concurrency).
  • Process monitoring.
  • Selective message reception.

Number 2 above is the hardest to support in VMs and language implementations that weren't initially designed for concurrency. This is not to knock Erlang-ish concurrency implementations in other languages, but a lot of Erlang's value comes from being able to create millions of processes, which is pretty damn hard if the process abstraction has a 1-1 relationship with an OS-level thread or process. Ulf has a lot more on this in the link above.



回答3:

Scala supports actors. But I would not call scala intentionally similar to Erlang.

Nonetheless scala is absolutely worth taking a look!



回答4:

Microsoft Concurrency and Coordination Runtime for .NET.

The CCR is appropriate for an application model that separates components into pieces that can interact only through messages. Components in this model need means to coordinate between messages, deal with complex failure scenarios, and effectively deal with asynchronous programming.



回答5:

Also kilim is a library for java, that brings erlang style message passing/actors to the Java language.



回答6:

Mike Rettig created a .NET library called Retlang and a Java port called Jetlang that is inspired by Erlang's concurrency model.



回答7:

Microsoft's Not-Production-Ready Answer to Erlang: Microsoft Axum



回答8:

For python you can try using processing module.



回答9:

Termite for Gambit Scheme.



回答10:

If you are using Ruby, take a look at Revactor: [http://revactor.org/][1]

Revactor is an Actor model implementation for Ruby 1.9 built on top of the Rev high performance event library. Revactor is primarily designed for writing Erlang-like network services and tools.

Take a look at this code sample:

  myactor = Actor.spawn do
    Actor.receive do |filter|
      filter.when(:dog) { puts "I got a dog!" }
    end
  end

Revactor only runs on Ruby 1.9. I believe the author of the library has discontinued maintaining it but the documentation on their site is very good.

You might also want to take a look at Reia: a ruby-like scripting language built on top of the Erlang VM. Reia is the new project of the creator of Revactor: Tony Arcieri.



回答11:

Warning: shameless plug!

I developed a library for this kind of message passing in Haskell: Erlang-style Distributed Haskell.

Volker



回答12:

JoCaml extends OCaml with join calculus for concurrent and distributed programming.



回答13:

Akka (http://akka.io) is heavily influenced by erlangs OTP. It has built on scala's actors and is great for concurrency on the JVM.