diff --git a/arangod/RestServer/ConsoleThread.cpp b/arangod/RestServer/ConsoleThread.cpp index 0cd678d0c6..b5ed584c84 100644 --- a/arangod/RestServer/ConsoleThread.cpp +++ b/arangod/RestServer/ConsoleThread.cpp @@ -151,7 +151,7 @@ void ConsoleThread::inner () { while (! _userAborted) { if (nrCommands >= gcInterval) { - TRI_RunGarbageCollectionV8(isolate, 1.0); + TRI_RunGarbageCollectionV8(isolate, 0.5); nrCommands = 0; } diff --git a/arangod/V8Server/ApplicationV8.cpp b/arangod/V8Server/ApplicationV8.cpp index fffd505bfd..d5edf68736 100644 --- a/arangod/V8Server/ApplicationV8.cpp +++ b/arangod/V8Server/ApplicationV8.cpp @@ -1440,7 +1440,7 @@ void ApplicationV8::shutdownV8Instance (const string& name, size_t i) { localContext->Enter(); v8::Context::Scope contextScope(localContext); - TRI_RunGarbageCollectionV8(isolate, 5.0); + TRI_RunGarbageCollectionV8(isolate, 30.0); TRI_GET_GLOBALS(); if (v8g != nullptr) { diff --git a/lib/V8/v8-utils.cpp b/lib/V8/v8-utils.cpp index 5a98635bf7..504c8a1627 100644 --- a/lib/V8/v8-utils.cpp +++ b/lib/V8/v8-utils.cpp @@ -3954,9 +3954,8 @@ void TRI_CreateErrorObject (v8::Isolate *isolate, TRI_V8_RETURN(TRI_V8_STRING_UTF16( (const uint16_t*) result.getBuffer(), result.length())); } - else { - TRI_V8_RETURN(v8::String::NewFromUtf8(isolate, "")); - } + + TRI_V8_RETURN(v8::String::NewFromUtf8(isolate, "")); } //////////////////////////////////////////////////////////////////////////////// @@ -3982,6 +3981,16 @@ v8::Handle static TRI_V8PathList (v8::Isolate* isolate, string const& return scope.Escape(result); } +//////////////////////////////////////////////////////////////////////////////// +/// @brief execute a single garbage collection run +//////////////////////////////////////////////////////////////////////////////// + +bool TRI_SingleRunGarbageCollectionV8 (v8::Isolate* isolate, + int idleTimeInMs) { + isolate->LowMemoryNotification(); + return isolate->IdleNotification(idleTimeInMs); +} + //////////////////////////////////////////////////////////////////////////////// /// @brief run the V8 garbage collection for at most a specifiable amount of /// time @@ -3994,6 +4003,9 @@ void TRI_RunGarbageCollectionV8 (v8::Isolate* isolate, if (availableTime >= 5.0) { idleTimeInMs = 10000; } + if (availableTime >= 10.0) { + idleTimeInMs = 100000; + } double const until = TRI_microtime() + availableTime; @@ -4007,10 +4019,8 @@ void TRI_RunGarbageCollectionV8 (v8::Isolate* isolate, int gcTries = 0; - isolate->LowMemoryNotification(); while (++gcTries <= gcAttempts) { - if (isolate->IdleNotification(idleTimeInMs)) { - // we're done + if (TRI_SingleRunGarbageCollectionV8(isolate, idleTimeInMs)) { return; } } @@ -4019,14 +4029,10 @@ void TRI_RunGarbageCollectionV8 (v8::Isolate* isolate, while (TRI_microtime() < until) { if (++i % 1000 == 0) { // garbage collection only every x iterations, otherwise we'll use too much CPU - isolate->LowMemoryNotification(); - // todo 1000 was the old V8-default, is this really good? - while (++gcTries <= gcAttempts) { - if (isolate->IdleNotification(idleTimeInMs)) { - // we're done - return; - } - } + if (++gcTries > gcAttempts || + TRI_SingleRunGarbageCollectionV8(isolate, idleTimeInMs)) { + return; + } } usleep(100); diff --git a/lib/V8/v8-utils.h b/lib/V8/v8-utils.h index 8b79463665..d1f686a216 100644 --- a/lib/V8/v8-utils.h +++ b/lib/V8/v8-utils.h @@ -215,6 +215,12 @@ void TRI_CreateErrorObject (v8::Isolate* isolate, void TRI_normalize_V8_Obj (const v8::FunctionCallbackInfo& args, v8::Handle obj); +//////////////////////////////////////////////////////////////////////////////// +/// @brief executes a single garbage collection run +//////////////////////////////////////////////////////////////////////////////// + +bool TRI_SingleRunGarbageCollectionV8 (v8::Isolate*, double); + //////////////////////////////////////////////////////////////////////////////// /// @brief run the V8 garbage collection for at most a specifiable amount of /// time