Question

I was pretty sure, that all Rack application servers (I had some experience with Unicorn and Passenger) were creating single process for every worker when they were created, and its state was "frozen".

Whenever app server receives request to handle, it forks from the master process and all further changes to forked process are separated from the original process. They benefit from copy-on-write optimizations and are safe to be "damaged" by processing request. All changes to the environment affect only single process that will be preempted anyway.

If my vision of RoR application stack was true, there should be almost no need of garbage collection, unless serving single request would take a lot of time and memory (which usually is not the case).

On the other hand, question about GC measurements done with NewRelic and it's answers led me to conclusion that I must be completely wrong.

Can someone clarify this process?

Was it helpful?

Solution

Rack applications servers are not forking at each request, only during initialization:

  1. First, the environment is loaded in one process
  2. Then, the server fork several workers
  3. Then all requests are distributed among these processes

That's why the Garbage collector is used to keep each process memory clean & stable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top