Skip to content

Commit

Permalink
update ct; test throughput in MB/s
Browse files Browse the repository at this point in the history
  • Loading branch information
kr committed Jun 6, 2013
1 parent 20da1ae commit c3f8d66
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 9 deletions.
32 changes: 27 additions & 5 deletions ct/ct.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ static char *curdir;
static int rjobfd = -1, wjobfd = -1;
static int64 bstart, bdur;
static int btiming; // bool
static int64 bbytes;
static const int64 Second = 1000 * 1000 * 1000;
static const int64 BenchTime = Second;
static const int MaxN = 1000 * 1000 * 1000;
Expand Down Expand Up @@ -107,6 +108,13 @@ ctstoptimer(void)
}


void
ctsetbytes(int n)
{
bbytes = (int64)n;
}


static void
die(int code, int err, char *msg)
{
Expand Down Expand Up @@ -297,6 +305,7 @@ runbenchn(Benchmark *b, int n)
b->f(n);
ctstoptimer();
write(durfd, &bdur, sizeof bdur);
write(durfd, &bbytes, sizeof bbytes);
_exit(0);
}
setpgid(pid, pid);
Expand All @@ -307,7 +316,6 @@ runbenchn(Benchmark *b, int n)
}
killpg(pid, 9);
rmtree(b->dir);

if (b->status != 0) {
putchar('\n');
lseek(outfd, 0, SEEK_SET);
Expand All @@ -319,9 +327,12 @@ runbenchn(Benchmark *b, int n)
int r = read(durfd, &b->dur, sizeof b->dur);
if (r != sizeof b->dur) {
perror("read");
if (b->status == 0) {
b->status = 1;
}
b->status = 1;
}
r = read(durfd, &b->bytes, sizeof b->bytes);
if (r != sizeof b->bytes) {
perror("read");
b->status = 1;
}
}

Expand Down Expand Up @@ -405,7 +416,18 @@ runbench(Benchmark *b)
runbenchn(b, n);
}
if (b->status == 0) {
printf("%8d\t%10lld ns/op\n", n, b->dur/n);
printf("%8d\t%10lld ns/op", n, b->dur/n);
if (b->bytes > 0) {
double mbs = 0;
if (b->dur > 0) {
int64 sec = b->dur / 1000L / 1000L / 1000L;
int64 nsec = b->dur % 1000000000L;
double dur = (double)sec + (double)nsec*.0000000001;
mbs = ((double)b->bytes * (double)n / 1000000) / dur;
}
printf("\t%7.2f MB/s", mbs);
}
putchar('\n');
} else {
if (failed(b->status)) {
printf("failure");
Expand Down
1 change: 1 addition & 0 deletions ct/ct.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ void ctfail(void);
void ctresettimer(void);
void ctstarttimer(void);
void ctstoptimer(void);
void ctsetbytes(int);
void ctlogpn(char*, int, char*, ...) __attribute__((format(printf, 3, 4)));
#define ctlog(...) ctlogpn(__FILE__, __LINE__, __VA_ARGS__)
#define assert(x) do if (!(x)) {\
Expand Down
1 change: 1 addition & 0 deletions ct/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct Benchmark {
char *name;
int status;
int64 dur;
int64 bytes;
char dir[sizeof TmpDirPat];
};

Expand Down
35 changes: 31 additions & 4 deletions testserv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1098,19 +1098,46 @@ cttestbinlogv5()
}


void
ctbenchputdelete(int n)
static void
benchputdeletesize(int n, int size)
{
port = SERVER();
fd = mustdiallocal(port);
char buf[50];
char buf[50], put[50];
char body[size+1];
memset(body, 'a', size);
body[size] = 0;
ctsetbytes(size);
sprintf(put, "put 0 0 0 %d\r\n", size);
int i;
for (i = 0; i < n; i++) {
mustsend(fd, "put 0 0 0 0\r\n");
mustsend(fd, put);
mustsend(fd, body);
mustsend(fd, "\r\n");
ckrespsub(fd, "INSERTED ");
sprintf(buf, "delete %d\r\n", i+1);
mustsend(fd, buf);
ckresp(fd, "DELETED\r\n");
}
}


void
ctbenchputdelete8byte(int n)
{
benchputdeletesize(n, 8);
}


void
ctbenchputdelete1k(int n)
{
benchputdeletesize(n, 1024);
}


void
ctbenchputdelete8k(int n)
{
benchputdeletesize(n, 8192);
}

0 comments on commit c3f8d66

Please sign in to comment.