Hello, I would like to introduce some traffic priority in Unicorn. The goal is to keep critical endpoints online even if the application is slowing down a lot.
The idea is to classify the request at nginx level (by vhost, http path, header or whatever), and send the queries to two different unicorn sockets (opened by the same unicorn instance): one for high priority request, one for low priority request. I need to do some small modifications [1] in the unicorn worker loop to process high priority requests first. It seems to work: - I launch a first apache bench toward the low priority port - I launch a second apache bench toward the high priority port - Unicorn handles the queries only for that one, and stop answering to the low priority traffic The tradeoff are - No more "bet"[2] on low priority traffic. This is probably slowing down a little bit the low priority traffic. - This approach is only low / high. Not sure if I can extend it for 3 (or more) level of priority without a non negligible performance impact (because of the "bet" above). Do you think this approach is correct? Do you have any better idea to have some traffic prioritization? (Another idea is to have dedicated workers for each priority class. This approach has other downsides, I would like to avoid it). Is it something we can introduce in Unicorn (not as default behaviour, but as a configuration option)? Thx for any opinion. Bertrand [1] https://github.com/bpaquet/unicorn/commit/58d6ba2805d4399f680f97eefff82c407e0ed30f# [2] https://bogomips.org/unicorn.git/tree/lib/unicorn/http_server.rb#n707
