On Linux, suppose I have an executable file. Let's look at two cases:
(A) A large portion of what the executable does is disk I/O;
(B) the executable doesn't do any disk I/O.
For each of the cases A and B, should I expect a significant difference in the running time of the executable between these two scenario?
(1) The executable and all the files involved are in a tmpfs folder (a RAM folder);
(2) The executable and all the files involved are in "regular" disk folders.
I'm also interested in whether I should expect a significant difference between these three scenarios, related to Docker:
(3) The executable is run from within a Docker container, and the executable and all files involved are in a tmpfs folder created from within the container under a disk drive which was mounted using docker run -v ...
(4) The executable is run from within a Docker container, and the executable and all files involved are in a tmpfs folder created from within the container, under an "internal" drive (that does not persist after the container is halted).
(5) The executable is run from within a Docker container, and the executable and all files involved are in "regular" disk folders.
My expectation is that in general, running from a tmpfs folder should be faster, mostly when there is a lot of disk I/O involved. But I don't see this in practice, so I would like to see if my expectations are correct.
Best Answer
Running on tmpfs will be faster only if you have a lot of disk I/O that isn't fulfilled from page cache.
If the I/O is reads and the files are already in cache, tmpfs will make no difference.
If the I/O is async writes without flushing and the workload is bursty rather than continuous and there is enough cache to soak up a burst of writes and the writes can be flushed in the background between the bursts, tmpfs will make no difference.
If there is no disk I/O to be done, tmpfs will make no difference.
If you have a lot of disk I/O and your process is blocked iowaiting for storage to catch up, running on tmpfs will make a huge difference. The slower your disks, the more difference it will make, right up to the point where you become CPU bottlenecked.