X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/1a02f182bb6af0a2034fd7e1c1c938fab61e413f..4e5b08053a5186715368d31bca769d5f02b15b0a:/utils/cron_banip.py?ds=sidebyside diff --git a/utils/cron_banip.py b/utils/cron_banip.py index 55a7b295..ad32b852 100755 --- a/utils/cron_banip.py +++ b/utils/cron_banip.py @@ -65,6 +65,7 @@ BLOCK_LOWER=4000 BLOCK_LOADFAC=380 BULK_LOADFAC=160 BULK_LOWER=1500 +MAX_BULK_IPS=85 # # END OF DEFAULT SETTINGS @@ -106,19 +107,21 @@ 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)) +BLOCK_LIMIT = max(BLOCK_LOWER, BLOCK_UPPER - BLOCK_LOADFAC * (dbload - 75)) BULKLONG_LIMIT = max(BULK_LOWER, BULKLONG_LIMIT - BULK_LOADFAC * (avgload - 14)) +if len(prevbulks) > MAX_BULK_IPS: + BLOCK_LIMIT = max(3600, BLOCK_LOWER - (len(prevbulks) - MAX_BULK_IPS)*10) # get the new block candidates cur.execute(""" SELECT ipaddress, max(count) FROM ((SELECT * FROM - (SELECT ipaddress, sum(case when endtime is null then 1 else 1+date_part('epoch',endtime-starttime) end) as count FROM new_query_log + (SELECT ipaddress, sum(case when endtime is null then 1 else 1+1.5*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 endtime is null then 1 else 1+date_part('epoch',endtime-starttime) end) as count FROM new_query_log + (SELECT ipaddress, count * 3 FROM + (SELECT ipaddress, sum(case when endtime is null then 1 else 1+1.5*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