Created
April 28, 2023 10:44
-
-
Save syominsergey/fe0dd4c634aed3f440b337cfbc02e197 to your computer and use it in GitHub Desktop.
stress_server.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python2.7 | |
import sys, zmq, time, random | |
reload(sys) | |
sys.setdefaultencoding('utf-8') | |
if len(sys.argv) > 1: | |
max_pause = float(sys.argv[1]) | |
else: | |
max_pause = 0.0 | |
if len(sys.argv) > 2: | |
port = int(sys.argv[2]) | |
else: | |
port = 14141 | |
zcontext = zmq.Context() | |
zcollector = zcontext.socket(zmq.PULL) | |
zcollector.bind("tcp://0.0.0.0:" + str(port)) | |
received_in_total = 0 | |
less_than_expected = 0 | |
more_than_expected = 0 | |
expected_rank = 1 | |
if max_pause != 0.0: | |
random.seed() | |
start_time = None | |
while True: | |
workload = zcollector.recv_json() | |
if start_time is None: | |
start_time = time.time() | |
print "start of messages receiving:", time.ctime(start_time) | |
if max_pause != 0.0: | |
time.sleep(max_pause * random.random()) | |
if workload['build_stage'] == 'decay': | |
break | |
received_in_total += 1 | |
received_rank = workload['pkg_rank'] | |
if received_rank < expected_rank: | |
less_than_expected += 1 | |
elif received_rank > expected_rank: | |
more_than_expected += 1 | |
expected_rank = received_rank + 1 | |
else: | |
expected_rank += 1 | |
end_time = time.time() | |
print "end time:", time.ctime(end_time) | |
print "average time for 1 message processing, seconds:", (end_time - start_time) / received_in_total | |
print "received_in_total:", received_in_total | |
print "less_than_expected:", less_than_expected | |
print "more_than_expected:", more_than_expected |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment