Subject: | ::Query has a memory leak? |
This may be related to the $query->{_iterator} circular reference mentioned in https://rt.cpan.org/Ticket/Display.html?id=81548 but any long process will increase the memory footprint until it's killed by the OS.
I've attached a test script (requires Test::Memory::Usage) that illustrates this.
2,500 'simple' queries results in:
➔ prove -l t/006_memory.t
t/006_memory.t .. 2/?
# Failed test 'virtual memory usage grows less than 10%'
# at /home/chisel/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Test/Memory/Usage.pm line 48.
# virtual memory usage grew from 68212 to 99116 (145.3%)
# Failed test 'RSS memory usage grows less than 10%'
# at /home/chisel/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Test/Memory/Usage.pm line 52.
# RSS memory usage grew from 27548 to 58476 (212.3%)
# Failed test 'data/stack memory usage grows less than 10%'
# at /home/chisel/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Test/Memory/Usage.pm line 56.
# data/stack memory usage grew from 68212 to 99116 (145.3%)
# Looks like you failed 3 tests of 4.
t/006_memory.t .. Dubious, test returned 3 (wstat 768, 0x300)
Failed 3/4 subtests
Test Summary Report
-------------------
t/006_memory.t (Wstat: 768 Tests: 4 Failed: 3)
Failed tests: 2-4
Non-zero exit status: 3
Files=1, Tests=4, 20 wallclock secs ( 0.02 usr 0.01 sys + 12.93 cusr 1.45 csys = 14.41 CPU)
Result: FAIL
[507][chisel@pilchard:REST-Neo4p-0.2252][master✘]➔
Subject: | 006_memory.t |
#-*-perl-*-
#$Id: 006_query.t 428 2014-05-15 02:52:21Z maj $
use Test::More;
use Data::Dumper;
use Test::Exception;
use Module::Build;
use lib '../lib';
use strict;
use warnings;
no warnings qw(once);
my @cleanup;
use_ok('REST::Neo4p');
use Test::Memory::Usage;
# $SIG{__DIE__} = sub { if (ref $_[0]) { $_[0]->rethrow } else { print $_[0] }};
my $build;
my ($user,$pass);
eval {
$build = Module::Build->current;
$user = $build->notes('user');
$pass = $build->notes('pass');
};
my $TEST_SERVER = $build ? $build->notes('test_server') : 'http://127.0.0.1:7474';
my $num_live_tests = 1;
my $not_connected;
eval {
REST::Neo4p->connect($TEST_SERVER,$user,$pass);
};
if ( my $e = REST::Neo4p::CommException->caught() ) {
$not_connected = 1;
diag "Test server unavailable : tests skipped";
}
use Data::Printer alias=>'dpp';
memory_usage_start;
#subtest "many queries don't increase memory usage" => sub {
for (1 .. 2_500) {
my $q = REST::Neo4p::Query->new(
'MATCH (p:Product)-[r]-(s:Size) DELETE r'
);
$q->execute;
while (my $row = $q->fetchrow_arrayref) {
# we don't care
};
# try to force things to cleam up
$q->finish;
undef $q;
}
#};
memory_usage_ok;
END {
CLEANUP : {
ok ($_->remove,'entity removed') for reverse @cleanup;
}
done_testing;
}