X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/73fdf5fae2755ba8c0170ff4b7ebce0aab5c08a4..f049decca2ccbbf91515d894962ae1fbfb40531e:/utils/cron_banip.py diff --git a/utils/cron_banip.py b/utils/cron_banip.py index 4cc50fc5..af443444 100755 --- a/utils/cron_banip.py +++ b/utils/cron_banip.py @@ -62,6 +62,7 @@ BULKLONG_LIMIT=8000 BULKSHORT_LIMIT=2000 BLOCK_UPPER=19000 BLOCK_LOADFAC=300 +BULK_LOADFAC=100 # # END OF DEFAULT SETTINGS @@ -77,8 +78,6 @@ fd = open("/proc/loadavg") avgload = int(float(fd.readline().split()[1])) fd.close() -BLOCK_LIMIT = BLOCK_UPPER - BLOCK_LOADFAC * avgload - # read the previous blocklist WHITELIST = set(WHITELIST.split()) if WHITELIST else set() prevblocks = [] @@ -100,6 +99,12 @@ try: except IOError: pass #ignore non-existing file +# current number of bulks +numbulks = len(prevbulks) + +BLOCK_LIMIT = BLOCK_UPPER - BLOCK_LOADFAC * (numbulks - 30) +BULKLONG_LIMIT = BULKLONG_LIMIT - BULK_LOADFAC * (avgload - 16) + conn = psycopg2.connect('dbname=nominatim') cur = conn.cursor() @@ -107,7 +112,7 @@ cur = conn.cursor() cur.execute(""" SELECT ipaddress, max(count) FROM ((SELECT * FROM - (SELECT ipaddress, sum(CASE WHEN type = 'search' THEN 2 ELSE 1 END) as count FROM new_query_log + (SELECT ipaddress, sum(CASE WHEN type = 'search' THEN 3 ELSE 1 END) as count FROM new_query_log WHERE starttime > now() - interval '1 hour' GROUP BY ipaddress) as i WHERE count > %s) UNION @@ -177,6 +182,7 @@ if debulkcandidates: cur.execute(""" SELECT DISTINCT ipaddress FROM new_query_log WHERE ipaddress IN ('%s') AND starttime > now() - interval '%s' + AND starttime > date_trunc('day', now()) """ % ("','".join(debulkcandidates), BULKCOOLOFF_PERIOD)) for c in cur: