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)
This commit is contained in:
parent
ca351f3ddc
commit
c751cc97db
|
@ -169,7 +169,7 @@ def process_loop(log):
|
||||||
if notice is not None:
|
if notice is not None:
|
||||||
try:
|
try:
|
||||||
process_notice(notice, log)
|
process_notice(notice, log)
|
||||||
except:
|
except Exception:
|
||||||
logger.exception("Error relaying zephyr:")
|
logger.exception("Error relaying zephyr:")
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
|
@ -255,9 +255,12 @@ def process_notice(notice, log):
|
||||||
log.write(simplejson.dumps(zeph) + '\n')
|
log.write(simplejson.dumps(zeph) + '\n')
|
||||||
log.flush()
|
log.flush()
|
||||||
|
|
||||||
|
if os.fork() == 0:
|
||||||
|
# Actually send the message in a child process, to avoid blocking.
|
||||||
res = send_humbug(zeph)
|
res = send_humbug(zeph)
|
||||||
if res.get("result") != "success":
|
if res.get("result") != "success":
|
||||||
logger.error("Error relaying zephyr:\n%s\n%s" % (zeph, res))
|
logger.error("Error relaying zephyr:\n%s\n%s" % (zeph, res))
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
def decode_unicode_byte_strings(zeph):
|
def decode_unicode_byte_strings(zeph):
|
||||||
for field in zeph.keys():
|
for field in zeph.keys():
|
||||||
|
@ -736,4 +739,6 @@ or specify the --api-key-file option.""" % (options.api_key_file,)))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
logger = configure_logger("zephyr=>humbug")
|
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)
|
zephyr_to_humbug(options)
|
||||||
|
|
Loading…
Reference in a new issue