from Hacker News

Using Rust to scale Elixir for 11M concurrent users (2019)

by i0exception on 8/15/22, 11:30 PM with 5 comments

  • by drunkenmagician on 8/16/22, 3:16 AM

  • by nicoburns on 8/16/22, 3:23 AM

    Rust really shines for FFI use cases. You get all the same performance benefits you would get with C, but:

    - It’s a safe language so you don’t have to worry about crashing your program or introducing UB.

    - You don’t have to deal with the pain of C compiler toolchains. Need you’re code to work on multiple platforms? It will likely just work out of the box.

    - It has a lot better abstraction capabilities than C, so you get a higher level interface to the host objects.

    - It has a great package ecosystem which you can take advantage of. Sometimes your native module could be as simple as exposing a few methods from a prewritten library.

    Once you go down this road, it can be very tempting to write the whole thing in Rust (which can work well too), but if you’ve got an existing code base, or some higher level code you want to keep in a more flexible language, then I think the Rust + scripting language of choice combo is hard to beat.

  • by RcouF1uZ4gsC on 8/16/22, 1:44 AM

    > and using the guarantees of Rust is guaranteed not to crash the VM or leak memory.

    Very interesting article.

    However, I do no think that Rust guarantees not to leak memory. It guarantees to double frees or dangling pointers, but it does not guarantee no leaks. One example would be making a cycle using Rc.

  • by anko on 8/16/22, 10:40 AM

    i'd love to know the operations they were doing and what they used the sorted sets for. I find for this type of thing, if the ids of the users are integers you can often use a bitset and optimise the crap out of it via SIMD. If memory is a huge concern, or if the data is super sparse you can use a roaring bitset.