Skip to content

Commit

Permalink
cleanup of the various tests and more structured output for graphing
Browse files Browse the repository at this point in the history
  • Loading branch information
avsm committed Oct 31, 2011
1 parent 2557d8a commit 65b421f
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 422 deletions.
14 changes: 11 additions & 3 deletions Makefile
@@ -1,13 +1,21 @@

CFLAGS = -g -Wall
CFLAGS = -g -Wall -O3

.PHONY: all clean run

all: pipe_lat pipe_thr \
unix_lat unix_thr \
tcp_lat tcp_thr \
tcp_local_lat tcp_remote_lat
# shm

shm: CFLAGS += -lrt

%_lat: atomicio.o xutil.o %_lat.o
$(CC) $(CFLAGS) -o $@ $^

%_thr: atomicio.o xutil.o %_thr.o
$(CC) $(CFLAGS) -o $@ $^

#shm: CFLAGS += -lrt

run:
./pipe_lat 100 10000
Expand Down
60 changes: 15 additions & 45 deletions pipe_lat.c
@@ -1,8 +1,8 @@
/*
Measure latency of IPC using unix domain sockets
Copyright (c) 2010 Erik Rigtorp <erik@rigtorp.com>
Copyright (c) 2011 Anil Madhavapeddy <anil@recoil.org>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
Expand All @@ -26,17 +26,16 @@
OTHER DEALINGS IN THE SOFTWARE.
*/


#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <stdint.h>
#include <inttypes.h>
#include <err.h>
#include "xutil.h"


int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
int ofds[2];
int ifds[2];
Expand All @@ -54,61 +53,32 @@ int main(int argc, char *argv[])
size = atoi(argv[1]);
count = atol(argv[2]);

buf = malloc(size);
if (buf == NULL) {
err(1, "malloc");
return 1;
}

printf("message size: %i octets\n", size);
printf("roundtrip count: %lli\n", count);
buf = xmalloc(size);

if (pipe(ofds) == -1) {
perror("pipe");
return 1;
}
if (pipe(ofds) == -1)
err(1, "pipe");

if (pipe(ifds) == -1) {
perror("pipe");
return 1;
}
if (pipe(ifds) == -1)
err(1, "pipe");

if (!fork()) { /* child */
int r;
for (i = 0; i < count; i++) {
r = read(ifds[0], buf, size);
if (r != size)
err(1, "child read ret=%d", r);

r = write(ofds[1], buf, size);
if (r != size)
err(1, "child write ret=%d", r);
xread(ifds[0], buf, size);
xwrite(ofds[1], buf, size);
}
} else { /* parent */
gettimeofday(&start, NULL);

for (i = 0; i < count; i++) {

if (write(ifds[1], buf, size) != size) {
perror("child write");
return 1;
}

if (read(ofds[0], buf, size) != size) {
perror("child read");
return 1;
}

xwrite(ifds[1], buf, size);
xread(ofds[0], buf, size);
}

gettimeofday(&stop, NULL);

delta = ((stop.tv_sec - start.tv_sec) * (int64_t) 1000000 +
stop.tv_usec - start.tv_usec);

printf("average latency: %lli us\n", delta / (count * 2));

printf("pipe_lat %d %" PRId64 " %" PRId64 "\n", size, count, delta / (count * 2));
}

return 0;
}
44 changes: 14 additions & 30 deletions pipe_thr.c
@@ -1,8 +1,8 @@
/*
Measure throughput of IPC using pipes
Copyright (c) 2010 Erik Rigtorp <erik@rigtorp.com>
Copyright (c) 2011 Anil Madhavapeddy <anil@recoil.org>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
Expand Down Expand Up @@ -31,10 +31,12 @@
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <stdint.h>

#include <inttypes.h>
#include <err.h>
#include "xutil.h"

int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
int fds[2];

Expand All @@ -51,48 +53,30 @@ int main(int argc, char *argv[])
size = atoi(argv[1]);
count = atol(argv[2]);

buf = malloc(size);
if (buf == NULL) {
perror("malloc");
exit(1);
}
buf = xmalloc(size);

printf("message size: %i octets\n", size);
printf("message count: %lli\n", count);

if (pipe(fds) == -1) {
perror("pipe");
exit(1);
}
if (pipe(fds) == -1)
err(1, "pipe");

if (!fork()) {
/* child */

for (i = 0; i < count; i++) {
if (read(fds[0], buf, size) != size) {
perror("read");
exit(1);
}
}
for (i = 0; i < count; i++)
xread(fds[0], buf, size);
} else {
/* parent */

gettimeofday(&start, NULL);

for (i = 0; i < count; i++) {
if (write(fds[1], buf, size) != size) {
perror("write");
exit(1);
}
}
for (i = 0; i < count; i++)
xwrite(fds[1], buf, size);

gettimeofday(&stop, NULL);

delta = ((stop.tv_sec - start.tv_sec) * (int64_t) 1e6 +
stop.tv_usec - start.tv_usec);

printf("average throughput: %lli msg/s\n", (count * (int64_t) 1e6) / delta);
printf("average throughput: %lli Mb/s\n", (((count * (int64_t) 1e6) / delta) * size * 8) / (int64_t) 1e6);
printf("pipe_thr %d %" PRId64 " %" PRId64 "\n", size, count, (((count * (int64_t) 1e6) / delta) * size * 8) / (int64_t) 1e6);
}

return 0;
Expand Down
17 changes: 13 additions & 4 deletions run.sh
@@ -1,14 +1,23 @@
#!/usr/bin/env bash
set -e

SIZES="1 2 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536"
NUMS="50000"
TEST="pipe_lat unix_lat"
#SIZES="1 2 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536"
#SIZES="1 8 32 64 256 1024 4096 8192 16384 32768 65536"
SIZES="8 64 1024 8192 16384"
NUMS="40000"
TEST="pipe_lat unix_lat tcp_lat tcp_thr pipe_thr unix_thr"

IF=eth0
EXTERNAL_IP=$(/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')

OUT=results.csv
rm -f ${OUT}

for test in ${TEST}; do
for size in ${SIZES}; do
for num in ${NUMS}; do
echo ${test}: ${size} x ${num}
./${test} ${size} ${num}
./${test} ${size} ${num} >> ${OUT}
done
done
done

0 comments on commit 65b421f

Please sign in to comment.