Limit the number of recycled fibers.

This allows the process to free up memory after heavy load spikes, while not impacting performance negatively.
This commit is contained in:
Sönke Ludwig 2017-05-30 11:00:37 +02:00
parent 0aed5664ef
commit 99a5b882d8
No known key found for this signature in database
GPG key ID: D95E8DB493EE314C
2 changed files with 28 additions and 2 deletions

View file

@ -293,6 +293,7 @@ final package class TaskFiber : Fiber {
ThreadInfo m_tidInfo;
shared size_t m_taskCounter;
shared bool m_running;
bool m_shutdown = false;
shared(ManualEvent) m_onExit;
@ -352,6 +353,7 @@ final package class TaskFiber : Fiber {
logWarn("CoreTaskFiber was resumed with exception but without active task!");
logDiagnostic("Full error: %s", e.toString().sanitize());
}
if (m_shutdown) return;
}
TaskFuncInfo task;
@ -431,6 +433,19 @@ final package class TaskFiber : Fiber {
@property size_t taskCounter() const @safe nothrow { return m_taskCounter; }
/** Shuts down the task handler loop.
*/
void shutdown()
@safe nothrow {
assert(!m_running);
m_shutdown = true;
while (state != Fiber.State.TERM)
() @trusted {
try call(Fiber.Rethrow.no);
catch (Exception e) assert(false, e.msg);
} ();
}
/** Blocks until the task has ended.
*/
void join(bool interruptiple)(size_t task_counter)