def sendAndWaitReplies(numRequests): corosArgs = sendRequests(numRequests) coros = buildCoros(checkReplyAndLogStat, corosArgs) for coro in coros: task = eventually(coro, retryWait=RETRY_WAIT, timeout=TTL, verbose=False) looper.run(task) printCurrentTestResults(stats, testStartedAt) logger.info("Sent and waited for {} {} requests".format( len(coros), requestType))
def sendAndWaitReplies(numRequests): corosArgs = sendRequests(numRequests) coros = buildCoros(checkReplyAndLogStat, corosArgs) for coro in coros: task = eventually(coro, retryWait=RETRY_WAIT, timeout=TTL, verbose=False) looper.run(task) printCurrentTestResults(stats, testStartedAt) logger.info("Sent and waited for {} {} requests" .format(len(coros), requestType))
def main(args): resultsFileName = \ "perf_results_{x.numberOfClients}_" \ "{x.numberOfRequests}_{0}.csv".format(int(time.time()), x=args) resultFilePath = os.path.join(args.resultsPath, resultsFileName) logger.info("Results file: {}".format(resultFilePath)) def writeResultsRow(row): if not os.path.exists(resultFilePath): resultsFd = open(resultFilePath, "w") resultsWriter = csv.DictWriter(resultsFd, fieldnames=resultsRowFieldNames) resultsWriter.writeheader() resultsFd.close() resultsFd = open(resultFilePath, "a") resultsWriter = csv.DictWriter(resultsFd, fieldnames=resultsRowFieldNames) resultsWriter.writerow(row) resultsFd.close() stats = [] def buildCoros(coroFunc, corosArgs): coros = [] for args in corosArgs: argsExt = args + [writeResultsRow, stats] coros.append(functools.partial(coroFunc, *argsExt)) return coros clientPoll = ClientPoll(args.clientsListFilePath, args.numberOfClients, args.numberOfClientsToSkip) with Looper() as looper: # connect connectionCoros = [] for cli in clientPoll.clients: looper.add(cli) connectionCoros.append( functools.partial(checkIfConnectedToAll, cli)) for coro in connectionCoros: looper.run( eventually(coro, timeout=CONNECTION_TTL, retryWait=RETRY_WAIT, verbose=False)) testStartedAt = time.time() stats.clear() requestType = args.requestType sendRequests = { "NYM": clientPoll.submitNym, "GET_NYM": clientPoll.submitGetNym, "ATTRIB": clientPoll.submitSetAttr, "ATTR": clientPoll.submitSetAttr }.get(requestType) if sendRequests is None: raise ValueError("Unsupported request type, " "only NYM and ATTRIB/ATTR are supported") def sendAndWaitReplies(numRequests): corosArgs = sendRequests(numRequests) coros = buildCoros(checkReplyAndLogStat, corosArgs) for coro in coros: task = eventually(coro, retryWait=RETRY_WAIT, timeout=TTL, verbose=False) looper.run(task) printCurrentTestResults(stats, testStartedAt) logger.info("Sent and waited for {} {} requests".format( len(coros), requestType)) if args.atOnce: sendAndWaitReplies(numRequests=args.numberOfRequests) else: for i in range(args.numberOfRequests): sendAndWaitReplies(numRequests=1)
def main(args): resultsFileName = \ "perf_results_{x.numberOfClients}_" \ "{x.numberOfRequests}_{0}.csv".format(int(time.time()), x=args) resultFilePath = os.path.join(args.resultsPath, resultsFileName) logger.info("Results file: {}".format(resultFilePath)) def writeResultsRow(row): if not os.path.exists(resultFilePath): resultsFd = open(resultFilePath, "w") resultsWriter = csv.DictWriter( resultsFd, fieldnames=resultsRowFieldNames) resultsWriter.writeheader() resultsFd.close() resultsFd = open(resultFilePath, "a") resultsWriter = csv.DictWriter( resultsFd, fieldnames=resultsRowFieldNames) resultsWriter.writerow(row) resultsFd.close() stats = [] def buildCoros(coroFunc, corosArgs): coros = [] for args in corosArgs: argsExt = args + [writeResultsRow, stats] coros.append(functools.partial(coroFunc, *argsExt)) return coros clientPoll = ClientPoll(args.clientsListFilePath, args.numberOfClients, args.numberOfClientsToSkip) with Looper() as looper: # connect connectionCoros = [] for cli in clientPoll.clients: looper.add(cli) connectionCoros.append( functools.partial(checkIfConnectedToAll, cli)) for coro in connectionCoros: looper.run(eventually(coro, timeout=CONNECTION_TTL, retryWait=RETRY_WAIT, verbose=False)) testStartedAt = time.time() stats.clear() requestType = args.requestType sendRequests = { "NYM": clientPoll.submitNym, "GET_NYM": clientPoll.submitGetNym, "ATTRIB": clientPoll.submitSetAttr, "ATTR": clientPoll.submitSetAttr }.get(requestType) if sendRequests is None: raise ValueError("Unsupported request type, " "only NYM and ATTRIB/ATTR are supported") def sendAndWaitReplies(numRequests): corosArgs = sendRequests(numRequests) coros = buildCoros(checkReplyAndLogStat, corosArgs) for coro in coros: task = eventually(coro, retryWait=RETRY_WAIT, timeout=TTL, verbose=False) looper.run(task) printCurrentTestResults(stats, testStartedAt) logger.info("Sent and waited for {} {} requests" .format(len(coros), requestType)) if args.atOnce: sendAndWaitReplies(numRequests=args.numberOfRequests) else: for i in range(args.numberOfRequests): sendAndWaitReplies(numRequests=1)