diff --git a/etc/arangodb/arangod.conf.in b/etc/arangodb/arangod.conf.in index 89eb83104b..ff1f694b31 100644 --- a/etc/arangodb/arangod.conf.in +++ b/etc/arangodb/arangod.conf.in @@ -35,14 +35,16 @@ endpoint = tcp://0.0.0.0:8529 disable-authentication = yes # number of server threads -threads = 10 +threads = 4 # the user and group are normally set in the start script # uid = arangodb # gid = arangodb [scheduler] -threads = 3 + +# number of threads used for I/O +threads = 1 [javascript] startup-directory = @PKGDATADIR@/js diff --git a/etc/relative/arangod.conf b/etc/relative/arangod.conf index b4038cc82f..0367df73c9 100644 --- a/etc/relative/arangod.conf +++ b/etc/relative/arangod.conf @@ -5,11 +5,11 @@ [server] disable-authentication = true endpoint = tcp://localhost:8529 -threads = 10 +threads = 4 # reuse-address = false [scheduler] -threads = 3 +threads = 1 [javascript] startup-directory = ./js diff --git a/lib/Dispatcher/DispatcherQueue.cpp b/lib/Dispatcher/DispatcherQueue.cpp index 5de1549bad..6e899e7694 100644 --- a/lib/Dispatcher/DispatcherQueue.cpp +++ b/lib/Dispatcher/DispatcherQueue.cpp @@ -74,6 +74,8 @@ DispatcherQueue::DispatcherQueue (Scheduler* scheduler, _nrSpecial(0), _nrBlocked(0), _nrThreads(nrThreads), + _lastChanged(0.0), + _gracePeriod(5.0), _scheduler(scheduler), _dispatcher(dispatcher), createDispatcherThread(creator) { @@ -370,6 +372,7 @@ bool DispatcherQueue::startQueueThread () { } else { _nrStarted++; + _lastChanged = TRI_microtime(); } return ok; diff --git a/lib/Dispatcher/DispatcherQueue.h b/lib/Dispatcher/DispatcherQueue.h index 45b9294e76..d9bcbd7a3f 100644 --- a/lib/Dispatcher/DispatcherQueue.h +++ b/lib/Dispatcher/DispatcherQueue.h @@ -316,6 +316,18 @@ namespace triagens { 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 //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/Dispatcher/DispatcherThread.cpp b/lib/Dispatcher/DispatcherThread.cpp index 00c5d60166..420904ca8c 100644 --- a/lib/Dispatcher/DispatcherThread.cpp +++ b/lib/Dispatcher/DispatcherThread.cpp @@ -266,6 +266,16 @@ void DispatcherThread::run () { tick(true); _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 if (_queue->_readyJobs.empty()) { _queue->_nrRunning--;