From: Eric S. Raymond Date: Fri, 28 Sep 2012 19:21:30 +0000 (-0400) Subject: Prevent empty-queue check from eating the CPU. X-Git-Tag: 1.1~3 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4d040db8a6ce6d889d1d8179b308ff310fb3bb21;p=irker.git Prevent empty-queue check from eating the CPU. --- diff --git a/BUGS b/BUGS index 44b5100..12564e5 100644 --- a/BUGS +++ b/BUGS @@ -1,13 +1,4 @@ KNOWN BUGS -We apologize for the rough edges on this software. The initial release -was somewhat rushed by the sudden death of cia.vc in late September 2012; -a replacement needed to be fielded immediately. - -* Testing has been minimal. - -* There is one report of unexplainedly high CPU usage by irkerd when - processing UDP requests. - * Despite what the header comment implies, the URL prefix and message template in irkerhook.py can at present only be modified by hacking the script. diff --git a/NEWS b/NEWS index 8ab0826..d6014ce 100644 --- a/NEWS +++ b/NEWS @@ -3,4 +3,7 @@ 1.0 @ 2012-09-27 First production version, somewhat rushed by the sudden death of cia.vc. +1.1 @ 2012-09-28 + Add a delay to avoid threads spinning on the empty-queue-check, eating CPU. + diff --git a/README b/README index 2f151d0..54b8553 100644 --- a/README +++ b/README @@ -15,7 +15,7 @@ and passes them to a local irker instance. Find it here: https://github.com/nenolod/irker-cia-proxy -Due to the abrupt death of cia.vc in late September 2012 the +Due to the abrupt death of cia.vc on September 24 2012 the initial release of this software was a bit rushed. See the file BUGS for known problems. diff --git a/irkerd b/irkerd index 3187e7f..905c12d 100755 --- a/irkerd +++ b/irkerd @@ -34,6 +34,7 @@ DISCONNECT_TTL = (24 * 60 * 60) # Time to live, seconds from last connect UNSEEN_TTL = 60 # Time to live, seconds since first request CHANNEL_MAX = 18 # Max channels open per socket (default) ANTI_FLOOD_DELAY = 0.125 # Anti-flood delay after transmissions, seconds +ANTI_BUZZ = 0.09 # Anti-buzz delay after queue-empty check # No user-serviceable parts below this line @@ -41,7 +42,7 @@ import sys, json, getopt, urlparse, time import threading, Queue, SocketServer import irc.client, logging -version = "1.0" +version = "1.1" # Sketch of implementation: # @@ -152,6 +153,13 @@ class Connection: self.connection.close() self.connection = None self.status = "disconnected" + else: + # Prevent this thread from hogging the CPU by pausing + # for just a little bit after the queue-empty check. + # As long as this is less that the duration of a human + # reflex arc it is highly unlikely any human will ever + # notice. + time.sleep(ANTI_BUZZ) elif self.status == "disconnected" \ and time.time() > self.last_xmit + DISCONNECT_TTL: # Queue is nonempty, but the IRC server might be down. Letting