8000 micro optimizations · thurt/arangodb@3d6582e · GitHub
[go: up one dir, main page]

Skip to content

Commit 3d6582e

Browse files
committed
micro optimizations
1 parent e411b88 commit 3d6582e

File tree

6 files changed

+39
-17
lines changed

6 files changed

+39
-17
lines changed

arangod/Aql/QueryRegistry.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,11 @@ void QueryRegistry::destroy (TRI_vocbase_t* vocbase,
290290
////////////////////////////////////////////////////////////////////////////////
291291

292292
void QueryRegistry::expireQueries () {
293+
double now = TRI_microtime();
293294
std::vector<std::pair<std::string, QueryId>> toDelete;
295+
294296
{
295297
WRITE_LOCKER(_lock);
296-
double now = TRI_microtime();
297298
for (auto& x : _queries) {
298299
// x.first is a TRI_vocbase_t* and
299300
// x.second is a std::unordered_map<QueryId, QueryInfo*>
@@ -307,6 +308,7 @@ void QueryRegistry::expireQueries () {
307308
}
308309
}
309310
}
311+
310312
for (auto& p : toDelete) {
311313
try { // just in case
312314
destroy(p.first, p.second, TRI_ERROR_TRANSACTION_ABORTED);

arangod/Statistics/statistics.cpp

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,17 +338,37 @@ static TRI_thread_t StatisticsThread;
338338
////////////////////////////////////////////////////////////////////////////////
339339

340340
static void StatisticsQueueWorker (void* data) {
341-
while (! Shutdown && TRI_ENABLE_STATISTICS) {
341+
uint64_t sleepTime = 100 * 1000;
342+
uint64_t const MaxSleepTime = 250 * 1000;
343+
int nothingHappened = 0;
344+
345+
while (! Shutdown.load(std::memory_order_relaxed) && TRI_ENABLE_STATISTICS) {
342346
size_t count = ProcessAllRequestStatistics();
343347

344348
if (count == 0) {
345-
usleep(100 * 1000);
346-
}
347-
else if (count < 10) {
348-
usleep(10 * 1000);
349+
if (++nothingHappened == 10 * 30) {
350+
// increase sleep time every 30 seconds
351+
nothingHappened = 0;
352+
sleepTime += 50 * 1000;
353+
if (sleepTime > MaxSleepTime) {
354+
sleepTime = MaxSleepTime;
355+
}
356+
}
357+
#ifdef _WIN32
358+
usleep((unsigned long) sleepTime);
359+
#else
360+
usleep((useconds_t) sleepTime);
361+
#endif
349362
}
350-
else if (count < 100) {
351-
usleep(1 * 1000);
363+
else {
364+
nothingHappened = 0;
365+
366+
if (count < 10) {
367+
usleep(10 * 1000);
368+
}
369+
else if (count < 100) {
370+
usleep(1 * 1000);
371+
}
352372
}
353373
}
354374

arangod/V8Server/V8PeriodicTask.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ bool V8PeriodicTask::handlePeriod () {
118118
_v8Dealer,
119119
"(function (params) { " + _command + " } )(params);",
120120
_parameters,
121-
_allowUseDatabase);
121+
_allowUseDatabase
122+
);
122123

123124
if (_dispatcher->addJob(job) != TRI_ERROR_NO_ERROR) {
124125
// just in case the dispatcher cannot accept the job (e.g. when shutting down)

arangod/V8Server/V8PeriodicTask.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
#define ARANGODB_V8SERVER_V8PERIODIC_TASK_H 1
3131

3232
#include "Basics/Common.h"
33-
3433
#include "Scheduler/PeriodicTask.h"
35-
3634
#include "VocBase/vocbase.h"
3735

3836
struct TRI_json_t;

arangod/VocBase/server.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,8 @@ static int WriteDropMarker (TRI_voc_tick_t id) {
14821482
////////////////////////////////////////////////////////////////////////////////
14831483

14841484
static void DatabaseManager (void* data) {
1485-
TRI_server_t* server = static_cast<TRI_server_t*>(data);
1485+
auto server = static_cast<TRI_server_t*>(data);
1486+
auto queryRegistry = static_cast<triagens::aql::QueryRegistry*>(server->_queryRegistry);
14861487
int cleanupCycles = 0;
14871488

14881489
while (true) {
@@ -1592,16 +1593,16 @@ static void DatabaseManager (void* data) {
15921593

15931594
usleep(DATABASE_MANAGER_INTERVAL);
15941595
// The following is only necessary after a wait:
1595-
auto queryRegistry = static_cast<triagens::aql::QueryRegistry*>
1596-
(server->_queryRegistry);
15971596
if (queryRegistry != nullptr) {
15981597
queryRegistry->expireQueries();
15991598
}
16001599

16011600
// on a coordinator, we have no cleanup threads for the databases
16021601
// so we have to do cursor cleanup here
1603-
if (triagens::arango::ServerState::instance()->isCoordinator() &&
1604-
++cleanupCycles == 10) {
1602+
if (++cleanupCycles >= 10 &&
1603+
triagens::arango::ServerState::instance()->isCoordinator()) {
1604+
// note: if no coordinator then cleanupCycles will increase endlessly,
1605+
// but it's only used for the following part
16051606
cleanupCycles = 0;
16061607

16071608
auto unuser(server->_databasesProtector.use());

js/server/modules/@arangodb/foxx/queues/manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ exports.manage = function () {
124124
global.KEYSPACE_CREATE('queue-control', 1, true);
125125
var delayUntil = global.KEY_GET('queue-control', 'delayUntil') || 0;
126126

127-
if (delayUntil > Date.now() || delayUntil === -1) {
127+
if (delayUntil === -1 || delayUntil > Date.now()) {
128128
return;
129129
}
130130

0 commit comments

Comments
 (0)
0