diff options
author | Marc Laukien <marc@zeroc.com> | 2005-06-23 14:19:36 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2005-06-23 14:19:36 +0000 |
commit | 6a5fea4951f6191ae774400440ab6d36ad3bf8eb (patch) | |
tree | 4e14e1c09e0dd2bba8e731f4011c82c3053a85c4 /cpp/src/Ice/ThreadPool.cpp | |
parent | Added ifdefs around server code (diff) | |
download | ice-6a5fea4951f6191ae774400440ab6d36ad3bf8eb.tar.bz2 ice-6a5fea4951f6191ae774400440ab6d36ad3bf8eb.tar.xz ice-6a5fea4951f6191ae774400440ab6d36ad3bf8eb.zip |
fixed load factor for thread pools
Diffstat (limited to 'cpp/src/Ice/ThreadPool.cpp')
-rw-r--r-- | cpp/src/Ice/ThreadPool.cpp | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/cpp/src/Ice/ThreadPool.cpp b/cpp/src/Ice/ThreadPool.cpp index 6609421d50f..0e4c59a3b2a 100644 --- a/cpp/src/Ice/ThreadPool.cpp +++ b/cpp/src/Ice/ThreadPool.cpp @@ -37,7 +37,7 @@ IceInternal::ThreadPool::ThreadPool(const InstancePtr& instance, const string& p _stackSize(0), _running(0), _inUse(0), - _load(0), + _load(1.0), _promote(true), _warnUdp(_instance->properties()->getPropertyAsInt("Ice.Warn.Datagrams") > 0) { @@ -667,14 +667,37 @@ IceInternal::ThreadPool::run() // Now we check if this thread can be destroyed, based // on a load factor. // - const double loadFactor = 0.05; // TODO: Configurable? - const double oneMinusLoadFactor = 1 - loadFactor; - _load = _load * oneMinusLoadFactor + _inUse * loadFactor; + + // + // The load factor jumps immediately to the number of + // threads that are currently in use, but decays + // exponentially if the number of threads in use is + // smaller than the load factor. This reflects that we + // create threads immediately when they are needed, + // but want the number of threads to slowly decline to + // the configured minimum. + // + double inUse = static_cast<double>(_inUse); + if(_load < inUse) + { + _load = inUse; + } + else + { + const double loadFactor = 0.05; // TODO: Configurable? + const double oneMinusLoadFactor = 1 - loadFactor; + _load = _load * oneMinusLoadFactor + inUse * loadFactor; + } if(_running > _size) { - int load = static_cast<int>(_load + 1); - if(load < _running) + int load = static_cast<int>(_load + 0.5); + + // + // We add one to the load factor because on + // additional thread is needed for select(). + // + if(load + 1 < _running) { assert(_inUse > 0); --_inUse; |