How Discord Scaled Elixir to 5M Concurrent Users
blog.discordapp.com
How Discord Scaled Elixir to 5M Concurrent Users
1–10 of 260 posts
Re: How Discord Scaled Elixir to 5M Concurrent Users
#2Re: How Discord Scaled Elixir to 5M Concurrent Users
#3Re: How Discord Scaled Elixir to 5M Concurrent Users
#4Re: How Discord Scaled Elixir to 5M Concurrent Users
#5> mochiglobal, a module that exploits a feature of the VM: if Erlang sees a function that always returns the same constant data, it puts that data into a read-only shared heap that processes can access without copying the data
There is a nice new OTP 20.0 optimization - now the value doesn't get copied even on message sends on the local node.
Jesper L. Andersen (jlouis) talked about it in his blog: https://medium.com/@jlouis666/an-erlang-otp-20-0-optimizatio...
> After some research we stumbled upon :ets.update_counter/4
Might not help in this case but 20.0 adds select_replace so can do a full on CAS (compare and exchange) pattern http://erlang.org/doc/man/ets.html#select_replace-2 . So something like acquiring a lock would be much easier to do.
> We found that the wall clock time of a single send/2 call could range from 30μs to 70us due to Erlang de-scheduling the calling process.
There are few tricks the VM uses there and it's pretty configurable.
For example sending to a process with a long message queue will add a bit of a backpressure to the sender and un-schedule them.
There are tons of configuration settings for the scheduler. There is to bind scheduler to physical cores to reduce the chance of scheduler threads jumping around between cores: http://erlang.org/doc/man/erl.html#+sbt Sometimes it helps sometimes it doesn't.
Another general trick is to build the VM with the lcnt feature. This will add performance counters for locks / semaphores in the VM. So then can check for the hotspots and know where to optimize:
Re: How Discord Scaled Elixir to 5M Concurrent Users
#6Re: How Discord Scaled Elixir to 5M Concurrent Users
#7Re: How Discord Scaled Elixir to 5M Concurrent Users
#8I so appreciate write ups that get into details of microsecond size performance gains at that scale. It's a huge help for the community.
Re: How Discord Scaled Elixir to 5M Concurrent Users
#9FastGlobal in particular looks like it nicely solves a problem I've manually had to work around in the past. I'll probably be pulling that into our codebase soon.
Re: How Discord Scaled Elixir to 5M Concurrent Users
#10[0] https://github.com/elixir-lang/elixir/releases/tag/v1.0.0