Re: A question about multithreading



On Mar 1, 6:01 pm, Joost Diepenmaat <jo...@xxxxxxxxx> wrote:
Ted <r.ted.by...@xxxxxxxxxx> writes:
If I launch ONE child process in one thread, one of the four available
cores is nearly fully utilized (about 95% of that one core's cycles.

This is ofcourse expected.

But if I launch four, the load is distributed evenly over ALL
available cores, but only about 5% of the processor's capacity is
used  This means that the time I have to wait for results is twnety
times longer than it would be if I could get the processor fully
utilitized!  WHY?  Might it have something to do with thread priority?

Since I can't see your code, I would assume this is because of the usual
cause: the threads are actually waiting on some external even like IO to
finish before they can contintue.

If your code is actually badly written, I would suspect your threads are
locking each other out.

If I launch the same four child processes manually, each in its own
separate commandline window, then I get the processor being fully
utilized.  How do I get the same effect by launching threads or child
processes?  But this gets quite tedious very quickly when there are
dozens of scripts to run!

So your threads aren't sharing any data and run faster as separate
processes? use fork() instead. It may be more efficient anyway, Or show
your code.

That is right. Using system 1, "cmd ..." did the trick.

All the real computing is done in stored procedures. The only
difference between one SQL script and the next is that they pass
different data to the same stored procedures.

But two questions remain. Do threads launched by a process get the
same priority as the process, or are they given lower priority. And,
one commonality in how I was launching the SQL scripts was that the
script was invoked taking the script from one file and sending the
output (from standard out) into another file. Would the threads be
sharing standard out making each other wait to output their data to
their respective files?

Thanks

Ted
.


Quantcast