Skip to content

Commit

Permalink
Added std dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ohler55 committed Mar 30, 2018
1 parent 9d8812b commit 628a580
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# CHANGELOG

### 1.2.0 - 2018-03-29

Changed results display and added standard deviation for latency.

### 1.1.1 - 2018-02-25

Fixed segfault on exit.
Expand Down
15 changes: 13 additions & 2 deletions src/drop.c
Expand Up @@ -156,14 +156,25 @@ drop_recv(Drop d, Pool p, bool enough) {
}
if (d->xsize <= d->rcnt) {
double dt = dtime() - d->pipeline[d->phead];

double ave;
double dif;

p->ok_cnt++;
d->pipeline[d->phead] = 0.0;
d->phead++;
if (PIPELINE_SIZE <= d->phead) {
d->phead = 0;
}
p->lat_sum += dt;
ave = p->lat_sum / (double)p->ok_cnt;
dif = dt - ave;
p->lat_sq_sum += dif * dif;


// TBD sum of (diff from on going average) squared
// sq_sum


/* TBD debugging, uses something better than a simple average for latency analysis.
if (0.01 < dt && p->lat_sum * 2.0 / p->ok_cnt < dt) {
printf("*** long latency: %0.3f msecs\n", dt * 1000.0);
Expand All @@ -173,7 +184,7 @@ drop_recv(Drop d, Pool p, bool enough) {
d->buf[d->xsize] = '\0';
printf("%s\n", d->buf);
}
if (enough || !d->h->keep_alive) {
if ((enough || !d->h->keep_alive) && 0 >= drop_pending(d) ) {
drop_cleanup(d);
return true;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/drop.h
Expand Up @@ -21,7 +21,7 @@ typedef struct _Drop {
double pipeline[PIPELINE_SIZE];
int phead;
int ptail;

long rcnt; // recv count
long xsize; // expected size of message
char buf[MAX_RESP_SIZE];
Expand Down
26 changes: 20 additions & 6 deletions src/perfer.c
Expand Up @@ -2,6 +2,7 @@

#include <errno.h>
#include <inttypes.h>
#include <math.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
Expand All @@ -17,7 +18,7 @@
extern int asprintf(char **strp, const char *fmt, ...);
#endif

#define VERSION "1.1.1"
#define VERSION "1.2.0"

static struct _Perfer perfer = {
.inited = false,
Expand Down Expand Up @@ -304,7 +305,10 @@ perfer_init(Perfer h, int argc, const char **argv) {
int i;
int err;
long n = num / h->tcnt;


if (!h->keep_alive) {
h->backlog = 1;
}
for (p = h->pools, i = h->tcnt; 0 < i; i--, p++) {
if (0 != (err = pool_init(p, h, n))) {
return err;
Expand Down Expand Up @@ -354,6 +358,7 @@ perfer_start(Perfer h) {
double psum = 0.0;
double lat = 0.0;
double rate = 0.0;
double stdev = 0.0;

for (p = h->pools, i = h->tcnt; 0 < i; i--, p++) {
if (0 != (err = pool_start(p))) {
Expand All @@ -368,6 +373,7 @@ perfer_start(Perfer h) {
err_cnt += p->err_cnt;
lat_sum += p->lat_sum;
psum += p->actual_end - h->start_time;
stdev += p->lat_sq_sum;
}
// TBD actual times for each thread
if (0 < err_cnt) {
Expand All @@ -381,11 +387,19 @@ perfer_start(Perfer h) {
}
if (0 < ok_cnt) {
lat = lat_sum * 1000.0 / ok_cnt;
stdev /= (double)ok_cnt;
stdev = sqrt(stdev) * 1000.0;
}
printf("%s processed %ld requests in %0.3f seconds for a rate of %ld Requests/sec.\n",
h->addr, ok_cnt, psum / h->tcnt, (long)rate);
printf("with an average latency of %0.3f msecs\n", lat);

printf("Benchmarks for:\n");
printf(" URL: %s/%s\n", h->addr, h->path);
printf(" Threads: %ld\n", h->tcnt);
printf(" Connections/thread: %ld\n", h->ccnt);
printf(" Duration: %0.1f seconds\n", psum / h->tcnt);
printf(" Keep-Alive: %s\n", h->keep_alive ? "true" : "false");
printf("Results:\n");
printf(" Throughput: %ld requests/second\n", (long)rate);
printf(" Latency: %0.3f +/-%0.3f msecs (and stdev)\n", lat, stdev);

return 0;
}

Expand Down
1 change: 1 addition & 0 deletions src/pool.c
Expand Up @@ -28,6 +28,7 @@ pool_init(Pool p, struct _Perfer *h, long num) {
p->err_cnt = 0;
p->ok_cnt = 0;
p->lat_sum = 0.0;
p->lat_sq_sum = 0.0;
p->actual_end = 0.0;
if (NULL == (p->drops = (Drop)malloc(sizeof(struct _Drop) * p->dcnt))) {
printf("-*-*- Failed to allocate %d connections.\n", p->dcnt);
Expand Down
1 change: 1 addition & 0 deletions src/pool.h
Expand Up @@ -17,6 +17,7 @@ typedef struct _Pool {
long err_cnt;
long ok_cnt;
double lat_sum;
double lat_sq_sum;
double actual_end;
struct _Perfer *perfer;
pthread_t thread;
Expand Down

0 comments on commit 628a580

Please sign in to comment.