Regarding run when blocked policy

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Regarding run when blocked policy

NarayanaSwamy

 

Hi,

Created the PooledExecuter with the following

1.       No Queue

2.       min pool size as 11

3.       max pool size as 13

4.       keep alive time as -1

5.       created 11 threads initially

6.       blocked execution policy is RunWhenBlocked

 

Now I am executing 26 runnable tasks. (All are independent and each task will sleep for 6 minutes)  [Issuing using a for loop]

 

I found that less than 14 tasks are executed initially (This is very random).

 

I think, the SynchronousChnnel.offer returns false and so this happens…. But I am not able to get the correct reason.

Can you please let me know the details regarding this?

 

Regards,

NarayanaSwamy A.

 

 


_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Regarding run when blocked policy

Joe Bowbeer
With max pool size of 13 and run-when-blocked policy (aka
"caller-runs"), the maximum number of concurrent tasks is

13 + (# of submitting threads)

In your case, this would be 13 long-running tasks executed by pool
threads, and then every subsequent task will be executed by the thread
that submits it.  (The meaning of run-when-blocked is that the thread
that submits the blocked task will run the task itself.)

If you have one thread submitting tasks, then a max of 14 is expected.


On 4/7/06, NarayanaSwamy <[hidden email]> wrote:

>
> Hi,
>
> Created the PooledExecuter with the following
>
> 1.       No Queue
> 2.       min pool size as 11
> 3.       max pool size as 13
> 4.       keep alive time as -1
> 5.       created 11 threads initially
> 6.       blocked execution policy is RunWhenBlocked
>
> Now I am executing 26 runnable tasks. (All are independent and each task
> will sleep for 6 minutes)  [Issuing using a for loop]
>
> I found that less than 14 tasks are executed initially (This is very
> random).
>
> I think, the SynchronousChnnel.offer returns false and so this happens…. But
> I am not able to get the correct reason.
>
> Can you please let me know the details regarding this?
>
> Regards,
>
> NarayanaSwamy A.
>

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

RE: Regarding run when blocked policy

David Holmes-3
In reply to this post by NarayanaSwamy
There are a lot of potential timing issues here. How many CPU's do you have? Do you wait for a while after creating the pool so that you can assume that all the core pool threads are blocked waiting to take a task from the queue?
 
Otherwise consider this scenario:
 
1. You create the TPE and prestart the 11 core threads
2. Those core threads are in varying stages of getting to the queue to pull a task from it
3. You submit task A:
   i. poolsize == coresize so you offer the task to the queue
   ii.assume no worker got to the queue yet, the offers fails
   iii. as poolSize < maxSize you create another pool thread *and* hand it
        task A
4. You submit task B:
   i. poolsize == coresize so you offer the task to the queue
   ii.assume no worker got to the queue yet, the offers fails
   iii. as poolSize < maxSize you create another pool thread *and* hand it
        task B
5. You submit task C:
   i. poolsize == coresize so you offer the task to the queue
   ii.assume no worker got to the queue yet, the offers fails
   iii. as poolSize == maxSize you reject the task
   iv. Task C runs in the submitter thread
 
So in this worst-case scenario you only got to execute two tasks before one gets rejected. How many tasks actually run before the caller runs one depends on how many pre-started threads manage to get to do a take() on the queue.
 
If you don't pre-start the core threads then creating a thread hands a task directly to it so you are guaranteed to get at least maxPoolSize tasks accepted before any rejections.
 
What you are seeing is an intentional but somewhat quirky consequence of both using a synchronous queue and pre-starting core thread.
 
Cheers,
David Holmes
 
-----Original Message-----
From: [hidden email] [mailto:[hidden email]]On Behalf Of NarayanaSwamy
Sent: Saturday, 8 April 2006 2:39 AM
To: [hidden email]
Subject: [concurrency-interest] Regarding run when blocked policy

 

Hi,

Created the PooledExecuter with the following

1.       No Queue

2.       min pool size as 11

3.       max pool size as 13

4.       keep alive time as -1

5.       created 11 threads initially

6.       blocked execution policy is RunWhenBlocked

 

Now I am executing 26 runnable tasks. (All are independent and each task will sleep for 6 minutes)  [Issuing using a for loop]

 

I found that less than 14 tasks are executed initially (This is very random).

 

I think, the SynchronousChnnel.offer returns false and so this happens…. But I am not able to get the correct reason.

Can you please let me know the details regarding this?

 

Regards,

NarayanaSwamy A.

 

 


_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest