-
Notifications
You must be signed in to change notification settings - Fork 3
/
wrk_interval.patch
113 lines (108 loc) · 5.08 KB
/
wrk_interval.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
diff --git a/src/wrk.c b/src/wrk.c
index 51f46f7..5125e0c 100644
--- a/src/wrk.c
+++ b/src/wrk.c
@@ -10,6 +10,7 @@ static struct config {
uint64_t threads;
uint64_t timeout;
uint64_t pipeline;
+ uint64_t interval;
bool delay;
bool dynamic;
bool latency;
@@ -42,20 +43,21 @@ static void handler(int sig) {
}
static void usage() {
- printf("Usage: wrk <options> <url> \n"
- " Options: \n"
- " -c, --connections <N> Connections to keep open \n"
- " -d, --duration <T> Duration of test \n"
- " -t, --threads <N> Number of threads to use \n"
- " \n"
- " -s, --script <S> Load Lua script file \n"
- " -H, --header <H> Add header to request \n"
- " --latency Print latency statistics \n"
- " --timeout <T> Socket/request timeout \n"
- " -v, --version Print version details \n"
- " \n"
- " Numeric arguments may include a SI unit (1k, 1M, 1G)\n"
- " Time arguments may include a time unit (2s, 2m, 2h)\n");
+ printf("Usage: wrk <options> <url> \n"
+ " Options: \n"
+ " -c, --connections <N> Connections to keep open \n"
+ " -d, --duration <T> Duration of test \n"
+ " -t, --threads <N> Number of threads to use \n"
+ " -i, --interval <T> Throughput reporting interval \n"
+ " \n"
+ " -s, --script <S> Load Lua script file \n"
+ " -H, --header <H> Add header to request \n"
+ " --latency Print latency statistics \n"
+ " --timeout <T> Socket/request timeout \n"
+ " -v, --version Print version details \n"
+ " \n"
+ " Numeric arguments may include a SI unit (1k, 1M, 1G) \n"
+ " Time arguments may include a time unit (2s, 2m, 2h) \n");
}
int main(int argc, char **argv) {
@@ -143,7 +145,34 @@ int main(int argc, char **argv) {
uint64_t bytes = 0;
errors errors = { 0 };
- sleep(cfg.duration);
+ uint64_t sleepTime = 0;
+ uint64_t totalTime = 0;
+ uint64_t totalReqs = 0;
+ uint64_t currentReqs = 0;
+ uint64_t intervalReqs = 0;
+ long double intervalRPS = 0;
+ // Report periodic throughput
+ if (cfg.interval > 0) {
+ while (totalTime < cfg.duration && stop == 0) {
+ sleepTime = cfg.interval;
+ if (totalTime + sleepTime > cfg.duration) {
+ sleepTime = totalTime + cfg.interval - cfg.duration;
+ }
+ totalTime += sleepTime;
+ sleep(sleepTime);
+ currentReqs = 0;
+ for (uint64_t i = 0; i < cfg.threads; i++) {
+ thread *t = &threads[i];
+ currentReqs += t->complete;
+ }
+ intervalReqs = currentReqs - totalReqs;
+ totalReqs = currentReqs;
+ intervalRPS = intervalReqs / sleepTime;
+ printf("%4llus: %llu requests in last %llus (%9.1Lf req/sec)\n", totalTime, intervalReqs, sleepTime, intervalRPS);
+ }
+ } else {
+ sleep(cfg.duration);
+ }
stop = 1;
for (uint64_t i = 0; i < cfg.threads; i++) {
@@ -469,6 +498,7 @@ static char *copy_url_part(char *url, struct http_parser_url *parts, enum http_p
static struct option longopts[] = {
{ "connections", required_argument, NULL, 'c' },
{ "duration", required_argument, NULL, 'd' },
+ { "interval", required_argument, NULL, 'i' },
{ "threads", required_argument, NULL, 't' },
{ "script", required_argument, NULL, 's' },
{ "header", required_argument, NULL, 'H' },
@@ -488,8 +518,9 @@ static int parse_args(struct config *cfg, char **url, struct http_parser_url *pa
cfg->connections = 10;
cfg->duration = 10;
cfg->timeout = SOCKET_TIMEOUT_MS;
+ cfg->interval = 0;
- while ((c = getopt_long(argc, argv, "t:c:d:s:H:T:Lrv?", longopts, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "t:c:d:i:s:H:T:Lrv?", longopts, NULL)) != -1) {
switch (c) {
case 't':
if (scan_metric(optarg, &cfg->threads)) return -1;
@@ -500,6 +531,9 @@ static int parse_args(struct config *cfg, char **url, struct http_parser_url *pa
case 'd':
if (scan_time(optarg, &cfg->duration)) return -1;
break;
+ case 'i':
+ if (scan_time(optarg, &cfg->interval)) return -1;
+ break;
case 's':
cfg->script = optarg;
break;