2

I have a C++ application on Linux which writes some data to an SSD. The application writes at ~100 MBytes per second.

Every second, the application writes 20 new files in to the disk. Additional threads of the application perform other logic and maintenance, beside those 20 threads.

For now, my application uses multiple threads to write multiple files at the same time, writing one file per thread.

It is better to change the design of the code and have one thread write all 20 new files every second?

Andrew
  • 5,212
  • 1
  • 22
  • 40
user3668129
  • 4,318
  • 6
  • 45
  • 87
  • 5
    Why not try it, measure it, and find out? As with any optimisation question, your results will depend on the system, the behaviour of your application, and any number of other factors. That said, multiple threads could permit the parallel preparation of data; each thread will block on the output operation, but that doesn't stop the other thread(s) running to prepare their own writes. Synchronisation between threads will affect the performance, as will the I/O scheduler and the nature of the writes. It's usually better to prepare a single large block and have the OS write it to a single file. – Andrew May 24 '16 at 13:43

1 Answers1

0

It depends on your OS

But would rather suggest to use a maximum of 4 -8 threads as the thread management of the OS most of the time slowers the programm if too much threads are being executed parallel

Try to use a bit fewer threads with more tasks to do for each of them ;)

The best you can do is still measuring the overall execution time of the program

TheGuy13
  • 21
  • 1
  • 6