Increase the hard memory limit and set a lower soft limit that does a
clean restart between requests.
This commit is contained in:
parent
aadb91861a
commit
1bd3710134
2 changed files with 29 additions and 3 deletions
|
@ -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)
|
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
|
end
|
||||||
|
|
||||||
# Force a restart after every 10000 requests
|
# Force a restart after every 10000 requests
|
||||||
|
|
|
@ -21,4 +21,30 @@
|
||||||
require File.dirname(__FILE__) + "/../config/environment"
|
require File.dirname(__FILE__) + "/../config/environment"
|
||||||
require 'fcgi_handler'
|
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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue