]> mj.ucw.cz Git - libucw.git/commitdiff
Added a simple experiment with parallel reads/writes.
authorMartin Mares <mj@ucw.cz>
Thu, 23 Nov 2006 23:33:24 +0000 (00:33 +0100)
committerMartin Mares <mj@ucw.cz>
Thu, 23 Nov 2006 23:33:24 +0000 (00:33 +0100)
debug/sorter/Makefile
debug/sorter/file-test.c [new file with mode: 0644]

index 5e649ca39eca0327dd43303072ecb3a50612933d..8ef966316d6565a907decb0dbd5359ad387a5147 100644 (file)
@@ -1,6 +1,7 @@
 # Testing the new sorter
 
 DIRS+=debug/sorter
-PROGS+=$(addprefix $(o)/debug/sorter/,retros)
+PROGS+=$(addprefix $(o)/debug/sorter/,retros file-test)
 
 $(o)/debug/sorter/retros: $(o)/debug/sorter/retros.o $(LIBSH)
+$(o)/debug/sorter/file-test: $(o)/debug/sorter/file-test.o $(LIBSH)
diff --git a/debug/sorter/file-test.c b/debug/sorter/file-test.c
new file mode 100644 (file)
index 0000000..9ea4084
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ *  An experiment with parallel reading and writing of files.
+ */
+
+#include "lib/lib.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+int main(int argc, char **argv)
+{
+  ASSERT(argc == 4);
+  uns files = atol(argv[1]);
+  uns bufsize = atol(argv[2]);
+  uns rounds = atol(argv[3]);
+  int fd[files];
+  byte *buf[files];
+
+  log(L_INFO, "Initializing");
+  for (uns i=0; i<files; i++)
+    {
+      byte name[16];
+      sprintf(name, "tmp/ft-%d", i);
+      fd[i] = open(name, O_RDWR | O_CREAT | O_TRUNC, 0666);
+      if (fd[i] < 0)
+       die("Cannot create %s: %m", name);
+      buf[i] = big_alloc(bufsize);
+    }
+  sync();
+
+  log(L_INFO, "Writing %d files in parallel with %d byte buffers", files, bufsize);
+  for (uns r=0; r<rounds; r++)
+    {
+      log(L_INFO, "\tRound %d", r);
+      for (uns i=0; i<files; i++)
+       {
+         for (uns j=0; j<bufsize; j++)
+           buf[i][j] = r+i+j;
+         uns c = write(fd[i], buf[i], bufsize);
+         ASSERT(c == bufsize);
+       }
+    }
+  log(L_INFO, "Syncing");
+  sync();
+
+  log(L_INFO, "Reading the files sequentially");
+  for (uns i=0; i<files; i++)
+    {
+      lseek(fd[i], 0, SEEK_SET);
+      for (uns r=0; r<rounds; r++)
+       {
+         uns c = read(fd[i], buf[i], bufsize);
+         ASSERT(c == bufsize);
+       }
+      close(fd[i]);
+    }
+
+  log(L_INFO, "Done");
+  return 0;
+}