Hello all, I have migrated another production web service over to Nim and 
wanted to share how it turned out. I hope some of you may find this 
interesting. 

#### The Migration

The service I migrated to Nim manages around 100k concurrent mostly long-lived 
WebSocket connections. These WebSocket connections are opened by client apps 
(Android, Windows desktop, etc) and are used to receive realtime events.

I wrote the new WebSocket server using [Mummy](https://github.com/guzba/mummy), 
[Ready](https://github.com/guzba/ready) and 
[JSONy](https://github.com/treeform/jsony). I wasn't quite sure what to expect 
for performance but have been pleasantly surprised.

The new Nim server has now been running for a week now on a single 2 vCPU + 
16GB RAM VM. This VM is behind a load balancer for HTTPS termination, the same 
kind of setup as described in [my previous 
post](https://forum.nim-lang.org/t/9902).

With 100k open WebSocket connections, the new server's CPU and RAM usage are 
both under 10% (~7.5%ish). This is pretty great.

While I don't have 1 million production WebSocket connections to prove it, this 
provides a solid indication that Nim + Mummy can handle 1M+ WebSocket 
connections on a single small VM which is quite cool.

The server is also not just sitting there idle either, every minute over 200k 
messages are sent to clients (most of these are simple heartbeat messages).

Considering this new Nim server has been humming along without any issues for 
the past week I am ready to say the migration has been a success.

#### Thoughts

I have now put Nim and Mummy into production serving both [a lot of HTTP 
request traffic](https://forum.nim-lang.org/t/9902) and a lot of WebSocket 
connections. Since everything has performed really well in both cases it is 
pretty easy to say I am happy with the results I have achieved with Nim.

Why does this matter to you?

  1. Many other languages used for web programming are either not capable of 
handing so many WebSocket connections per VM or have to go to extraordinary 
effort to make it work. This out-of-the-box performance highlights a strength 
of Nim.
  2. If you're learning Nim (or interested in doing so), this provides 
real-world evidence that Nim is capable of exceptional performance for web 
servers too, not just in games or systems programming. Seems smart to me to 
learn a language that can do so much while still having such pleasant syntax.
  3. [Nim 2.0](https://forum.nim-lang.org/t/10051) is very close and for me the 
highlight is ARC/ORC + threads:on as the new defaults. Well, everything written 
above is multi-threaded and compilied with those settings. Having these servers 
running in production for days, weeks and soon months without issue provides 
more proof that Nim's threading capabilities are very real, solid and perhaps 
under-utilized.
  4. It can be hard to know if a programming language or web server or lib or 
whatever is a good choice without real-world testimonials of things actually 
working in production. A demo app and passing some tests are not always enough 
to go on. Does the system last in front of a lot of traffic for months on end? 
That's a very high bar to clear and what I want to prove.



Thanks for giving this a read and good luck with your own Nim adventures.

Reply via email to