Solved

TThread and dual processor machines

Posted on 2004-10-06
10
869 Views
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?

Thanks

Geoff M.
0
Comment
Question by:gmayo
  • 2
  • 2
  • 2
  • +4
10 Comments
 
LVL 27

Assisted Solution

by:kretzschmar
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
http://www.havoctribe.org/BigBrain.php
0
 
LVL 11

Assisted Solution

by:calinutz
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
0
 
LVL 12

Assisted Solution

by:Ivanov_G
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.
0
 
LVL 17

Accepted Solution

by:
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.
0
 
LVL 8

Author Comment

by:gmayo
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.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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...
0
 
LVL 13

Assisted Solution

by:BlackTigerX
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
0
 
LVL 3

Assisted Solution

by:Tyrsis
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.  
http://www.nexusdb.com has a memory manager replacement which is also good
Also, recyclerMM can be found at http://glscene.sourceforge.net/RecyclerMM.htm.

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.)

Tyrsis
0
 
LVL 8

Author Comment

by:gmayo
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.
0
 
LVL 3

Expert Comment

by:Tyrsis
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. :)

Tyrsis
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now