From c751cc97dbcc2645d1a2484c1078ad4f143e299a Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 14 Nov 2012 16:02:56 -0500 Subject: [PATCH] zephyr_mirror: Send Humbugs in child processes. This improves the throughput of mirroring a large number of zephyrs in a row from about 1.5/second to about 9/second, which is basically satisfactory. (imported from commit 5f72680d6290eaa02ef8ced5b3792fb3efc1db41) --- bots/zephyr_mirror.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bots/zephyr_mirror.py b/bots/zephyr_mirror.py index ce2fe65..70c99aa 100755 --- a/bots/zephyr_mirror.py +++ b/bots/zephyr_mirror.py @@ -169,7 +169,7 @@ def process_loop(log): if notice is not None: try: process_notice(notice, log) - except: + except Exception: logger.exception("Error relaying zephyr:") time.sleep(2) @@ -255,9 +255,12 @@ def process_notice(notice, log): log.write(simplejson.dumps(zeph) + '\n') log.flush() - res = send_humbug(zeph) - if res.get("result") != "success": - logger.error("Error relaying zephyr:\n%s\n%s" %(zeph, res)) + if os.fork() == 0: + # Actually send the message in a child process, to avoid blocking. + res = send_humbug(zeph) + if res.get("result") != "success": + logger.error("Error relaying zephyr:\n%s\n%s" % (zeph, res)) + sys.exit(0) def decode_unicode_byte_strings(zeph): for field in zeph.keys(): @@ -736,4 +739,6 @@ or specify the --api-key-file option.""" % (options.api_key_file,))) traceback.print_exc() time.sleep(1) logger = configure_logger("zephyr=>humbug") + # Have the kernel reap children for when we fork off processes to send Humbugs + signal.signal(signal.SIGCHLD, signal.SIG_IGN) zephyr_to_humbug(options)