git » libjio » commit c7fbc99

Performance tests cleanups

author Alberto Bertogli
2009-03-28 04:04:33 UTC
committer Alberto Bertogli
2009-03-28 04:13:20 UTC
parent f5ba4fabcc031f353ab627fc59f7cd6d85230f41

Performance tests cleanups

This patch brings the performance tests more up to date, by doing several
cleanups:

 - Fix the Makefile so it's more correct when building and linking.
 - Remove the streaming test, and rename the parallel test to performance.
   The streaming test is exactly the same test as the parallel with one
   thread, so why keep both around?
 - Fix some comments and minor style changes.
 - Expand the help.
 - Mark the functions and static data as static.
 - Use proper types (unsigned long, ssize_t) instead of int.
 - Add checks for the return of some calls like malloc().
 - The blocksize is now passed in Kb, to make it easier to use bigger
   sizes.
 - Do not open the file O_SYNC, it makes no sense.
 - Run jfsck after all the writes, and verify it went well.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

.gitignore +1 -0
tests/performance/Makefile +9 -9
tests/performance/parallel.c +0 -122
tests/performance/performance.c +141 -0
tests/performance/streaming.c +0 -82

diff --git a/.gitignore b/.gitignore
index 457538f..2f09c27 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,5 +7,6 @@ samples/full
 samples/jio1
 samples/jio2
 samples/jio3
+tests/performance/performance
 *.pyc
 *.pyo
diff --git a/tests/performance/Makefile b/tests/performance/Makefile
index 36a953f..11ddd33 100644
--- a/tests/performance/Makefile
+++ b/tests/performance/Makefile
@@ -1,23 +1,23 @@
 
-LIBS = -ljio -lpthread
-CFLAGS = -Wall -O6
+CFLAGS := -Wall -O3 -D_XOPEN_SOURCE=500 \
+	$(shell getconf LFS_CFLAGS 2>/dev/null)
+LIBS = -ljio
 
 default: all
 
-all: parallel streaming
+all: performance
 
-parallell: parallel.o
-	$(CC) $(LIBS) parallel.o -o parallel
-
-streaming: streaming.o
-	$(CC) $(LIBS) streaming.o -o streaming
+performance: performance.o
+	$(CC) $(LIBS) performance.o -o performance
 
 .c.o:
 	$(CC) $(CFLAGS) -c $< -o $@
 
 clean:
-	rm -f streaming.o streaming parallel.o parallel
+	rm -f performance.o performance
 	rm -f *.bb *.bbg *.da *.gcov gmon.out
+	rm -f test_file
+	rm -rf .test_file.jio
 
 
 .PHONY: default all clean
