From 1a02f182bb6af0a2034fd7e1c1c938fab61e413f Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Wed, 27 Mar 2013 23:29:48 +0100 Subject: [PATCH] use db load for blocks --- utils/cron_banip.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/utils/cron_banip.py b/utils/cron_banip.py index 54b7ae8c..55a7b295 100755 --- a/utils/cron_banip.py +++ b/utils/cron_banip.py @@ -62,8 +62,8 @@ BULKLONG_LIMIT=8000 BULKSHORT_LIMIT=2000 BLOCK_UPPER=19000 BLOCK_LOWER=4000 -BLOCK_LOADFAC=300 -BULK_LOADFAC=100 +BLOCK_LOADFAC=380 +BULK_LOADFAC=160 BULK_LOWER=1500 # @@ -75,11 +75,6 @@ try: except IOError: pass -# determine current load -fd = open("/proc/loadavg") -avgload = int(float(fd.readline().split()[2])) -fd.close() - # read the previous blocklist WHITELIST = set(WHITELIST.split()) if WHITELIST else set() prevblocks = [] @@ -101,14 +96,18 @@ try: except IOError: pass #ignore non-existing file -# current number of bulks -numbulks = len(prevbulks) - -BLOCK_LIMIT = max(BLOCK_LOWER, BLOCK_UPPER - BLOCK_LOADFAC * (numbulks - 27)) -BULKLONG_LIMIT = max(BULK_LOWER, BULKLONG_LIMIT - BULK_LOADFAC * (avgload - 14)) - +# determine current load +fd = open("/proc/loadavg") +avgload = int(float(fd.readline().split()[2])) +fd.close() +# DB load conn = psycopg2.connect('dbname=nominatim') cur = conn.cursor() +cur.execute("select count(*)/60 from new_query_log where starttime > now() - interval '1min'") +dbload = int(cur.fetchone()[0]) + +BLOCK_LIMIT = max(BLOCK_LOWER, BLOCK_UPPER - BLOCK_LOADFAC * (dbload - 70)) +BULKLONG_LIMIT = max(BULK_LOWER, BULKLONG_LIMIT - BULK_LOADFAC * (avgload - 14)) # get the new block candidates cur.execute(""" -- 2.39.5