X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/aadb91861a50623ac616dc757e49254ac6bf6f81..b99227b808e610429c7318c8b6f562d7833977f7:/public/dispatch.fcgi?ds=sidebyside diff --git a/public/dispatch.fcgi b/public/dispatch.fcgi index cd76b6113..3a13f230c 100755 --- a/public/dispatch.fcgi +++ b/public/dispatch.fcgi @@ -21,4 +21,29 @@ require File.dirname(__FILE__) + "/../config/environment" require 'fcgi_handler' -RailsFCGIHandler.process! nil, 10 +class OpenStreetMapFCGIHandler < RailsFCGIHandler +protected + def process_request(cgi) + # Call superclass to process the request + super + + # Restart if we've hit our memory limit + if resident_size > 512 + dispatcher_log :info, "restarting due to memory limit" + restart! + end + end + + def resident_size + # Read statm to get process sizes. Format is + # Size RSS Shared Text Lib Data + fields = File.open("/proc/self/statm") do |file| + fields = file.gets.split(" ") + end + + # Return resident size in megabytes + return fields[1].to_i / 256 + end +end + +OpenStreetMapFCGIHandler.process!