QThread performance
-
Hi,
Im using QthreadPool to start multiple thread to perform same task (eg, running same calculation function) but the time it takes for each task is around 5 milliseconds regardless if i create 1 thread or 5 thread in linux. I understand that this might be related to thread scheduling but i was wondering how i can increase the performance of the thread (reducing the task execution time from 5 milliseconds to say 3 ms or less), i did try to set the priority but base on the document it does not work on linux. Can anyone provide suggestions or if there are any other method to boost performance? thanks in advance. -
@yalee
My very first question would be how many cores are available for your threads to run in?My next question would be can you use some tool to discover when these threads are running, how many at once, are they using all cores?
I presume you time this over a whole bunch of tasks, so that the thread pool has a chance to re-use threads, not all first-timers?
I assume you are coding in C++ and not Python.
Nobody can say exactly how long a thread or task will take ("from 5 milliseconds to say 3 ms or less"). Is your code efficient? Does it wait on any system resources? Is it using shared variables so that it is mutexing? Would you consider using a profiling tool on your application (unfortunately not a trivial exercise!)?
-
before asking the general question you should do a test program that simply spawns multiple threads that do a single operation (something like modify a threadlocal variable) and collect metrics on program efficiency. That will tell you if your load is computational or system level. 5ms seems high for context switching on modern computers. I suspect you'll find you are blocking in the run() loop somewhere...perhaps waiting on a mutex?
-
@yalee said in QThread performance getaway shootout:
Hi,
Im using QthreadPool to start multiple thread to perform same task (eg, running same calculation function) but the time it takes for each task is around 5 milliseconds regardless if i create 1 thread or 5 thread in linux. I understand that this might be related to thread scheduling but i was wondering how i can increase the performance of the thread (reducing the task execution time from 5 milliseconds to say 3 ms or less), i did try to set the priority but base on the document it does not work on linux. Can anyone provide suggestions or if there are any other method to boost performance? thanks in advance.Problems with Qt::DirectConnection could arise. As stated in the manual, threading must be utilized with queued connections. You may find this class useful if you look at QtConcurrent with QFuture and QFutureWatcher.