From 6c471ef9155d339bdbff128c1d94560d144d300a Mon Sep 17 00:00:00 2001 From: Paul Date: Sat, 5 Nov 2016 15:16:27 +0100 Subject: [PATCH] Benchmark script never completed on Docker (#211) (#428) * Do not generate new fingerprint when connection fails * Do not try to print latencies when all connections failed * Update asgi_redis and channels versions in Dockerfile --- testproject/Dockerfile | 4 ++-- testproject/benchmark.py | 31 +++++++++++++++++-------------- testproject/docker-compose.yml | 2 +- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/testproject/Dockerfile b/testproject/Dockerfile index aeddb65..15e43e3 100644 --- a/testproject/Dockerfile +++ b/testproject/Dockerfile @@ -12,13 +12,13 @@ RUN apt-get update && \ # Install asgi_redis driver and most recent Daphne RUN pip install \ - asgi_redis==0.8.3 \ + asgi_redis==1.0.0 \ git+https://github.com/django/daphne.git@#egg=daphne # Clone Channels and install it RUN git clone https://github.com/django/channels.git /srv/channels/ && \ cd /srv/channels && \ - git reset --hard caa589ae708a1a66ba1bdcd24f5fd473040772bd && \ + git reset --hard origin/master && \ python setup.py install WORKDIR /srv/channels/testproject/ diff --git a/testproject/benchmark.py b/testproject/benchmark.py index 01c1f81..c0c4c91 100644 --- a/testproject/benchmark.py +++ b/testproject/benchmark.py @@ -70,7 +70,6 @@ class MyClientProtocol(WebSocketClientProtocol): "connect": True, } else: - self.fingerprint = "".join(random.choice("abcdefghijklmnopqrstuvwxyz") for i in range(16)) stats[self.fingerprint] = { "sent": 0, "received": 0, @@ -168,22 +167,26 @@ class Benchmarker(object): num_out_of_order += 1 else: num_good += 1 - # Some analysis on latencies - latency_mean = statistics.mean(latencies) - latency_median = statistics.median(latencies) - latency_stdev = statistics.stdev(latencies) - latency_95 = self.percentile(latencies, 0.95) - latency_99 = self.percentile(latencies, 0.99) + + if latencies: + # Some analysis on latencies + latency_mean = statistics.mean(latencies) + latency_median = statistics.median(latencies) + latency_stdev = statistics.stdev(latencies) + latency_95 = self.percentile(latencies, 0.95) + latency_99 = self.percentile(latencies, 0.99) + # Print results print("-------") print("Sockets opened: %s" % len(stats)) - print("Latency stats: Mean %.3fs Median %.3fs Stdev %.3f 95%% %.3fs 95%% %.3fs" % ( - latency_mean, - latency_median, - latency_stdev, - latency_95, - latency_99, - )) + if latencies: + print("Latency stats: Mean %.3fs Median %.3fs Stdev %.3f 95%% %.3fs 95%% %.3fs" % ( + latency_mean, + latency_median, + latency_stdev, + latency_95, + latency_99, + )) print("Good sockets: %s (%.2f%%)" % (num_good, (float(num_good) / len(stats))*100)) print("Incomplete sockets: %s (%.2f%%)" % (num_incomplete, (float(num_incomplete) / len(stats))*100)) print("Corrupt sockets: %s (%.2f%%)" % (num_corruption, (float(num_corruption) / len(stats))*100)) diff --git a/testproject/docker-compose.yml b/testproject/docker-compose.yml index a0603fd..1753b71 100644 --- a/testproject/docker-compose.yml +++ b/testproject/docker-compose.yml @@ -13,6 +13,6 @@ services: worker: image: channels-test build: . - command: python manage.py runworker + command: python manage.py runworker --settings=testproject.settings.channels_redis depends_on: - redis