title: How to increase my program disk Read speed on Ubuntu?
body: <p>I have a C++ program <code>read_bin</code> to read hundreds of 200MB binary files on disk. The program to read a file using <code>ifstream</code>:</p>
  
  <pre><code>std::ifstream is(filename,  std::ios::in | std::ios::binary);
  is.seekg(startPos, std::ios::beg);
  int8_t* buffer = new int8_t [bytesToRead];
  is.read(reinterpret_cast&lt;char*&gt;(buffer), bytesToRead);
  </code></pre>
  
  <p>I start hundreds of <code>read_bin</code> processes in the terminal to read individual binary files concurrently.</p>
  
  <p>e.g.</p>
  
  <pre><code>read_bin 001.bin
  read_bin 002.bin
  read_bin 003.bin
  read_bin 004.bin
  read_bin 005.bin
  ...
  read_bin 101.bin
  </code></pre>
  
  <p>It's a SSD disk, but I use <code>iotop</code> to monitor the read speed is usually at <code>25MB/s</code> which is very slow.</p>
  
  <pre><code>Total DISK READ :      25.35 M/s | Total DISK WRITE :       0.00 B/s
  Actual DISK READ:      25.35 M/s | Actual DISK WRITE:       7.84 K/s
    TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN     IO&gt;    COMMAND 
   2636 be/4 ubuntu      501.71 K/s    0.00 B/s  0.00 % 99.99 % read_bin 001.bin
   2631 be/4 ubuntu      501.71 K/s    0.00 B/s  0.00 % 99.99 % read_bin 002.bin
   2660 be/4 ubuntu      501.71 K/s    0.00 B/s  0.00 % 99.99 % read_bin 003.bin
   2662 be/4 ubuntu      501.71 K/s    0.00 B/s  0.00 % 99.99 % read_bin 004.bin
   2665 be/4 ubuntu      501.71 K/s    0.00 B/s  0.00 % 99.99 % read_bin 005.bin
   2668 be/4 ubuntu      501.71 K/s    0.00 B/s  0.00 % 99.99 % read_bin 006.bin
  </code></pre>
  
  <p>I can see the IO is full at 99%.</p>
  
  <p>and run <code>top</code>:</p>
  
  <pre><code>top - 21:36:58 up 10 min,  3 users,  load average: 95.28, 74.89, 37.27
  Tasks: 250 total,   1 running, 188 sleeping,   0 stopped,   0 zombie
  %Cpu(s):  1.2 us,  0.9 sy,  0.0 ni, 74.9 id, 23.0 wa,  0.0 hi,  0.0 si,  0.0 st
  KiB Mem : 30875564 total,  5388416 free, 12671052 used, 12816096 buff/cache
  KiB Swap:        0 total,        0 free,        0 used. 17743200 avail Mem 
  
    PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND    
   2633 ubuntu      20   0  147928 133532   3080 D   0.7  0.4   0:00.73 read_bin 
   2652 ubuntu      20   0  147928 133368   2916 D   0.7  0.4   0:00.72 read_bin 
   2697 ubuntu      20   0  145604 131764   2884 D   0.7  0.4   0:00.69 read_bin 
   2701 ubuntu      20   0  145604 131000   2928 D   0.7  0.4   0:00.70 read_bin 
   2630 ubuntu      20   0  147928 134680   2908 D   0.3  0.4   0:00.72 read_bin 
   2632 ubuntu      20   0  147928 134292   2772 D   0.3  0.4   0:00.72 read_bin 
   2634 ubuntu      20   0  147928 134120   2868 D   0.3  0.4   0:00.70 read_bin
  </code></pre>
  
  <p>I tried to increase buffer <code>bytesToRead</code>, but the read speed is still very slow at <code>25MB/s</code>. Normally, SSD speed can be fast as <code>500MB/s</code>.</p>
  
  <p>How to fix my program to maximize disk READ speed?</p>