]> git.openstreetmap.org Git - rails.git/commitdiff
Increase the hard memory limit and set a lower soft limit that does a
authorTom Hughes <tom@compton.nu>
Sun, 26 Apr 2009 16:56:40 +0000 (16:56 +0000)
committerTom Hughes <tom@compton.nu>
Sun, 26 Apr 2009 16:56:40 +0000 (16:56 +0000)
clean restart between requests.

config/initializers/limits.rb
public/dispatch.fcgi

index 485d95e9c98c03d57547d815c35389ac00215df1..1ce493dfbeaa6dcebd0b91522e2c60ab81c30236 100644 (file)
@@ -1,6 +1,6 @@
-# Limit each rails process to a 512Mb resident set size if possible
+# Set a hard limit of 1Gb on the virtual size of the process
 if Process.const_defined?(:RLIMIT_AS)
-  Process.setrlimit Process::RLIMIT_AS, 640*1024*1024, Process::RLIM_INFINITY
+  Process.setrlimit Process::RLIMIT_AS, 1024*1024*1024, Process::RLIM_INFINITY
 end
 
 # Force a restart after every 10000 requests
index cd76b6113a89ec3192f5543cdd5e9fed61189f70..af8434a76dead81c4d50ba756f9bac3aeec3b662 100755 (executable)
 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! nil, 10