In fact, you are completely screwed.
Let's see ... 300 * 4 MB = 1.2 GB. Does this fit your memory budget? If so, read them all in mind. But to speed things up, you can try the following:
Read 512KB of each file, sequentially. You can try reading from 2 to 8 at the same time - perhaps through Futures and see how well it scales. Depending on your I / O system, you may get some speed by reading multiple files at the same time, but I do not expect it to scale. EXPERIMENT! REFERENCE!
Process these 512K with Futures .
Go back to step 1 if you are not done with the files.
Get the result from Futures processing.
In step number 1, by limiting concurrent reading, you avoid bypassing your I / O subsystem. Click on it as much as possible, maybe a little less than that, but definitely nothing more.
Without reading all the files in step number 1, you are using some time spent reading these files, doing useful CPU work. You can experiment with decreasing the bytes read in step 1.
source share