Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

execute code in rails after response is sent to browser

Using Rails 3.0.7, REE 1.8.7.

I want to run code (specifically, Garbage Collection) in Rails after the response has been sent to the browser.

Is there a way to patch into Rails/Rack/something so that I can call GC.start right after the response is sent to the browser from the controller?

*Note: This is not a situation where I want to use delayed_job or resque. I am aware of those tools already and they are not appropriate for this use case.*

like image 803
Raphael Avatar asked Nov 13 '22 04:11

Raphael


1 Answers

This one-line patch to passenger allows you to run GC between requests. After implementing it, we saw our GC execution time (as reported by NewRelic) drop by about 40%. Individual results may vary. :)

Thanks to this post.

like image 132
Raphael Avatar answered Dec 01 '22 00:12

Raphael