lamtrhieu

lamtrhieu

Concurrency vs asynchronous?

Hi everyone,

I am still having a hard time to understand the difference between concurrency and asynchronous.
I have asked the question about how we can achieve highly concurrency in elixir here and all the answers really helps a lot.
But, I recently view the presentation about modern java non-blocking library like Reactor or RxJava. I think they are non-blocking java library and helps to use resource more efficiently and asynchronously.
My understanding about reactor is as follow:

  • They also use 1 thread for each cpu cores
  • Use event loop mechanism, ie. when there’s a request come in, they do the book keeping (register request and its callback) and move it to the waiting queue so that the system can continue serving more request. When there’s result comeback then the callback is put in the event queue and processed by event loop.

So basically I think it was also like elixir where one scheduler thread run processes when needed ?

So I think reactor is also highly concurrent if the “task” is IO-bound ? And in this case, elixir and java reactive library is the same ?

And elixir only prove more concurrency when the “task” is cpu-bound ? I am still not sure how the event loop will behave in that situation because I think the code in the callback should be very quick to avoid blocking the entire system.

Another question is that library like reactor support the reactive streams specification. I also read in one of the blog post saying that otp which is based on actor model is also provide built-in support for reactive streams. Can you help to explain that ?

I would appreciate your feedback on this questions. Thank you so much?

Most Liked

ityonemo

ityonemo

I have not used java in a long time. If java reactor works the way you say it does, it is in many ways similar to elixir. But I think the difference is this: Elixir is designed from the bottom up to work with its “event loop”. If you write a long function in elixir, the system knows exactly where to interrupt this function and move on to work on another function. Can you say the same for Java? Can you say with confidence that whatever mechanism reactor uses to decide when to take control away from one task plays nicely with the entire JVM ecosystem?

OTP is not based on the actor model, but it looks a lot like the actor model. It’s so close that it’s often “good enough” to think about it that way. But it’s important to remember, the actor model was designed as a way to organize your code, and erlang processes were designed as a way to organize your failure domains. These are different in very important ways. If you try too hard to follow the traditional actor model in your BEAM program design, you are very likely to wind up with bottlenecks. If you don’t care about bottlenecks (which you don’t need to for some tasks), then that might be okay too (I watched a fantastic talk by Laura Castro where she designed a very actor- heavy system, and you know what, it was totally fine, for her purposes). There aren’t any absolute answers. Sometimes the JVM is going to be better than the BEAM, but I personally wouldn’t want to spend my time coding in the JVM.

Maybe one way to put it is this: I write code in the BEAM because I care about my customers and I like to sleep soundly at night =D. There is no way to measure that.

Where Next?

Popular in Questions Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New

Other popular topics Top

albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New

We're in Beta

About us Mission Statement