From 9912b6e3c31679294189794db1bfa71c7e5fdc0e Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Wed, 27 Mar 2013 22:23:13 +0100 Subject: [PATCH] handle spikes in load more gracefully --- utils/cron_banip.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/utils/cron_banip.py b/utils/cron_banip.py index af443444..54b7ae8c 100755 --- a/utils/cron_banip.py +++ b/utils/cron_banip.py @@ -61,8 +61,10 @@ BULKCOOLOFF_PERIOD='15 min' BULKLONG_LIMIT=8000 BULKSHORT_LIMIT=2000 BLOCK_UPPER=19000 +BLOCK_LOWER=4000 BLOCK_LOADFAC=300 BULK_LOADFAC=100 +BULK_LOWER=1500 # # END OF DEFAULT SETTINGS @@ -75,7 +77,7 @@ except IOError: # determine current load fd = open("/proc/loadavg") -avgload = int(float(fd.readline().split()[1])) +avgload = int(float(fd.readline().split()[2])) fd.close() # read the previous blocklist @@ -102,8 +104,8 @@ except IOError: # current number of bulks numbulks = len(prevbulks) -BLOCK_LIMIT = BLOCK_UPPER - BLOCK_LOADFAC * (numbulks - 30) -BULKLONG_LIMIT = BULKLONG_LIMIT - BULK_LOADFAC * (avgload - 16) +BLOCK_LIMIT = max(BLOCK_LOWER, BLOCK_UPPER - BLOCK_LOADFAC * (numbulks - 27)) +BULKLONG_LIMIT = max(BULK_LOWER, BULKLONG_LIMIT - BULK_LOADFAC * (avgload - 14)) conn = psycopg2.connect('dbname=nominatim') cur = conn.cursor() @@ -112,12 +114,12 @@ cur = conn.cursor() cur.execute(""" SELECT ipaddress, max(count) FROM ((SELECT * FROM - (SELECT ipaddress, sum(CASE WHEN type = 'search' THEN 3 ELSE 1 END) as count FROM new_query_log + (SELECT ipaddress, sum(case when endtime is null then 1 else 1+date_part('epoch',endtime-starttime) end) as count FROM new_query_log WHERE starttime > now() - interval '1 hour' GROUP BY ipaddress) as i WHERE count > %s) UNION (SELECT ipaddress, count * 4 FROM - (SELECT ipaddress, sum(CASE WHEN type = 'search' THEN 2 ELSE 1 END) as count FROM new_query_log + (SELECT ipaddress, sum(case when endtime is null then 1 else 1+date_part('epoch',endtime-starttime) end) as count FROM new_query_log WHERE starttime > now() - interval '10 min' GROUP BY ipaddress) as i WHERE count > %s)) as o GROUP BY ipaddress -- 2.39.5