# [whatwg] [Web workers] An attribute describing the "best" number of worker to invoke in a delegation use case

David Bruant bruant at enseirb-matmeca.fr
Mon Dec 7 14:08:28 PST 2009

```Ian Hickson a écrit :
> 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.
>
=> As far as I know, if the running time is a decreasing function of the
number of workers (which seems to be a non-such-trivial assumption), the
best algorithm (on average, of course !) is to double the number of
workers until finding a barrier in the running time (find n such as the
max is between [2^n, 2^(n+1)[ ). Then, use a dichotomy algorithm in this
interval.

However, running this algorithm each time a UA comes in your website can
become to be costly.
I think that the spec should say something about "finding the correct
number of thread for your problem" and encourage authors to store their
value with the local storage and add a date to re-run the algorithm if
the value is old (more than two months ?)

>> 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:
>
>
> Cheers,
>
I understand now that my proposition was not very realistic. However, I
think that something should be described in the spec to avoid arbitrary
choices of number of workers.

I'm convinced that with canvas and workers, we will see very soon fancy
web video games with AI. Authors of those games will want to use as many
computation power as possible for their AI, so the "best number of
workers" will be a value that they are interested in.

So, either an "hint" can be provided by the spec through the Navigator
object, either the spec could provide the above described method
(improve my description or ask me to improve it if you want) to find the
"best" number (according to a particular problem).

Thanks,

David

```