How to avoid upstream timeouts?

Just out of curiosity, is there any reason behind? I mean, generally speaking, do you see more performance running Unicorn instead of Puma? I said this because in our case it works fine, easy to deal with it, but never tried Unicorn.

Well, we do run thousands of web processes across a many datacenters so we had to pick a standard.

@sam has deep knowledge of Unicorn internals, we have plugins which expose its internal metrics and have a great relationship with the maintainer too.

6 Likes

That is impossible to answer 100% accurately without a proper A-B test, last thing I want to do is bad-mouth Puma, I also have a great relationship with the Puma maintainers.

What our unicorn setup gives us excellent predictability regarding performance. A unicorn worker can only serve one active (non message bus / non hijacked) request at a time. That means quite a few things in the Ruby world.

  1. Due to global interpreter lock, if you start serving more than 1 request per worker you start bottlenecking on the lock making stuff slower.

  2. If you run lots of requests on a single worker concurrently memory usage can spike and you can bloat Ruby heaps

  3. Only clean way of timing out a request is tearing down a process, unicorn makes this very straight forward and the forking model makes the cost of timing out low.

Unicorn has served us enormously well, and I see no plans to experiment with anything else. That said if memory is super tight I can see an advantage to using puma but the behavior of ā€œlow memoryā€ + ā€œmisbahving appā€ on a single process puma could be very very painful.

7 Likes

Super interesting, many thanks @sam. Itā€™s true there are tons of comparations out there about what app server to choose when Ruby is in between, and as usual, will depend on how familiar is anyone with it, that obviously can tip the balance to make a decision.

Only fear about this is if you will focus your efforts in Unicorn only and exclusively, in the way that Puma wonā€™t be, not useful but Iā€™d say not well adapted to server Discourse in an optimized way.

Iā€™m wondering if anyone have tried with NGINX Unitā€¦

Many thanks guys! :clap:
Ismael

NGINX Unit is not going to work properly until they implement this:

https://github.com/nginx/unit/issues/124

3 Likes