TThread and dual processor machines

Posted on 2004-10-06
Last Modified: 2010-04-05
If I have a program with multiple TThreads running on a dual processor machine, will it run faster than on a single processor machine (in general terms)? I realise a single-threaded program doesn't run faster on a dual-processor machine. Anything else that can be done to get the most out of 2 processors?


Geoff M.
Question by:gmayo
  • 2
  • 2
  • 2
  • +4
LVL 27

Assisted Solution

kretzschmar earned 40 total points
ID: 12235678
susal i would guess, it depends how the os do share its work to this two processors

maybe this gives some hints
LVL 11

Assisted Solution

calinutz earned 40 total points
ID: 12235735
Windows does the spliting of threads between processors. But the only difference you would feel is that if your threads fill up the first processor then a single processor system will hang while a double processor will place the threads on the second processors tail before hanging
LVL 12

Assisted Solution

Ivanov_G earned 40 total points
ID: 12236472
using SystemParametersInfo you can detect the number of processors and them with SetProcessAffinityMask you can assign threads to different processors. But I also think (although I am not sure) that the OS will put the new threads on the second processors.

> will it run faster than on a single processor machine
Yes, it will.

> I realise a single-threaded program doesn't run faster on a dual-processor machine.
I think so. But this is for your process only. With the same number of running applications you still get some better performance for your Application, even it is single threaded.
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

LVL 17

Accepted Solution

Wim ten Brink earned 50 total points
ID: 12237393
> If I have a program with multiple TThreads running on a dual processor machine, will it run faster than on a single processor machine (in general terms)?
This depends mainly on the speed of the processors. If you only have P4 2.4GHz systems, the dual processor system will perform a lot faster. Why? Because it can process a lot more things at the same time. It's not only your own application that is making use of this second processor. Windows itself, the device drivers, the system services and any other application that runs on your system can now shoft the workload over two processors.
So yes, with processors of same speed and quality, the dual-processor system will be a lot faster.

But what if you compare a 1GHz dual-pentium with a 2 GHz single-pentium? In that case, the performance will be about the same level, depending on the amount of pressure every system gets. The dual-pentium system will still be able to handle two processes at the same time while the single-processor system will just continue to swap.

Of course, we haven't mentioned the advantage of hyperthreading here either.

> I realise a single-threaded program doesn't run faster on a dual-processor machine.
Oh, it will. It will, depending on the circumstances, though. If it's a database application that has to read a lot of data from the disk then it doesn't matter if you have 1, 2, 4 or even 64 processors. It will be the disk speed that determines the speed of your application. The same is true for network applications that still have to wait for the other side to respond. Even memory access will slow things down a bit, which you especially notice with a dual-processor system.
But if you consider the raw calcultion power of your system, it will get more time with the processor because the other processor will handle about half the processes on your system. If your PC is running 24 processes then each processor will handle about half of them. Thus the system performs two tasks simultaneously, which improves speed.

> Anything else that can be done to get the most out of 2 processors?
Buy a faster harddisk if you're working on a database system... A faster network for network applications. Faster and better memory for applications that handle huge amounts of data (video-editing, for example.) The best use for a multi-processor system would be tor more complex calculations.

You don't have to use multi-threading to speed up your application on a multi-processor system. It will just get more processor-time since every processor has less processes to handle. However, using multiple threads does increase the speed of your application even further because now your application can really do two things at the same time.

Say, we have a system with 24 processes. If you have a single-threaded application then:
On a single-processor system, your processor will have to execute 24 processes per second (or other time-unit).
On a dual-processor system, each processor only has to handle half the processes in the same time-unit. Thus your process gets about twice as much time. (Unless it wasted time on waiting for disks, network or memory.)
With a multi-threaded application, you'd get:
On a single-processor system, your processor will have to execute 24 processes per second (or other time-unit) but your application gets a bit more time because every thread gets a small time-slice.
On a dual-processor system, each processor only has to handle half the processes in the same time-unit. But also, each thread can be handled by a specific processor, thus allowing your application to speed up to a maximum of 4 times that of a single-processor, single-thread application.

