From: Tyler Riddle Date: Wed, 10 Oct 2012 23:14:24 +0000 (-0700) Subject: reduce memory consumption and number of open connections as gather progresses; wrap... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=311dc0ff67c5eb9758828a62d9e67461e406052b;p=scpubgit%2FSystem-Introspector.git reduce memory consumption and number of open connections as gather progresses; wrap storage reset with eval so errors with that do not abort the rest of the gathers --- diff --git a/lib/System/Introspector/State.pm b/lib/System/Introspector/State.pm index 2bbfcdf..a2a7261 100644 --- a/lib/System/Introspector/State.pm +++ b/lib/System/Introspector/State.pm @@ -15,6 +15,12 @@ has root => (is => 'ro', required => 1); sub user { $_[0]->config->user } sub sudo_user { $_[0]->config->sudo_user } +#TODO if a connection fails the host will be tried +#again on the next gather cycle if there is more +#than one group - the unconnectable host should +#be removed from the configured host list if this +#happens because it makes the console output a +#bit messy sub gather { my ($self, @groups) = @_; log_debug { "Starting to gather results" }; @@ -51,7 +57,8 @@ sub gather { push @waiting, $to_fetch; } log_debug { sprintf("There are %i hosts in the waiting list", scalar(@waiting)) }; - for my $wait (@waiting) { + + while(defined(my $wait = shift(@waiting))) { my ($host, @futures) = @$wait; my $report; @@ -133,8 +140,6 @@ sub _store { } split m{::}, $class; my $fh = $storage->open('>:utf8', $file, mkpath => 1); my $full_path = $storage->file($file); - log_trace { "Collecting probe data for '$class' from '$host'" }; - my $data = $gathered->get_probe_data($class); log_debug { "Generated file name for storage: '$file'; Writing state to '$full_path'" }; print $fh encode_json($gathered->get_probe_data($class)); push @files, $full_path; @@ -147,7 +152,12 @@ sub _store { unless ($ok) { log_error { "Rolling back snapshot because of: " . $@ || 'unknown error' }; - $storage->reset; + eval { $storage->reset }; + + if ($@) { + log_error { "Could not roll back snapshot: $@" }; + } + return 0; } return 1;