2 * An experiment with parallel reading and writing of files.
13 int main(int argc, char **argv)
16 uns files = atol(argv[1]);
17 uns bufsize = atol(argv[2]) * 1024; // Kbytes
18 uns rounds = (u64)atol(argv[3]) * 1024*1024 / bufsize; // Mbytes
22 log(L_INFO, "Initializing");
23 for (uns i=0; i<files; i++)
26 sprintf(name, "tmp/ft-%d", i);
27 fd[i] = sh_open(name, O_RDWR | O_CREAT | O_TRUNC, 0666);
29 die("Cannot create %s: %m", name);
30 buf[i] = big_alloc(bufsize);
34 log(L_INFO, "Writing %d files in parallel with %d byte buffers", files, bufsize);
36 u64 total = 0, total_rep = 0;
37 for (uns r=0; r<rounds; r++)
39 for (uns i=0; i<files; i++)
41 for (uns j=0; j<bufsize; j++)
43 uns c = write(fd[i], buf[i], bufsize);
46 if (total >= total_rep + 1024*1024*1024)
48 printf("Wrote %d MB (round %d of %d)\r", (int)(total >> 20), r, rounds);
54 log(L_INFO, "Syncing");
57 log(L_INFO, "Spent %dms (%d MB/sec)", ms, (uns)(total/ms*1000/1048576));
59 log(L_INFO, "Reading the files sequentially");
60 total = total_rep = 0;
61 for (uns i=0; i<files; i++)
63 lseek(fd[i], 0, SEEK_SET);
64 for (uns r=0; r<rounds; r++)
66 uns c = read(fd[i], buf[i], bufsize);
69 if (total >= total_rep + 1024*1024*1024)
71 printf("Read %d MB (file %d)\r", (int)(total >> 20), i);
79 log(L_INFO, "Spent %dms (%d MB/sec)", ms, (uns)(total/ms*1000/1048576));