From ebb5adc6eeb7eda8cec92714e1a6dbbbbe66d13d Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Fri, 14 Nov 2014 00:11:09 +0000 Subject: [PATCH] [#164] Workers should restart periodically They restart once a day, if the worker completes a job at least every hour. The worker ID is compared to the hour of day and if the modulus matches, then it exits (and is restarted by MCE). Should do the trick with memory usage. --- Netdisco/Changes | 1 + Netdisco/lib/App/Netdisco/Daemon/Worker/Common.pm | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/Netdisco/Changes b/Netdisco/Changes index ea92759b..e1e39f3a 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -4,6 +4,7 @@ * [#161] Updated IOS-XR SSHCollector * [#165] Mention system clock in docs + * [#164] Workers should restart periodically [BUG FIXES] diff --git a/Netdisco/lib/App/Netdisco/Daemon/Worker/Common.pm b/Netdisco/lib/App/Netdisco/Daemon/Worker/Common.pm index 437be666..ff232cc7 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/Worker/Common.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/Worker/Common.pm @@ -38,6 +38,13 @@ sub worker_body { }; $self->close_job($job); + + # restart worker once a day. + # relies on the worker seeing a job at least every hour. + my $hour = [localtime()]->[2]; + if ($wid and (($wid % 24) == $hour)) { + $self->exit(0, "recycling worker $wid"); + } } }