Skip to content

Commit

Permalink
Limit memory useage to 10GB, resp. 1.4 GB for crawler
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Nov 25, 2013
1 parent f43561f commit c85e77e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/util/oddbapp.rb
Expand Up @@ -1394,7 +1394,8 @@ class App < SBSM::DRbServer
CLEANING_INTERVAL = 5*60
EXPORT_HOUR = 2
UPDATE_HOUR = 9
MEMORY_LIMIT = 20480
MEMORY_LIMIT = 10240 # 10 GB
MEMORY_LIMIT_CRAWLER = 1450 # 1,4 GB
RUN_CLEANER = true
RUN_UPDATER = false
SESSION = Session
Expand Down Expand Up @@ -1991,15 +1992,18 @@ def log_size
alarm = time - lasttime > 60 ? '*' : ' '
lastthreads = threads
threads = Thread.list.size
# Shutdown if more than 100 threads are created, probably because of spiders
# Shutdown if more than 200 threads are created, probably because of spiders
if threads > 200
exit
end
lastbytes = bytes
bytes = File.read("/proc/#{$$}/stat").split(' ').at(22).to_i
mbytes = bytes / (2**20)
if mbytes > MEMORY_LIMIT
puts "Footprint exceeds #{MEMORY_LIMIT}MB. Exiting."
puts "Footprint exceeds #{MEMORY_LIMIT}MB. Exiting. Exiting #{status}."
Thread.main.raise SystemExit
elsif /crawler/i.match(status) and mbytes > MEMORY_LIMIT_CRAWLER
puts "Footprint exceeds #{MEMORY_LIMIT_CRAWLER}MB. Exiting #{status}."
Thread.main.raise SystemExit
end
lastsessions = sessions
Expand Down

0 comments on commit c85e77e

Please sign in to comment.