The slowest stars ever recorded

Speed is quite important when trying to predict the future success of NBA prospects, particularly for ball-handlers and wings. Either way, the league still measures speed for participating prospects…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Erlang Concurrency

Concurrency often refers to the same concept as parallelism in other programming languages and other places. However, in Erlang the two are used in a different context, concurrency refers to actors running independently but not at the same time whereas in parallelism the actors run at the same time.

Concepts of Concurrency

Scalability

For this to be made efficient, it makes sense for a process to be started very quickly, destroyed very quickly and be able to switch them really fast. Having them lightweight is mandatory for this to work. And since applications need reliability, the cleanest way to do things is to forbid processes from shared memory.

Shared memory can leave things in an inconsistent state after some crashes (especially on data shared across different nodes) and has some complications. Instead, processes should communicate by sending messages where all the data is copied. This would risk being slower, but safer.

Fault-tolerance

Erlang has been able to full fill the reliability requirement.

The design approach of multiple processes with message passing is a good idea, because error handling could be grafted onto it relatively easily.

Processes-with-asynchronous-messages model, messages are sent from one process to a second one and stored in a mailbox inside the receiving process until they are taken out to be read. It’s important to mention that messages are sent without even checking if the receiving process exists or not because it would not be useful to do so.

As implied in the previous paragraph, it’s impossible to know if a process will crash between the time a message is sent and received. And if it’s received, it’s impossible to know if it will be acted upon or again if the receiving process will die before that.

Asynchronous messages allow safe remote function calls because there is no assumption about what will happen; the programmer is the one to know. If you need to have a confirmation of delivery, you have to send a second message as a reply to the original process. This message will have the same safe semantics, and so will any program or library you build on this principle.

How then do we implement Erlang?

To handle all these potential processes your programs could create, the VM starts one thread per core which acts as a scheduler. Each of these schedulers has a run queue or a list of Erlang processes on which to spend a slice of time. When one of the schedulers has too many tasks in its run queue, some are migrated to another one. This is to say each Erlang VM takes care of doing all the load-balancing and the programmer doesn’t need to worry about it. There are some other optimizations that are done, such as limiting the rate at which messages can be sent on overloaded processes in order to regulate and distribute the load.

That’s my understanding of concurrency, keep it locked.

As you were 😎. Adios!!

Add a comment

Related posts:

Big advances for Democrats in Virginia

One of the states where the Democratic Party did best on November 6 was Virginia, which, each year, is turning from being a “purple” state to a “blue” one. Virginia, population 8 million, entered the…

Just Say No

My thirteen year old daughter absolutely loves young children. We try to visit her cousins (four, five and eight years old) in Yorkshire as often as possible because it’s an absolute win win for…

Lost Corvettes Winners Announced For First Round

The Lost Corvettes were things of automotive lore not too long ago. Stored in relative secrecy in New York City by a reclusive artist who purchased them from the man who won a VH1 giveaway contest…