Thus, the best you'd get is a performance increase factor of 4. It's doubled because the processor is executing less processes and doubled again because it's running over two processes. Your performance won't get much better than this.

Still, people forget that the processor speed isn't the most important factor in application speed. You can have a system with 64 Pentiums XIX at 766 THz with 64 billion terabytes of RAM but if it's a database application that reads it's data from a 2400 RPM harddisk that's connected through an USB 1.1 port, then your application will still run like a snail. (Unless you read the whole database in memory, of course. But that's caching...) A simple Pentium 1 with 64 MB memory and a SCSI harddisk at over 10.000 RPM would out-perform that superfast system in this case. :-)

To improve speed, try to locate the bottlenecks in your application and solve them.

Author Comment

ID: 12238645
I appreciate the comments so far... we have a program which, unfortunately, does a lot of string processing repeatedly, which would be better pre-processed into binary. Luckily it already uses threads. Our software resources are stretched to the max at the moment, so we don't have the time to fix this. So one short-term improvement would be to buy a dual processor system.

Thanks. I'll leave this open for a day or two more to see if any more tips come up.

Geoff M.
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12244051
Lots of string-handling? Then make sure your new system has the fastest RAM available. (And about 512 MB at least.) Also choose a SCSI harddisk for better performance or choose an even faster harddisk setup. If you're handling lots of strings, your system will just eat away memory and start swapping if there isn't enough RAM. Thus, you get lots of memory access and lots of disk access. The processing itself might be just a simple process that might not become much faster with more processor, because as I said, the system might waste time waiting for the harddisk or RAM...
LVL 13

Assisted Solution

BlackTigerX earned 40 total points
ID: 12244358
Workshop Alex has given you pretty good answers, but just to make sure, check your Performance in the Task Manager, and see what your bottle neck problems are, there you should see:

- if the memory utilization is higher than the physical memory, then that's the problem (solution, buy more and faster RAM),
- if the CPU is maxed out (or close), then adding another processor would definetely help because as Workshop Alex says, is not only your program that is using the processor, is Windows, all the services and any other programs that are running

Assisted Solution

Tyrsis earned 40 total points
ID: 12262553
If you are using threads and are string manipulating, then the number one thing you can do to improve speeds (by magnitudes in fact) is replacing delphi's memory manager.  The one suggested by kretz is good (bigbrain), as well as nexus db's memory manager replacement.  There is also another one called RecyclerMM that works well and is completely free, though not as fast as the other two.  

Big brain memory manager replacment can be found at the web site listed above by kretz. has a memory manager replacement which is also good
Also, recyclerMM can be found at

On top of increasing speeds of memory allocations done in delphi, the above units also eliminate memory fragmentation (which, if your program runs for any length of time and does a lot of allocation/deallocation, can lead to a slippery slope condition where you will run out of virtual memory due to how Delphi's memory manager works.)


Author Comment

ID: 12262828
Memory isn't much of a problem - the whole app doesn't use more than 10-20Mb of RAM. Most of the processing is raw back end manipulation. Little visual stuff, and that itself is fairly simple graphics (few Windows controls due to the nature of the software).

Thanks for all the tips. There is no one single answer to this so I'll divide up the points as fairly as I can.

Geoff M.

Expert Comment

ID: 12262908
Actually, memory manager replacement is not about saving memory.  In fact most use MORE memory.  It's actually used to help speed up memory allocations.  For example if you use Strings ANYWHERE and use multiple threads, memory manager replacements can help speed up processing these allocated strings by magnitudes.  I have a program where I can create and destroy probably close to a million strings in the time span of about 10 seconds across 1000 threads.  If it wasn't for memory manager replacements, it wouldn't be anywhere nearly as fast (think of it as memory cacheing of sorts, instead of ditching the memory back to the system, it intelligently keeps it allocated for reuse.  Delphi's MM does this already, but does it poorly across multiple threads due to how it's locking works).

I know a little out of the scope of what you were asking, but I figured it would be useful to know, because this can single handedly decrease CPU usage by magnitudes as well. :)


Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question