• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Auto tuning ThreadPool in runtime

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have this common situation in which I have a set of tasks to execute.
Each tasks has:
- a part that execute a certain code (it spends time Te)
- and a part it has to wait for an amount of time that I call Tw.

In this situation it's good using a ThreadPool of size (1+ Tw/Te).

The problem is that Tw is not constant, and it changes during the time: so I would like to have a System that increase or decrease the size of the Pool given the Tw that I calculate.

And now my question:
Do you know if there are some systems already made that "auto-tune" the size of the ThreadPool? I would like to know if there are solutions already done to that!

Thank you in advance!!! :-)
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Executors.newCachedThreadPool() tunes the number of threads. See its Javadoc for details. However to tune the number in the number of threads as you suggest you can override submit, beforeExecute and/or afterExecute in ThreadPoolExecutor to do what you want.
 
Enrico Tamellin
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your tip! :-)
... but I think I can't use your solution in my application.

The fact is that if I have 1000 requests of executions in a rush, I will have 1000 Thread running in the same time: this could be a problem because it increases the amount of Context Switch.

So if I know exactly the time of execution Te and the time of wait Tw and they are constant, the optimum thread pool size will be (1 + Tw/Te) so I can have a system that use 100% his resources without a relevant Context Switch. I have already done it.

BUT, if I have Tw not constant it will be a problem. I will have to calculate it! So I would like to know if someone know there are classes or solution to this already done in Internet.
 
I will suppress my every urge. But not this shameless plug:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic