summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-05-03 14:37:48 +0200
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-05-03 18:00:22 +0200
commit9d8fd99811f9c70af7baa74a1b06968b2908c0dd (patch)
treee33e3f91adca38c51570a9235f250c0b54940241
parenta1fd9987e7f88dd71035396115c8ed132797046e (diff)
downloadpykolab-9d8fd99811f9c70af7baa74a1b06968b2908c0dd.tar.gz
Throttle the number of connections
-rw-r--r--wallace/__init__.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/wallace/__init__.py b/wallace/__init__.py
index e018553..2db963e 100644
--- a/wallace/__init__.py
+++ b/wallace/__init__.py
@@ -63,6 +63,9 @@ def worker_process(*args, **kw):
class WallaceDaemon(object):
def __init__(self):
+ self.current_connections = 0
+ self.max_connections = 24
+
daemon_group = conf.add_cli_parser_option_group(_("Daemon Options"))
daemon_group.add_option(
@@ -215,21 +218,29 @@ class WallaceDaemon(object):
if stage.lower() == "defer":
continue
+ self.current_connections += 1
self.pool.apply_async(pickup_message, (filepath, (self.modules), {'module': module, 'stage': stage}))
+ self.current_connections -= 1
continue
+ self.current_connections += 1
self.pool.apply_async(pickup_message, (filepath, (self.modules)))
+ self.current_connections -= 1
try:
while 1:
+ while self.current_connections >= self.max_connections:
+ time.sleep(0.5)
+
pair = s.accept()
log.info(_("Accepted connection"))
if not pair == None:
+ self.current_connections += 1
connection, address = pair
- #print "Accepted connection from %r" % (address)
channel = SMTPChannel(self, connection, address)
asyncore.loop()
+
except Exception, errmsg:
traceback.print_exc()
s.shutdown(1)
@@ -258,6 +269,8 @@ class WallaceDaemon(object):
self.pool.apply_async(pickup_message, (filename, (self.modules)))
+ self.current_connections -= 1
+
return
def reload_config(self, *args, **kw):