diff --git a/tests/performance/parallel.c b/tests/performance/parallel.c
deleted file mode 100644
index 205bb90..0000000
--- a/tests/performance/parallel.c
+++ /dev/null
@@ -1,122 +0,0 @@
-
-/*
- * streaming.c - A program to test speed of parallel writes using libjio.
- * Alberto Bertogli (albertito@blitiri.com.ar)
- */
-
-/*
- * It creates a big file, extend it using truncate and fork N threads, which
- * write the file in chunks (ie. if we have three threads, the first one
- * writes the first 1/3rd of the file, and so on).
- */
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/time.h>
-#include <libjio.h>
-
-#define FILENAME "test_file-parallel"
-
-/* Declare here what's shared among threads
- * It's not the cleanest design ever, but let's face it, it's a simple
- * benchmarking program, who cares? */
-struct jfs fs;
-int blocksize, towrite, mb;
-
-
-void help(void)
-{
-	printf("Use: parallel MBs_to_write_per_thread blocksize nthreads\n");
-	exit(1);
-}
-
-void *worker(void *tno)
-{
-	void *buf;
-	int tid, work_done, rv;
-	off_t localoffset;
-	long secs, usecs;
-	double seconds, mb_per_sec;
-	struct timeval tv1, tv2;
-
-	tid = (int) tno;
-
-	localoffset = tid * towrite;
-	
-	buf = malloc(blocksize);
-	work_done = 0;
-
-	gettimeofday(&tv1, NULL);
-
-	while (work_done < towrite) {
-		rv = jpwrite(&fs, buf, blocksize, localoffset + work_done );
-		if (rv != blocksize) {
-			perror("jpwrite:");
-			break;
-		}
-
-		work_done += blocksize;
-	}
-
-	gettimeofday(&tv2, NULL);
-
-	secs = tv2.tv_sec - tv1.tv_sec;
-	usecs = tv2.tv_usec - tv1.tv_usec;
-
-	if (usecs < 0) {
-		secs -= 1;
-		usecs = 1000000 + usecs;
-	}
-	
-	seconds = secs + (usecs / 1000000.0);
-	mb_per_sec = mb / seconds;
-	
-	printf("%d %d %d %f %f\n", tid, mb, blocksize, seconds, mb_per_sec);
-
-	return NULL;
-
-}
-
-int main(int argc, char **argv)
-{
-	int rv, nthreads, i;
-	pthread_t *threads;
-
-	if (argc != 4)
-		help();
-
-	mb = atoi(argv[1]);
-	blocksize = atoi(argv[2]);
-	nthreads = atoi(argv[3]);
-	towrite = mb * 1024 * 1024;
-
-	threads = malloc(sizeof(pthread_t) * nthreads);
-	
-
-	rv = jopen(&fs, FILENAME, O_RDWR | O_CREAT | O_SYNC | O_TRUNC, 
-			0600, 0);
-	if (rv < 0) {
-		perror("jopen():");
-		exit(1);
-	}
-
-	/* extend the file */
-	jtruncate(&fs, towrite * nthreads);
-	
-	/* start the threads */
-	for (i = 0; i < nthreads; i++) {
-		pthread_create(threads + i, NULL, &worker, (void *) i);
-	}
-
-	for (i = 0; i < nthreads; i++) {
-		pthread_join(*(threads + i), NULL);
-	}
-
-	jclose(&fs);
-	return 0;
-}
-
diff --git a/tests/performance/performance.c b/tests/performance/performance.c
new file mode 100644
index 0000000..849cd60
--- /dev/null
+++ b/tests/performance/performance.c
@@ -0,0 +1,141 @@
+
+/*
+ * performance.c - A program to test speed of parallel writes using libjio.
+ * Alberto Bertogli (albertito@blitiri.com.ar)
+ *
+ * It creates a big file, extends it using truncate, and forks N threads which
+ * write the file in chunks (ie. if we have three threads, the first one
+ * writes the first 1/3rd of the file, and so on).
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/time.h>
+#include <libjio.h>
+
+#define FILENAME "test_file"
+
+/* These are shared among threads, to make the code simpler */
+static struct jfs fs;
+static unsigned long mb;
+static ssize_t blocksize, towrite;
+
+
+static void help(void)
+{
+	printf("Use: performance towrite blocksize nthreads\n");
+	printf("\n");
+	printf(" - towrite: how many MB to write per thread\n");
+	printf(" - blocksize: size of blocks written, in KB\n");
+	printf(" - nthreads: number of threads to use\n");
+}
+
+static void *worker(void *tno)
+{
+	void *buf;
+	unsigned long tid;
+	ssize_t work_done, rv;
+	off_t localoffset;
+	long secs, usecs;
+	double seconds, mb_per_sec;
+	struct timeval tv1, tv2;
+
+	tid = (unsigned long) tno;
+
+	localoffset = tid * towrite;
+
+	buf = malloc(blocksize);
+	if (buf == NULL) {
+		perror("malloc()");
+		return NULL;
+	}
+
+	work_done = 0;
+
+	gettimeofday(&tv1, NULL);
+
+	while (work_done < towrite) {
+		rv = jpwrite(&fs, buf, blocksize, localoffset + work_done);
+		if (rv != blocksize) {
+			perror("jpwrite()");
+			break;
+		}
+
+		work_done += blocksize;
+	}
+
+	gettimeofday(&tv2, NULL);
+
+	secs = tv2.tv_sec - tv1.tv_sec;
+	usecs = tv2.tv_usec - tv1.tv_usec;
+
+	if (usecs < 0) {
+		secs -= 1;
+		usecs = 1000000 + usecs;
+	}
+
+	seconds = secs + (usecs / 1000000.0);
+	mb_per_sec = mb / seconds;
+
+	printf("%lu %zd %zd %f %f\n", tid, mb, blocksize, seconds, mb_per_sec);
+
+	return NULL;
+}
+
+int main(int argc, char **argv)
+{
+	int rv, nthreads;
+	unsigned long i;
+	pthread_t *threads;
+	struct jfsck_result ckres;
+
+	if (argc != 4) {
+		help();
+		return 1;
+	}
+
+	mb = atoi(argv[1]);
+	blocksize = atoi(argv[2]) * 1024;
+	nthreads = atoi(argv[3]);
+	towrite = mb * 1024 * 1024;
+
+	threads = malloc(sizeof(pthread_t) * nthreads);
+	if (threads == NULL) {
+		perror("malloc()");
+		return 1;
+	}
+
+	rv = jopen(&fs, FILENAME, O_RDWR | O_CREAT | O_TRUNC, 0600, 0);
+	if (rv < 0) {
+		perror("jopen()");
+		return 1;
+	}
+
+	jtruncate(&fs, towrite * nthreads);
+
+	for (i = 0; i < nthreads; i++) {
+		pthread_create(threads + i, NULL, &worker, (void *) i);
+	}
+
+	for (i = 0; i < nthreads; i++) {
+		pthread_join(*(threads + i), NULL);
+	}
+
+	jclose(&fs);
+	jfsck(FILENAME, NULL, &ckres);
+	if (ckres.total != 0) {
+		fprintf(stderr, "There were %d errors during the test\n",
+				ckres.total);
+		fprintf(stderr, "jfsck() was used to fix them, but that");
+		fprintf(stderr, "shouldn't happen.\n");
+		return 1;
+	}
+
+	jfsck_cleanup(FILENAME, NULL);
+	return 0;
+}
+
diff --git a/tests/performance/streaming.c b/tests/performance/streaming.c
deleted file mode 100644
index 211b388..0000000
--- a/tests/performance/streaming.c
+++ /dev/null
@@ -1,82 +0,0 @@
-
-/*
- * streaming.c - A program to test speed of a streaming write using libjio.
- * Alberto Bertogli (albertito@blitiri.com.ar)
- */
-
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/time.h>
-#include <libjio.h>
-
-#define FILENAME "test_file-streaming"
-
-
-void help(void)
-{
-	printf("Use: streaming MBs_to_write blocksize\n");
-	exit(1);
-}
-
-
-int main(int argc, char **argv)
-{
-	int towrite, blocksize, rv, mb;
-	long secs, usecs;
-	double seconds, mb_per_sec;
-	void *buf;
-	struct jfs fs;
-	struct timeval tv1, tv2;
-
-	if (argc != 3)
-		help();
-
-	mb = atoi(argv[1]);
-	towrite = mb * 1024 * 1024;
-	blocksize = atoi(argv[2]);
-
-	rv = jopen(&fs, FILENAME, O_RDWR | O_CREAT | O_SYNC | O_TRUNC, 
-			0600, 0);
-	if (rv < 0) {
-		perror("jopen():");
-		exit(1);
-	}
-
-	buf = malloc(blocksize);
-
-	gettimeofday(&tv1, NULL);
-
-	while (towrite > 0) {
-		rv = jwrite(&fs, buf, blocksize);
-		if (rv != blocksize) {
-			perror("jwrite:");
-			break;
-		}
-
-		towrite -= blocksize;
-	}
-
-	gettimeofday(&tv2, NULL);
-
-	secs = tv2.tv_sec - tv1.tv_sec;
-	usecs = tv2.tv_usec - tv1.tv_usec;
-
-	if (usecs < 0) {
-		secs -= 1;
-		usecs = 1000000 + usecs;
-	}
-	
-	seconds = secs + (usecs / 1000000.0);
-	mb_per_sec = mb / seconds;
-	
-	printf("%d %d %f %f\n", mb, blocksize, seconds, mb_per_sec);
-
-	jclose(&fs);
-	return 0;
-}
-