10000 Add Scripts for Performance Testing · 1biot/esp32_https_server@376b396 · GitHub
[go: up one dir, main page]

Skip to content

Commit 376b396

Browse files
committed
Add Scripts for Performance Testing
1 parent f80b961 commit 376b396

File tree

7 files changed

+464
-0
lines changed

7 files changed

+464
-0
lines changed

extras/tests/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Testing
2+
3+
This directory contains tools to test specific characteristics of the server, e.g. performance.
4+
5+
## Setup
6+
7+
Create the virtual environment with the required dependencies:
8+
9+
```bash
10+
virtualenv --python=python3 env
11+
source env/bin/activate
12+
pip install -r requirements.txt
13+
```
14+
15+
## Scripts
16+
17+
| Script | Description |
18+
| ------ | ----------- |
19+
| chart_perf_tests.py | **Visualizes performance tests** created by `run_perf_tests.py`. |
20+
| run_perf_tests.py | **Runs performance tests**: Command line tool to request a bunch of resources from the server, with various clients synchronously, and one or more pooled connections for each client. Use `chart_perf_tests.py` to visualize the output (`./run_perf-tests.py ... > ./chart_perf_tests.py` in its simplest form) |

extras/tests/chart_perf_tests.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env python
2+
import argparse
3+
import csv
4+
import matplotlib.pyplot as plt
5+
import numpy as np
6+
import sys
7+
8+
parser = argparse.ArgumentParser(description='Display results of performance tests')
9+
parser.add_argument('infile', default='-', type=str,
10+
help='Input file (use \'-\' for standard input, default: standard input)')
11+
parser.add_argument('--charttype', default='avgrestime', type=str,
12+
help='Chart type to display the results (default: %(default)s, use \'help\' for a list)')
13+
14+
args = parser.parse_args()
15+
16+
def log(x, end='\n'):
17+
print(x, end=end, file=sys.stderr)
18+
19+
def avgrestime_selector(row):
20+
""" Create a row for each request based on (pool, connection, reqtime) """
21+
return [
22+
int(row['pool']),
23+
int(row['connection']),
24+
int(row['time_data']) + 0 if int(row['time_connect'])<0 else int(row['time_connect'])
25+
]
26+
27+
def avgrestime_visualizer(data):
28+
""" Use (pool, connection, reqtime) to display a chart """
29+
# pool, connection, reqtime
30+
pool_labels = ["Pool %d" % p for p in sorted(set(d[0] for d in data))]
31+
con_labels = ["Conn. %d" % c for c in sorted(set(d[1] for d in data))]
32+
concount = len(con_labels)
33+
ind = np.arange(concount)
34+
width = 0.35
35+
fig, axs = plt.subplots(len(pool_labels), 1, squeeze=False, constrained_layout=True)
36+
fig.suptitle("Average Time per Request")
37+
for pool in range(len(pool_labels)):
38+
plotmeans = []
39+
plotstd = []
40+
for con in range(concount):
41+
condata = [x[2]/1000.0 for x in data if x[0]==pool and x[1]==con]
42+
plotmeans.append(np.mean(condata))
43+
plotstd.append(np.std(condata))
44+
axs[pool,0].bar(ind, plotmeans, width, yerr=plotstd)
45+
axs[pool,0].set_title(pool_labels[pool])
46+
axs[pool,0].set_ylabel('Time (ms)')
47+
axs[pool,0].set_xticks(ind, minor=False)
48+
axs[pool,0].set_xticklabels(con_labels, fontdict=None, minor=False)
49+
50+
charttypes = {
51+
"avgrestime": {
52+
"description": "Average Time per Request",
53+
"selector": avgrestime_selector,
54+
"visualizer": avgrestime_visualizer
55+
}
56+
}
57+
58+
if not args.charttype in charttypes:
59+
if args.charttype.lower()!='help':
60+
log("Invalid chart type. ", end="")
61+
log("The following options are available for --charttype:")
62+
for charttype in charttypes.keys():
63+
print(" %s - %s" % (charttype, charttypes[charttype]['description']))
64+
else:
65+
charttype = charttypes[args.charttype]
66+
67+
data = []
68+
with sys.stdin if args.infile=='-' else open(args.infile, 'r') as infile:
69+
csvdata = csv.DictReader(infile, delimiter=',', quotechar='"')
70+
for row in csvdata:
71+
data.append(charttype['selector'](row))
72+
73+
charttype['visualizer'](data)
74+
plt.show()

extras/tests/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
matplotlib==3.1.1
2+
numpy==1.17.4
3+

extras/tests/resourcelist/cats.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/cats/cat_sm_1.jpg
2+
/cats/cat_sm_2.jpg
3+
/cats/cat_sm_3.jpg
4+
/cats/cat_sm_4.jpg
5+
/cats/cat_sm_5.jpg
6+
/cats/cat_sm_6.jpg
7+
/cats/cat_sm_7.jpg
8+
/cats/cat_sm_8.jpg
9+
/cats/cat_sm_9.jpg
10+
/cats/cat_sm_10.jpg
11+
/cats/cat_sm_11.jpg
12+
/cats/cat_sm_12.jpg
13+
/cats/cat_sm_13.jpg
14+
/cats/cat_sm_14.jpg
15+
/cats/cat_sm_15.jpg
16+
/cats/cat_sm_16.jpg
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/small/1.txt
2+
/small/2.txt
3+
/small/3.txt
4+
/small/4.txt
5+
/small/5.txt
6+
/small/6.txt
7+
/small/7.txt
8+
/small/8.txt
9+
/small/9.txt
10+
/small/10.txt
11+
/small/11.txt
12+
/small/12.txt
13+
/small/13.txt
14+
/small/14.txt
15+
/small/15.txt
16+
/small/16.txt

0 commit comments

Comments
 (0)
0