Multi threaded failure

T

trant

I was trying to enhance my application which loads data from thousands of
files by making it multi threaded but I ended up instead of halving the time
with 2 threads for example I managed to double it!

So apparently there is some major contention going on and this app is very
complex so I was hoping you guys know of a good way to discover the
bottleneck maybe something within the IDE itself or some other trick?

It's just way to complex and long to even think about posting any code
 
A

Adam Benson

Well, just a general observation.

Adding threads won't necessarily make a program faster.
If you're loading data from lots of files simultaneously hitting the hard
disk will be a lot slower than allowing your hard disk to load from one file
at once.

Threading will only make things faster if your machine can genuinely be
doing 2 things at once and if your machine has more than 1 cpu.

AB
 
P

Peter Duniho

trant said:
I was trying to enhance my application which loads data from thousands of
files by making it multi threaded but I ended up instead of halving the time
with 2 threads for example I managed to double it!

So apparently there is some major contention going on and this app is very
complex so I was hoping you guys know of a good way to discover the
bottleneck maybe something within the IDE itself or some other trick?

It's just way to complex and long to even think about posting any code

Nothing is "way too complex and long to even think about posting any
code". It is always possible to refine existing code to come up with a
smaller, simpler example that still reproduces the same problem.

As for the threading issue generally, it certainly is possible to
implement the threading behavior incorrectly and wind up with more
overhead than gain. But without a code example, it's extremely
difficult to suggest what might be the problem. Some things you need to
be aware of though:

-- too much dependency between threads can result in serializing
data access and processing, which when added to the overhead of the
syncronization can result in lower performance

-- depending on the hardware, cache aliasing can cause multiple
threads to destroy performance by causing data in a cache shared between
CPU cores to constantly be flushed out

-- of course, you are not going to see gains greater than the
number of CPU cores in the hardware, and exceeding the number of CPU
cores in your number of threads by any significant amount can cause
context-switching overhead to dominate the processing costs, further
reducing throughput

-- similar to the above, any other resource (e.g. a hard drive)
shared by all the threads will reduce throughput, sometimes
significantly. To see a performance improvement, you really need some
practical way for each thread to work independently. If they are all
trying (for example) to access the same hard drive, then the hard
drive's throughput can be reduced significantly as it tries to satisfy
all the different i/o requests (obviously this is very dependent on
where the data on the disk is and how fast the drive is, as compared to
the number of threads...with a very small number of threads, there's a
theoretical possibility that having multiple i/o requests running
concurrently can allow the disk i/o system to optimize accesses to the
data, but you'll hit the wall of diminishing returns very quickly as you
add threads; one thread per i/o resource is the safest).

Any, all, or none of the above might be applicable in your situation.
If you don't post a concise-but-complete code example, there's no way
for anyone to know.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top