aboutsummaryrefslogtreecommitdiff
path: root/tools/test-performance.py
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-11-10 14:33:17 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-11-10 14:33:17 +1300
commitd7c46e9bc205d8f5a3cf7e1871547eff8ae7164c (patch)
tree1caa86899b9b6edc18de022bf6e277cb10fde6d1 /tools/test-performance.py
parentb204307a34b8eeddd8653949465b2864b0fdf2a5 (diff)
downloadtrackermap-server-d7c46e9bc205d8f5a3cf7e1871547eff8ae7164c.tar.gz
trackermap-server-d7c46e9bc205d8f5a3cf7e1871547eff8ae7164c.tar.bz2
trackermap-server-d7c46e9bc205d8f5a3cf7e1871547eff8ae7164c.zip
Implement performance testing script
Diffstat (limited to 'tools/test-performance.py')
-rwxr-xr-xtools/test-performance.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/test-performance.py b/tools/test-performance.py
new file mode 100755
index 000000000..ec31e9b86
--- /dev/null
+++ b/tools/test-performance.py
@@ -0,0 +1,44 @@
+#!/usr/bin/python3
+
+import asyncio
+import random
+
+host = 'localhost'
+port = 5027
+
+messageLogin = bytearray.fromhex('000F313233343536373839303132333435')
+messageLocation = bytearray.fromhex('000000000000002b080100000140d4e3ec6e000cc661d01674a5e0fffc00000900000004020100f0000242322318000000000100007a04')
+
+devices = 100
+period = 1
+
+
+class AsyncClient(asyncio.Protocol):
+
+ def __init__(self, loop):
+ self.loop = loop
+ self.buffer = memoryview(messageLogin)
+
+ def connection_made(self, transport):
+ self.send_message(transport)
+
+ def send_message(self, transport):
+ transport.write(self.buffer)
+ self.buffer = memoryview(messageLocation)
+ delay = period * (0.9 + 0.2 * random.random())
+ self.loop.call_later(delay, self.send_message, transport)
+
+ def data_received(self, data):
+ pass
+
+ def connection_lost(self, exc):
+ self.loop.stop()
+
+
+loop = asyncio.get_event_loop()
+
+for i in range(0, devices):
+ loop.create_task(loop.create_connection(lambda: AsyncClient(loop), host, port))
+
+loop.run_forever()
+loop.close()