I need to download and decompress a file as quickly as possible in a very latency sensitive environment with limited resources (A VM with 1 cpu, 2 cores, 128MB RAM)
Naturally, I tried to pipe the download process to the uncompress process to with the assumption that I could uncompress while downloading simultaneously. I know that piping is blocked by the slowest process. To overcome this I use a buffer in between the download and decompress process.
My shell script looks something like this:
curl -s $CACHE_URL | buffer -S 100M | lz4 -d > /tmp/myfile
If I first download the compressed file and then uncompress without piping the download takes about 250ms and the uncompress takes about 250ms if executed sequentially.
My assumption is therefore that the piped approach will take around 250-275ms since there is no additional disk read in between and the download isn't CPU bound like the decompression so should not affect that much.
But it isn't. It's barely faster as shown by my logs:
Start download
35211K, 81131K/s
Download & decompressed done in 447ms
Starting individual download & decompress
Download done in 234ms
Decompressed : 61 MiB
/tmp/myfile : decoded 75691880 bytes
Decompress done in 230ms
I'm I thinking wrong here? Is there any other way to speed this up?