1
0
Fork 0

remove superfluous threads after a grace period

This commit is contained in:
Frank Celler 2014-11-10 21:42:32 +01:00
parent 25601bb7d9
commit 9c9bd02454
5 changed files with 31 additions and 4 deletions

View File

@ -35,14 +35,16 @@ endpoint = tcp://0.0.0.0:8529
disable-authentication = yes disable-authentication = yes
# number of server threads # number of server threads
threads = 10 threads = 4
# the user and group are normally set in the start script # the user and group are normally set in the start script
# uid = arangodb # uid = arangodb
# gid = arangodb # gid = arangodb
[scheduler] [scheduler]
threads = 3
# number of threads used for I/O
threads = 1
[javascript] [javascript]
startup-directory = @PKGDATADIR@/js startup-directory = @PKGDATADIR@/js

View File

@ -5,11 +5,11 @@
[server] [server]
disable-authentication = true disable-authentication = true
endpoint = tcp://localhost:8529 endpoint = tcp://localhost:8529
threads = 10 threads = 4
# reuse-address = false # reuse-address = false
[scheduler] [scheduler]
threads = 3 threads = 1
[javascript] [javascript]
startup-directory = ./js startup-directory = ./js

View File

@ -74,6 +74,8 @@ DispatcherQueue::DispatcherQueue (Scheduler* scheduler,
_nrSpecial(0), _nrSpecial(0),
_nrBlocked(0), _nrBlocked(0),
_nrThreads(nrThreads), _nrThreads(nrThreads),
_lastChanged(0.0),
_gracePeriod(5.0),
_scheduler(scheduler), _scheduler(scheduler),
_dispatcher(dispatcher), _dispatcher(dispatcher),
createDispatcherThread(creator) { createDispatcherThread(creator) {
@ -370,6 +372,7 @@ bool DispatcherQueue::startQueueThread () {
} }
else { else {
_nrStarted++; _nrStarted++;
_lastChanged = TRI_microtime();
} }
return ok; return ok;

View File

@ -316,6 +316,18 @@ namespace triagens {
size_t _nrThreads; size_t _nrThreads;
////////////////////////////////////////////////////////////////////////////////
/// @brief last time we created or deleted a queue thread
////////////////////////////////////////////////////////////////////////////////
double _lastChanged;
////////////////////////////////////////////////////////////////////////////////
/// @brief grace period before shuting down queue threads
////////////////////////////////////////////////////////////////////////////////
double _gracePeriod;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief scheduler /// @brief scheduler
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -266,6 +266,16 @@ void DispatcherThread::run () {
tick(true); tick(true);
_queue->_accessQueue.lock(); _queue->_accessQueue.lock();
// there is a chance, that we created more threads than necessary
if (_queue->_nrThreads + _queue->_nrBlocked < _queue->_nrRunning + _queue->_nrStarted + _queue->_nrWaiting) {
double n = TRI_microtime();
if (_queue->_lastChanged + _queue->_gracePeriod < n) {
_queue->_lastChanged = n;
break;
}
}
// wait, if there are no jobs // wait, if there are no jobs
if (_queue->_readyJobs.empty()) { if (_queue->_readyJobs.empty()) {
_queue->_nrRunning--; _queue->_nrRunning--;