J
J
justed_ss2015-07-30 14:36:30
Ruby on Rails
justed_ss, 2015-07-30 14:36:30

Why doesn't rails release memory?

There is an application, a database with a bunch of data. There is a method in the model that generates a file / json through cunning manipulations and consumption of mountains of memory, and gives the result at the output. The result is returned via the controller method.
The essence of the problem is that the memory is not released.
Even if you do not take into account the curvature of the code and so on, according to my theory, all local variables of the method that are not properties / class variables should sooner or later be destroyed and release memory, but this does not happen.
rails 4.1.4 ruby ​​2.0.0
Tried ruby ​​2.2.2 rails 4.1.12 same result
Tried different web servers( puma, thin, webbriks ), tried killing workers, nothing changes.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Vsk, 2015-07-30
@viktorvsk

Because that's how the vast majority of scripting languages ​​work.
When memory is needed, it is taken from the OS. When the memory is cleared, it is marked as writable, but not given back to the OS
. For such a task, as you described, you should use background task queues: delayed job, resque, sidekiq, rabbitmq ...
By the way, delayed job and, it seems, sidekiq - also will not release memory. They will need to be killed periodically (for example, using monit and a memory limit). Resque creates a new fork for each task

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question