There is a Rails 5.0.0 project in which there are a lot of tasks. All these tasks are associated with both simple updating of data in the database and parsing.

Almost 20 additional gems are registered in the Gemfile. Anyway, they take part in the project somewhere.

All this is on a server with 1Gb RAM and 1 CPU.

When Rails Tasks are not running (by the way, they are started by CRON), then the application lives to itself normally. But as soon as one, two or even three tasks start (not necessarily at the same time, it is enough that their work intersects), then the RAM quickly ends, the processes start to be killed by the system, and so on.

In principle, this problem solves SWAP. But there is one BUT - the project and the task begin to blunt. They are very slow.

Now to the point.

I wrote above about ~ 20 gem project. And after all, all these gems are also used by tasmas, even if they are not needed there, right? How to specify your personal Gemfile (list of gems) for tasks, so that tasks do not eat so much RAM (or else one task can safely take RAM as a Rails project)?

I think I have made my situation more clear.

    1 answer 1

    Look at the SWAP files as a серебряную пулю не стоит . Everything starts to slow down when you turn on swap because the memory is clogged and written to disk, which is why there is not enough memory for the remaining resources. We must look where the memory goes. It is worth thinking about integrated application optimization and monitoring. The number of gems is not an indicator, maybe 40. It would be nice, of course, to take a look at the Gemfile itself.

    • In such a situation, it is worthwhile to think that it would be good to spread gems around the group test, develpment , which are always available, which can be transferred.
    • To see that Cron / Jobs / Workers are correctly launched, we must not forget that the Id of the entity must be passed to the worker, which we will process in another process.
    • It is worth thinking of using redis for asynchronous tasks, so as not to water the base once again, radish is light and doesn’t eat much.
    • Of course you shouldn't forget about the simple optimization of N + 1 queries, the number of pool
    • And for good, I would also advise you to try Puma server with setting up workers and threads 2 to 2, which is more optimal. Yet the puma thread does and not fork the application.