diff options
author | Benoit Foucher <benoit@zeroc.com> | 2009-02-10 15:08:16 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2009-02-11 12:03:17 +0100 |
commit | 0a3e143c041ef47dc13bc84d742bc472923f6557 (patch) | |
tree | cae8cdf83a82094d848ad31ffceee16ca7634f73 /cpp/src/Ice/ThreadPool.cpp | |
parent | Fixed bug 3706 - invalid SocketException handler (diff) | |
download | ice-0a3e143c041ef47dc13bc84d742bc472923f6557.tar.bz2 ice-0a3e143c041ef47dc13bc84d742bc472923f6557.tar.xz ice-0a3e143c041ef47dc13bc84d742bc472923f6557.zip |
Fixed bug 3720 - Added check for dynamic thread pool
Diffstat (limited to 'cpp/src/Ice/ThreadPool.cpp')
-rw-r--r-- | cpp/src/Ice/ThreadPool.cpp | 106 |
1 files changed, 55 insertions, 51 deletions
diff --git a/cpp/src/Ice/ThreadPool.cpp b/cpp/src/Ice/ThreadPool.cpp index ab41198104c..6a3d26c95c5 100644 --- a/cpp/src/Ice/ThreadPool.cpp +++ b/cpp/src/Ice/ThreadPool.cpp @@ -554,70 +554,74 @@ IceInternal::ThreadPool::run() handler->_serializing = false; } - // - // First we reap threads that have been destroyed before. - // - int sz = static_cast<int>(_threads.size()); - assert(_running <= sz); - if(_running < sz) + if(_size < _sizeMax) // Dynamic thread pool { - vector<IceUtil::ThreadPtr>::iterator start = - partition(_threads.begin(), _threads.end(), IceUtil::constMemFun(&IceUtil::Thread::isAlive)); - - for(vector<IceUtil::ThreadPtr>::iterator p = start; p != _threads.end(); ++p) + // + // First we reap threads that have been destroyed before. + // + int sz = static_cast<int>(_threads.size()); + assert(_running <= sz); + if(_running < sz) { - (*p)->getThreadControl().join(); - } + vector<IceUtil::ThreadPtr>::iterator start = + partition(_threads.begin(), _threads.end(), + IceUtil::constMemFun(&IceUtil::Thread::isAlive)); - _threads.erase(start, _threads.end()); - } - - // - // Now we check if this thread can be destroyed, based - // on a load factor. - // + for(vector<IceUtil::ThreadPtr>::iterator p = start; p != _threads.end(); ++p) + { + (*p)->getThreadControl().join(); + } - // - // 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; - } + _threads.erase(start, _threads.end()); + } - if(_running > _size) - { - int load = static_cast<int>(_load + 0.5); + // + // Now we check if this thread can be destroyed, based + // on a load factor. + // // - // We add one to the load factor because on - // additional thread is needed for select(). + // 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. // - if(load + 1 < _running) + double inUse = static_cast<double>(_inUse); + if(_load < inUse) + { + _load = inUse; + } + else { - assert(_inUse > 0); - --_inUse; + 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 + 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; - assert(_running > 0); - --_running; + assert(_running > 0); + --_running; - return false; + return false; + } } } - + assert(_inUse > 0); --_inUse; } |