From 5c74ee587ec88660467af733fd3b42b9235ee3a1 Mon Sep 17 00:00:00 2001 From: Malyshev Artem Date: Tue, 24 Jan 2017 09:04:42 +0300 Subject: [PATCH] Installable benchmark package. (#501) * Make benchmark installable module. * Use passed url in the Benchmarker constructor. * Correct percentile output. * Import reactor globally. Since it used in the benchmarker. --- testproject/benchmark.py | 15 +++++++-------- testproject/setup.py | 7 +++++++ 2 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 testproject/setup.py diff --git a/testproject/benchmark.py b/testproject/benchmark.py index c0c4c91..387f1c9 100644 --- a/testproject/benchmark.py +++ b/testproject/benchmark.py @@ -3,9 +3,11 @@ from __future__ import unicode_literals import time import random import statistics -from autobahn.twisted.websocket import WebSocketClientProtocol, \ - WebSocketClientFactory - +from autobahn.twisted.websocket import ( + WebSocketClientProtocol, + WebSocketClientFactory, +) +from twisted.internet import reactor stats = {} @@ -92,9 +94,7 @@ class Benchmarker(object): self.rate = rate self.spawn = spawn self.messages = messages - self.factory = WebSocketClientFactory( - args.url, - ) + self.factory = WebSocketClientFactory(self.url) self.factory.protocol = MyClientProtocol self.factory.num_messages = self.messages self.factory.message_rate = self.rate @@ -180,7 +180,7 @@ class Benchmarker(object): print("-------") print("Sockets opened: %s" % len(stats)) if latencies: - print("Latency stats: Mean %.3fs Median %.3fs Stdev %.3f 95%% %.3fs 95%% %.3fs" % ( + print("Latency stats: Mean %.3fs Median %.3fs Stdev %.3f 95%% %.3fs 99%% %.3fs" % ( latency_mean, latency_median, latency_stdev, @@ -200,7 +200,6 @@ if __name__ == '__main__': import argparse from twisted.python import log - from twisted.internet import reactor # log.startLogging(sys.stdout) diff --git a/testproject/setup.py b/testproject/setup.py new file mode 100644 index 0000000..916e2da --- /dev/null +++ b/testproject/setup.py @@ -0,0 +1,7 @@ +from setuptools import setup + +setup( + name='channels-benchmark', + py_modules=['benchmark'], + install_requires=['autobahn', 'Twisted'], +)