From 9c33cfc62cfd0e2067e444212d1a3b370792f7f7 Mon Sep 17 00:00:00 2001 From: wkliao Date: Fri, 29 Apr 2022 20:01:01 -0500 Subject: [PATCH] use malloc to increase read chunk size from 1 KB to 4 MB Otherwise running command below as part of nc_test/run_inmemory.sh can be very slow ./tst_diskless4 500000000 opendiskless --- libdispatch/dutil.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libdispatch/dutil.c b/libdispatch/dutil.c index d4b37a3448..357737e69e 100644 --- a/libdispatch/dutil.c +++ b/libdispatch/dutil.c @@ -279,12 +279,13 @@ NC_readfilen(const char* filename, NCbytes* content, long long amount) int NC_readfileF(FILE* stream, NCbytes* content, long long amount) { +#define READ_BLOCK_SIZE 4194304 int ret = NC_NOERR; long long red = 0; - char part[1024]; + char *part = (char*) malloc(4194304); while(amount < 0 || red < amount) { - size_t count = fread(part, 1, sizeof(part), stream); + size_t count = fread(part, 1, 4194304, stream); if(ferror(stream)) {ret = NC_EIO; goto done;} if(count > 0) ncbytesappendn(content,part,(unsigned long)count); red += count; @@ -297,6 +298,7 @@ NC_readfileF(FILE* stream, NCbytes* content, long long amount) } ncbytesnull(content); done: + free(part); return ret; }