Elixir’s main selling point is concurrency,what are some of the practical examples where concurrency wins?
Thank you !!
Elixir’s main selling point is concurrency,what are some of the practical examples where concurrency wins?
Thank you !!
Wins over what? Doing things sequentially? If so, do you really need examples?
But the strengths of elixir is not only concurrency, it’s fault tolerance as well, which comes because of the wonderful OTP framework.
So concurrency is doing things at the same time…so elixir can do different things at the same time via OTP?
Yes, concurrency is doing different things at the same time.
OTP is built on top of that and some BEAM-built-ins that let you easily monitor other (BEAM) processes. Basically OTP abstracts away the main building blocks of concurrency, the processes. It adds supervision of those processes (and even other supervisors [which are itself processes]) on top. And this is what makes it so fault tollerant.
If there were no concurrency, we were not able to do this kind of supervision.
But still, I do not really get your original question, what do you want to know what were “concurrency winning against”?
You can have a look at Task when You want to do multiple things at the same time. A common use case example is web scrapping.
As a noobie …im overwhelmed about how every programming want to have concurrent features…be it java (java8), scala ,ruby …i mean even earlier the code used to work before people started giving concurrency a serious thought …right ? …so i wanted to know what problems of today can concurrency solve ?
Thank you ! You pattern-matching, process building atoms !!!
Two tasks
If A has to complete before B can begin then only sequential processing is possible (single-tasking)
AAAAAAAAAABBBBBBBBBBBBBBB
Total: 25 secs
If A and B are independent then concurrent processing is possible (multi-tasking)
ABABABABABABABABABABBBBBB
Total: 25 secs
Sequential A B on 2 cores (parallel)
Concurrent A B on 2 cores (parallel)
Concurrency in Elixir:
Kernel.spawn/3
and the like.Kernel.send/2
a message to another process.Kernel.receive/1
a message from another process.defprotocol
).Also see: Programming Erlang 2e, Sample Chapter 1: 1.2 Benefits of Concurrency (page 8)
Great stuff!