A
A
Anton Ivanov2015-07-10 07:03:11
Ruby on Rails
Anton Ivanov, 2015-07-10 07:03:11

How to increase the number of concurrent connections when using unicorn?

Hello.
The server has 4 gigabytes of memory.
worker_processes in the unicorn settings is set to 10, with large values ​​sometimes there are crashes associated with lack of memory.
Let's say that requests are made to the application, there can be 50-200 requests per second. The processing time of one request is about 500 milliseconds. What options are there in this case (besides optimizing the
application? :) ) recently. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
teet, 2015-07-10
@teet

Can be put between the client and the nginx application! Then horizontal scaling is possible.

V
Viktor Vsk, 2015-07-10
@viktorvsk

worker_processes should be set based on the number of processor cores (2 to 1, usually), not memory. In theory, even if you have 100 workers, ideally, each of them should load one core at 100%.
There are a lot of options for increasing RPS, but apart from the general ones that, as you indicated, you already use (caching, optimization), all the rest are completely dependent on the project and code.
Here's a nice article on the options:
merbist.com/2011/02/22/concurrency-in-ruby-explained
In principle, you can also try the simple steps as you wrote: take another web server. For example, start with puma. It should consume much less memory and run in threads. Although, you will hardly notice a big increase in RPS. Then you can try using, say, Rubinius (a really multi-threaded Ruby interpreter) for Puma. But what if.
Thin is unlikely to help here, but why not try - it's a matter of a few minutes.
PS
It should be noted that for a serious application and 200 RPS 4GB - this is usually staging for development.

K
kkrieger, 2015-07-10
@kkrieger

If you do not need to respond to requests in real time, accept the request and put it in the queue, then process it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question