3 ms·
Elixir has concurrency built in as an easy to use concept. There is the concept of processes running within the runtime, which is called the BEAM. Think of the
by mattbrewsbytes 5y ago
Elixir has concurrency built in as an easy to use concept. There is the concept of processes running within the runtime, which is called the BEAM. Think of the runtime as a mini OS where you can create lightweight processes as needed to do things asynchronously. You can use a simple Task module[0] to do things async or implement GenServer[1] which is a process running and has state.
An example is calling an API that has a paginated response where it indicates the number of pages (like ?page=X in GET request), you can async call each page and accumulate the responses using a map_reduce function[2]. You could fire up like 1000 (or 10k or as many as you like really) of these processes calling an API with different params/creds and handling paginated responses concurrently, each with their own state. I found that Elixir will let you quickly exhaust any rate limit budget/threshold you have in a scenario like this, that is more the limiting factor.
[0] https://hexdocs.pm/elixir/1.13.4/Task.html https://hexdocs.pm/elixir/1.13.4/Task.html
[1] https://hexdocs.pm/elixir/1.13.4/GenServer.html https://hexdocs.pm/elixir/1.13.4/GenServer.html
[2] https://hexdocs.pm/elixir/1.13.4/Enum.html#map_reduce/3 https://hexdocs.pm/elixir/1.13.4/Enum.html#map_reduce/3
- nrdvana 4y agoThis answer is growing on me. My first reaction was "well that's not really what I meant", but actually my question could have been phrased as "I want to use one-process-per-logical-task design, but this is too heavyweight, so I want a solution designed around (lightweight process technical details)" and your answer is basically "Elixir and Erlang have lightweight processes allowing you to use one process per logical task". It doesn't really matter if it's using the exact technical details I specified; it has one process per task, and therefore no library fragmentation because that basic design scales well.