[whatwg] [Web workers] An attribute describing the "best" number of worker to invoke in a delegation use case
Ian Hickson
ian at hixie.ch
Tue Dec 1 02:28:10 PST 2009
On Wed, 11 Nov 2009, David Bruant wrote:
>
> This is a new proposal taking into account the feedback I recieved to
> the "[WebWorkers] About the delegation example" message.
>
> In the delegation example of the WebWorker spec, we can see this line :
> "var num_workers = 10;"
>
> My concern is about the arbitrarity of the "10".
I agree that it's suboptimal. However, I think realistically a good
implementation of parallel work would need some sort of dynamic
performance tuning, continuously slowly ramping up the number of workers
while it increases throughput, and when throughput decreases, switching to
reducing the number of workers until throughput increases again. That
would probably be too complicated to show in an example in the spec.
> My proposal is to add an attribute to the navigator object to write this :
> "var num_workers = navigator.optimalWorkerNumber;
> var items_per_worker = 10000000/num_workers;" (uneven dividing can
> easily be solved)
> (the name "optimalWorkerNumber" is not good, but I will use it in the
> rest of this e-mail)
optimalWorkerNumber is a function of time and of the algorithm that the
worker implements. I don't think it would solve the problem.
> This attribute have the following properties :
> - It's only dependant on the hardware, the operating system and the
> WebWorker implementation (thus, it is not dynamically computed by the
> user agent at each call and two calls in the same
> hardware//OS//WebWorker implementation have the same result).
> - In the same running conditions (same memory available, same number of
> process running concurrently...) running the "same algorithm" (an easy
> delegation algorithm) has a significantly better performance with
> (navigator.optimalWorkerNumber) workers than
> (navigator.optimalWorkerNumber - 1) workers
> - In the same running conditions, running the same algorithm has no
> significantly better performance with (navigator.optimalWorkerNumber +1)
> workers than (navigator.optimalWorkerNumber) workers
I do not think it is possible to satisfy all of the above conditions at
the same time.
On Thu, 12 Nov 2009, David Bruant wrote, in response to Boris saying much
the same as what I wrote above:
>
> => You're perfectly right. I reformulate the definition of "running
> conditions" (appearing in condition 2 and 3) as :
> "same memory available, same number of process running concurrently, no
> other worker running working on the same document".
On Thu, 12 Nov 2009, Boris Zbarsky wrote:
>
> That doesn't help that much, unfortunately. Most simply, consider a
> quad-core chip and workers that are completely cpu-bound. If there are
> no other processes running, the optimal number of workers is 4. If
> there is one other process which is also completely cpu-bound running,
> the optimal number of workers is 3 (in the sense that 4 may well not
> satisfy your condition 3). This is really the same issue as having one
> worker running, but it's some process not under the browser's control.
>
> If, on the other hand, the workers are I/O bound (esp. network I/O
> latency bound), then the optimal number of workers can well be larger
> than the number of cores...
On Thu, 12 Nov 2009, David Bruant wrote:
>
> => If you are comparing "no other processes running" and "one other
> process which is also completely cpu-bound running", you are not in what
> I've called "same running conditions". (because the number of concurrent
> processes is different).
The point is that the constant can't be constant if it has to return a
different number based on conditions outside the UA's control.
> I reformulate this way the conditions 2 and 3:
> - In "blank conditions" (no other processes/thread running on the CPU,
> enough memory to allocate the workers), running the same algorithm (an
> easy delegation algorithm) has significantly better performances with
> (navigator.optimalWorkerNumber) dedicated workers than with
> (navigator.optimalWorkerNumber -1) dedicated workers
> - In "blank conditions", running the same algorithm has no significantly
> better performances with (navigator.optimalWorkerNumber+1) dedicated
> workers than with (navigator.optimalWorkerNumber) dedicated workers
This isn't especially useful, since "blank conditions" are never met by a
running script (for one, the script is running).
> Just to remind, the purpose of this attribute is to decide, at the
> beginning of a delegation algorithm what is the "optimal" number of
> workers to divide the work in a way that is optimal regarding the
> hardware, the OS and the worker implementation.
> No matter the running conditions, 2 calls return the same value for the
> same hardware//OS//Worker implementation.
> The idea behind this property is that even if you start running the
> algorithm with a lot of concurrent processes, you create a number of
> workers that cannot be ran concurrently at the beginning, but you may
> use optimally the ressources later (if the other processes/threads stop
> running, what you cannot control, but can still hope that it happens
> during the "algorithm lifetime". According to the spec, "workers are
> expected to be long-lived").
Basically, this would encourage authors to always use too many workers, as
far as I can tell.
On Thu, 12 Nov 2009, David Bruant wrote:
>
> => I think it happens very often. While I'm writing this e-mail, "no
> process" is running. About fifty processes are runnable, but not
> running. They are passively waiting. My CPU is barely used.
You're lucky. :-) My CPU is almost always at at least 25%.
> My point is that this number may be available very easily. For example,
> in my dual-core, Linux, Firefox 3.5, the number is 2. Why spare an
> information that can be useful and reliable (more than measurement at
> least !) ?
It's actually probably quite rarely 2. It depends on all kinds of factors,
like the kind of algorithm, what other programs are running, etc.
I still haven't added this feature, as I do not believe the arguments
presented form a convincing case. However, if you are still interested in
persuing this feature, I encourage you to convince a browser vendor to
implement it, as discussed here:
http://wiki.whatwg.org/wiki/FAQ#Is_there_a_process_for_adding_new_features_to_a_specification.3F
Cheers,
--
Ian Hickson U+1047E )\._.,--....,'``. fL
http://ln.hixie.ch/ U+263A /, _.. \ _\ ;`._ ,.
Things that are impossible just take longer. `._.-(,_..'--(,_..'`-.;.'
More information about the whatwg
mailing list