From: Martin Mares Date: Fri, 1 Dec 2006 21:04:38 +0000 (+0100) Subject: Adapted the file-test to use asio. X-Git-Tag: holmes-import~506^2~13^2~224 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=ae8a9dd77d64838c354731ab32cc42b5bf576738;p=libucw.git Adapted the file-test to use asio. --- diff --git a/debug/sorter/Makefile b/debug/sorter/Makefile index 8ef96631..70f745dc 100644 --- a/debug/sorter/Makefile +++ b/debug/sorter/Makefile @@ -1,7 +1,9 @@ # Testing the new sorter DIRS+=debug/sorter -PROGS+=$(addprefix $(o)/debug/sorter/,retros file-test) +PROGS+=$(addprefix $(o)/debug/sorter/,retros file-test asio-test) $(o)/debug/sorter/retros: $(o)/debug/sorter/retros.o $(LIBSH) $(o)/debug/sorter/file-test: $(o)/debug/sorter/file-test.o $(LIBSH) +$(o)/debug/sorter/asio-test: $(o)/debug/sorter/asio-test.o $(LIBSH) +$(o)/debug/sorter/asio-test: LIBS+=-lpthread diff --git a/debug/sorter/asio-test.c b/debug/sorter/asio-test.c new file mode 100644 index 00000000..f3f384ca --- /dev/null +++ b/debug/sorter/asio-test.c @@ -0,0 +1,145 @@ +/* + * An experiment with parallel reading and writing of files using ASIO. + */ + +#include "lib/lib.h" +#include "lib/lfs.h" +#include "lib/asio.h" + +#include +#include +#include +#include + +#define COPY +#define DIRECT O_DIRECT + +#define P_INIT do { cnt = 0; cnt_rep = 0; cnt_ms = 1; } while(0) +#define P_UPDATE(cc) do { \ + cnt += cc; \ + if (cnt >= cnt_rep) { cnt_ms += get_timer(); \ + printf("%d of %d MB (%.2f MB/sec)\r", (int)(cnt >> 20), (int)(total_size >> 20), (double)cnt / 1048576 * 1000 / cnt_ms); \ + fflush(stdout); cnt_rep += 1<<26; } } while(0) +#define P_FINAL do { \ + cnt_ms += get_timer(); \ + log(L_INFO, "Spent %.3f sec (%.2f MB/sec)", (double)cnt_ms/1000, (double)cnt / 1048576 * 1000 / cnt_ms); \ +} while(0) + +static struct asio_queue io_queue; + +int main(int argc, char **argv) +{ + ASSERT(argc == 4); + uns files = atol(argv[1]); + uns bufsize = atol(argv[2]) * 1024; // Kbytes + u64 total_size = (u64)atol(argv[3]) * 1024*1024*1024; // Gbytes + u64 cnt, cnt_rep; + uns cnt_ms; + int fd[files]; + byte name[files][16]; + + init_timer(); + + io_queue.buffer_size = bufsize; + io_queue.max_writebacks = 2; + asio_init_queue(&io_queue); + +#ifdef COPY + log(L_INFO, "Creating input file"); + int in_fd = sh_open("tmp/ft-in", O_RDWR | O_CREAT | O_TRUNC | DIRECT, 0666); + ASSERT(in_fd >= 0); + ASSERT(!(total_size % bufsize)); + P_INIT; + for (uns i=0; iop = ASIO_WRITE_BACK; + r->fd = in_fd; + r->len = bufsize; + byte *xbuf = r->buffer; + for (uns j=0; j> 20), files, bufsize); + P_INIT; + for (uns round=0; roundop = ASIO_READ; + r->fd = in_fd; + r->len = bufsize; + asio_submit(r); + struct asio_request *rr = asio_wait(&io_queue); + ASSERT(rr == r && r->status == (int)r->len); +#else + for (uns j=0; jbuffer[j] = round+i+j; +#endif + r->op = ASIO_WRITE_BACK; + r->fd = fd[i]; + r->len = bufsize; + asio_submit(r); + P_UPDATE(bufsize); + } + } + asio_sync(&io_queue); +#ifdef COPY + close(in_fd); +#endif + log(L_INFO, "Syncing"); + sync(); + P_FINAL; + + log(L_INFO, "Reading the files sequentially"); + P_INIT; + for (uns i=0; iop = ASIO_READ; + r->fd = fd[i]; + r->len = bufsize; + asio_submit(r); + rr = asio_wait(&io_queue); + ASSERT(rr == r && r->status == (int)bufsize); + asio_put(r); + P_UPDATE(bufsize); + } + close(fd[i]); + } + P_FINAL; + + for (uns i=0; i