Results 1 to 6 of 6
So i have built a program that takes a picture from two cameras every second and converts them both to jpeg format. The problem is that currently it takes ~2 ...
- 05-18-2011 #1Just Joined!
- Join Date
- May 2011
- Posts
- 1
Will Multi-Threading Improve Performance?
So i have built a program that takes a picture from two cameras every second and converts them both to jpeg format. The problem is that currently it takes ~2 seconds to convert a single raw photo to jpeg format, thus every second I add another raw photo (30 MB) to ram waiting to be converted to jpeg.
So... theoretically the conversion to jpeg is running on a single core with hyperthreading, would I see better performance running the exact same process (a program pulling from a queue and converting to jpeg) running as a single process, or two concurrent processes? (both processes running on the same core, (so 1 thread on one clock cycle, the other on the other... (or one thread running on 1 core and the other on another core)))
What other steps would you take to improve the performance so there would no longer be a race condition?
-Currently using QT
- 05-18-2011 #2Just Joined!
- Join Date
- Feb 2005
- Location
- Utah
- Posts
- 18
Should be faster with two threads for the very reason you mention: pipe-lining has wasted space, and most processors can run different processes through the CPU, so instead of sending an empty cycle, it sends cycles for another thread.
- 05-19-2011 #3Just Joined!
- Join Date
- Jan 2011
- Location
- Fairfax, Virginia, USA
- Posts
- 94
Hi fistlo,
I'm assuming your using a 3rd party application for your image conversion like Magick++ in C or C++?
From what you described, I unfortunately don't see how more threads will solve your bottleneck problem. Problems along the nature you described are typically handled by either decreasing the load on your program or by handling work off to other CPUs. Sorry, but I can't see how more threads running on what sounds like a single core Intel x86 will help.
- 05-19-2011 #4Linux Newbie
- Join Date
- Apr 2010
- Location
- Novosibirsk, Russia
- Posts
- 136
If you want to improve the performance, do the conversion faster, for example with lower quality. If you take an image every second and free it every 2 seconds - some day the memory is going to blow

Multithreaded programs are needed when you need to do different tasks exactly simultaneously (for example, you handle user interaction and check a hard disk in the same time). Your program should consist of two threads: one for grabbing images and another to convert it.
In general threads are needed when you have some tasks which could be divided to a small ones, for example the task is
1. Switch off the alarm clock
2. Fill your bed
3. Make a breakfast
4. Eat a breakfast
You could do the first 3 things sequentially, or simultaneously - it really does not matter - but you could not make a breakfast and eat it in parallel
And here is the main thing of multithreading - if you have more than one core, then multithreading will improve performance, But if you have only one - then you could only split your logic to threads, do not think about speed up. Amount of cores exactly means how many threads you can run simultaneously. Hyper threading - it's a workaround to have "two cores". There are two "logical cores" for OS, but physical is only one.
I suppose that splitting your converting thread it's like a trying to cook a breakfast and eat it in the same time
So you could not proceed the image until you pull out it from a queue.
Intel Hyper-threading technology (pdf)
- 05-19-2011 #5Just Joined!
- Join Date
- Apr 2007
- Location
- Smithfield, UT
- Posts
- 4
Another possibility
Another (probably obvious) possibility would be to structure your program to offload the conversion to hardware such as a graphics card (if you have that hardware available).
- 05-20-2011 #6Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
You can either use multi-threading, or multi-processing. IE, using fork() to spawn a second process to deal with the new image. Multi-threading uses less resources. Multi-processing is safer/simpler. It is a trade-off of space vs. time vs. complexity.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote