Use a threadpool to this faster; increase resolution of the collectd graph.

This commit is contained in:
Ralph Bean 2015-05-09 11:14:54 +00:00
parent 20e22a5005
commit 06d2517c67

View file

@ -6,6 +6,7 @@ Reports what percentage of fedmsg endpoints are bound and ready.
import base64 import base64
import collections import collections
import multiprocessing.pool
import socket import socket
import sys import sys
import time import time
@ -18,18 +19,17 @@ expected = '/wAAAAAAAAABfw=='
for_collectd = 'verbose' not in sys.argv for_collectd = 'verbose' not in sys.argv
active = collections.defaultdict(list)
inactive = collections.defaultdict(list)
pool = multiprocessing.pool.ThreadPool(10)
def info(content="\n"): def info(content="\n"):
if not for_collectd: if not for_collectd:
sys.stdout.write(content) sys.stdout.write(content)
sys.stdout.flush() sys.stdout.flush()
def scan_one(item):
def do_scan():
active = collections.defaultdict(list)
inactive = collections.defaultdict(list)
for i, item in enumerate(config['endpoints'].items()):
name, endpoints = item name, endpoints = item
for endpoint in endpoints: for endpoint in endpoints:
if not endpoint.startswith('tcp://'): if not endpoint.startswith('tcp://'):
@ -52,6 +52,11 @@ def do_scan():
if connection: if connection:
connection.close() connection.close()
def scan_all():
pool.map(scan_one, config['endpoints'].items())
info() info()
if 'verbose' in sys.argv: if 'verbose' in sys.argv:
@ -101,13 +106,13 @@ def do_scan():
return value return value
if not for_collectd: if not for_collectd:
do_scan() scan_all()
else: else:
interval = 10 interval = 5
host = socket.getfqdn() host = socket.getfqdn()
while True: while True:
start = time.time() start = time.time()
value = do_scan() value = scan_all()
stop = timestamp = time.time() stop = timestamp = time.time()
delta = stop - start delta = stop - start
output = ( output = (