Skip to content
Permalink
Browse files

Add a small load testing script.

  • Loading branch information
mxsasha committed Jan 22, 2019
1 parent 5380035 commit 87e509faeaaa579a5e1c8bd794b3151080b87d54
Showing with 54 additions and 0 deletions.
  1. +53 −0 irrd/scripts/load_test.py
  2. +1 −0 setup.cfg
@@ -0,0 +1,53 @@
#!/usr/bin/env python
# flake8: noqa: E402

"""
A simple load tester for IRRd.
Sends random !g queries.
"""
import time

import argparse
import random
import socket


def main(host, port, count):
queries = [b'!!\n']
for i in range(count):
asn = random.randrange(1, 50000)
query = f'!gAS{asn}\n'.encode('ascii')
queries.append(query)
queries.append(b'!q\n')

s = socket.socket()
s.settimeout(30)
s.connect((host, port))

queries_str = b''.join(queries)
s.sendall(queries_str)

start_time = time.perf_counter()
while 1:
data = s.recv(1024*1024)
if not data:
break

elapsed = time.perf_counter() - start_time
time_per_query = elapsed / count * 1000
qps = int(count / elapsed)
print(f'Ran {count} queries in {elapsed}s, time per query {time_per_query} ms, {qps} qps')


if __name__ == '__main__': # pragma: no cover
description = """A simple load tester for IRRd. Sends random !g queries."""
parser = argparse.ArgumentParser(description=description)
parser.add_argument('--count', dest='count', type=int, default=5000,
help=f'number of queries to run (default: 5000)')
parser.add_argument('host', type=str,
help='hostname of instance')
parser.add_argument('port', type=int,
help='port of instance')
args = parser.parse_args()

main(args.host, args.port, args.count)
@@ -19,6 +19,7 @@ omit =
irrd/storage/alembic/*
irrd/scripts/query_qa_comparison.py
irrd/scripts/database_upgrade.py
irrd/scripts/load_test.py
irrd/integration_tests/*

[tool:pytest]

0 comments on commit 87e509f

Please sign in to comment.
You can’t perform that action at this time.