def tester(k, tId, mID, n, wargs, q, evts): # excessively clever lambda that bypasses the voluntary throttle of # system default policy while still using it for the 429 nr = numerous.Numerous(apiKey=k, throttle=lambda nr, tp, td, up: (tp['result-code'] == 429) and up[0] (nr, tp, up[1], up[2])) testmetric = nr.metric(mID) # one time to prime the pump, avoid TCP connect overhead during test, etc. ignored = testmetric.read() # Let the main thread know we got to this staging point evts[0].set() # and wait for everyone else to get there too (set() by main thread) evts[1].wait() for i in range(n): try: t0 = time.time() v = testmetric.write(1, **wargs) dt = time.time() - t0 except numerous.NumerousMetricConflictError: dt = time.time() - t0 v = "NoChange" q.put({'thread': tId, 'result': v, 'timestamps': [t0, dt]})
def tester(k, mID, n429, lim, q): # excessively clever lambda that bypasses the voluntary throttle aspect of the # system default policy while still using the 429/500 bit nr = numerous.Numerous(apiKey=k, throttle=lambda nr, tp, td, up: (tp['result-code'] in (429, 500)) and up[0](nr, tp, up[1], up[2])) nr.statistics['serverResponseTimes'] = [ 0 ] * 10 # keep 10, purely infomational testmetric = nr.metric(mID) expectedVal = testmetric.read() while nr.statistics['throttle429'] < n429 and lim != 0: if testmetric.read() != expectedVal: q.put({'error': "Huh, got a wrong value"}) break if lim > 0: # because -1 means "forever" lim -= 1 q.put(nr.statistics)
] * 10 # keep 10, purely infomational testmetric = nr.metric(mID) expectedVal = testmetric.read() while nr.statistics['throttle429'] < n429 and lim != 0: if testmetric.read() != expectedVal: q.put({'error': "Huh, got a wrong value"}) break if lim > 0: # because -1 means "forever" lim -= 1 q.put(nr.statistics) apiKey = numerous.numerousKey(args.credspec) nrMain = numerous.Numerous(apiKey=apiKey) testmetric = None if args.metric: # - attempt to use it as a metric ID. If that works, use that metric. # - then attempt to look it up ByLabel 'STRING' # - then attempt to look it up ByLabel 'ONE' (regexp processing will work) for mt in ['ID', 'STRING', 'ONE']: try: testmetric = nrMain.metricByLabel(args.metric, matchType=mt) if testmetric: break except numerous.NumerousError: # can potentially get "conflict" pass
parser.add_argument('--capdelay', action="store_true") parser.add_argument('--statistics', action="store_true") args = parser.parse_args() # # This sleeps until you have a fresh API allocation at the "top" of the minute # def sync_to_top_of_api_rate(nr): nr.ping() # just anything to cause an API call if nr.statistics['rate-reset'] > 0: time.sleep(nr.statistics['rate-reset']) nr = numerous.Numerous(apiKey=numerous.numerousKey(args.credspec)) if args.statistics: nr.statistics['serverResponseTimes'] = [0] * 5 # keep extra response times testmetric = None if args.metric: # - attempt to use it as a metric ID. If that works, use that metric. # - then attempt to look it up ByLabel 'STRING' # - then attempt to look it up ByLabel 'ONE' (regexp processing will work) for mt in [ 'ID', 'STRING', 'ONE' ]: try: testmetric = nr.metricByLabel(args.metric, matchType = mt) if testmetric: break except numerous.NumerousError: # can potentially get "conflict"