Kenneth P. Turvey wrote On 10/06/05 15:40,:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
[quoted text clipped - 3 lines]
> get a hint on how many threads are optimal. It's too bad. That's what
> you really want from the operating system, not how many CPUs it has.
The processor count can be misleading on systems where
some kind of resource management is running -- just because
a CPU is present and idle doesn't mean the system will
necessarily let you have it. There's also the issue of
dynamic reconfiguration, where CPUs can be added to and
removed from "domains" or "partitions" while programs are
running. Still, CPU count is a reasonable default, provided
you offer a way for the user to override it with his superior
knowledge.
The Holy Grail would be some kind of self-adjusting
scheme. For long-running CPU-bound programs such a scheme
might actually work (I confess I haven't tried it). The
idea would be to start a small number of threads, let them
run for a while, and measure the amount of progress they make
per unit time. Then add a few more threads, let the whole
bunch run a little longer, and measure again. If the rate
of progress has improved in approximate proportion to the
increase in thread count, adding those threads was a step in
the right direction and you can try adding a few more. If
progress has improved less than expected (e.g., going from
ten to eleven threads gave only a 2% boost), or if the progress
actually slowed down, you're running too many threads and
should get rid of a few of them.
Of course, not every CPU-bound program is easy to organize
in this manner. The individual "atoms" of work may be too
coarse-grained to permit easy "progress" measurement, the
overall task may not run long enough for the process to converge
on a good thread count, the problem structure may require that
the number of threads be known in advance, and so on. Still,
for some classes of program I think the approach might work.
If you decide to try it, I'd like to hear about your experiences.

Signature
Eric.Sosman@sun.com
Kenneth P. Turvey - 07 Oct 2005 07:03 GMT
[Snip]
> The Holy Grail would be some kind of self-adjusting
> scheme. For long-running CPU-bound programs such a scheme
[quoted text clipped - 10 lines]
> actually slowed down, you're running too many threads and
> should get rid of a few of them.
This would really get complicated when you start throwing in
other jobs running and I/O and everything else. I guess the
way to handle all that would be to look only at the big
picture without delving into the details too much.
[Snip]
> If you decide to try it, I'd like to hear about your experiences.
Unfortunately, or fortunately depending on how you look at it, at
this time I have more than enough entertaining little projects
that produce little or negative amounts of money. :-)
- --
Kenneth P. Turvey <kt-usenet@squeakydolphin.com>
http://kt.squeakydolphin.com (not much there yet)
Jabber IM: kpturvey@jabber.org
Phone: (314) 255-2199
Eric Sosman - 07 Oct 2005 15:39 GMT
Kenneth P. Turvey wrote On 10/07/05 02:03,:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
[quoted text clipped - 20 lines]
> way to handle all that would be to look only at the big
> picture without delving into the details too much.
That's why I specified "long-running CPU-bound programs."
Other kinds of programs often have other "goodness" criteria
than simple throughput -- in a server, for example, latency
may also be important. Also, a server usually faces a varying
load from its clients; if they all go to lunch and the server's
throughput drops to zero, it does not mean that the server is
running the wrong number of threads!
A CPU-bound program faces a constant "demand" (some do,
anyhow), so it doesn't confront the issue of variable client
load. Also, latency and throughput are merely inverses of
each other, so optimizing either optimizes both. That makes
the situation a whole lot simpler, perhaps even tractable.
> [Snip]
>
[quoted text clipped - 3 lines]
> this time I have more than enough entertaining little projects
> that produce little or negative amounts of money. :-)
You lose money on every project, but you make it up
in volume? ;-)

Signature
Eric.Sosman@sun.com