Created benchmark with pycurl
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Pünkösd Marcell 2020-10-22 23:12:20 +02:00
parent 45afb935d4
commit efd7639021

View File

@ -0,0 +1,66 @@
import sys
import multiprocessing
import time
def independent_worker(result_queue):
import pycurl
prepared_curl = pycurl.Curl()
prepared_curl.setopt(pycurl.URL, "https://birb.k8s.kmlabz.com/benchmark")
prepared_curl.setopt(pycurl.SSL_VERIFYPEER, 0)
prepared_curl.setopt(pycurl.SSL_VERIFYHOST, 0)
# prepared_curl.setopt(pycurl.FORBID_REUSE, 0)
prepared_curl.setopt(pycurl.HTTP_VERSION, pycurl.CURL_HTTP_VERSION_2_0)
prepared_curl.setopt(pycurl.WRITEFUNCTION, lambda data: None)
start_time = time.time()
stop_time = 0
count = 0
while True:
prepared_curl.perform()
count += 1
if count % 50 == 0:
if (time.time() - start_time) >= 10:
stop_time = time.time()
break
runtime = stop_time - start_time
prepared_curl.close()
result_queue.put((runtime, count))
def main():
num_workers = int(sys.argv[1])
result_queue = multiprocessing.Queue()
workers = []
for _ in range(num_workers):
workers.append(multiprocessing.Process(target=independent_worker, args=(result_queue,)))
for w in workers:
w.start()
for w in workers:
w.join()
total_requests_sent = 0
print("Completed requests for each worker:")
while not result_queue.empty():
requests_sent = result_queue.get()
print('-', requests_sent[1], 'req ', requests_sent[0], 'sec')
total_requests_sent += requests_sent[1]
print("Total completed requests:", total_requests_sent)
print(total_requests_sent / 10, "req/s")
if __name__ == '__main__':
main()