small medium large xlarge

07 May 2017, 07:18
Francesco Biegi (1 post)

Hi to all, i’ve just taken the book days ago and finally a book that show a real example on how to structure code!

I’m very (VERY) new to elixir and maybe this is a stupid question.. I did see all entities are handled by Agent process. The island_set is 10x10 (so 100 unit) and there are other entities like player, island etc handled with Agent.

For example, if the server have 50 active players will be ~approx 6000 “processes?” active at the same time..

Because i come from by other languages i’m asking if have all this processes use a lot of memory/resources..

I know Erlang is born to handle a lot of processes but… mmm.. can really handle all of them?

Sorry again for this question..

07 May 2017, 18:03
Lance Halvorsen (46 posts)

Thanks for your question Francesco!

Don’t worry, the BEAM can handle a very large number of processes. We can set a configurable value for the maximum number of processes the BEAM will handle, but we can set this to a number in the millions. The physical limit has more to do with system resources on the machine you’re running.

One of my favorite exercises in Dave Thomas’ book, Programming Elixir, involves an unusual way to count to one million. First, we spawn a million processes that each receive a number, add one to it, and pass that number along to the next process before terminating. Then we pass zero to the process at the end of the line and see the result as the last process passes its message back.

That whole operation - spawning a million processes and having each one do the addition and pass a message off to the next process - takes about 7 seconds on a laptop.

You must be logged in to comment