Skip to content

Instantly share code, notes, and snippets.

@athomason
Created May 20, 2011 00:16
Show Gist options
  • Save athomason/982072 to your computer and use it in GitHub Desktop.
Save athomason/982072 to your computer and use it in GitHub Desktop.
AnyEvent::Gearman::Client memory leak
use strict;
use warnings;
use AnyEvent;
use AnyEvent::Gearman::Client;
my $count = shift || 1000;
my $client = AnyEvent::Gearman::Client->new(job_servers => ['127.0.0.1:7003']);
my $cv = AnyEvent->condvar;
my $done = 0;
sub done {
$cv->send if ++$done > $count;
new();
}
sub new {
$client->add_task(
test => 1 =>
on_complete => \&done,
on_error => \&done,
);
}
report();
new();
END { report() }
$cv->recv;
sub report {
open my $stat_fh, '<', '/proc/self/status';
print "$1\n" if join('', <$stat_fh>) =~ /VmSize:\s+(\d+)\s+kB/;
}
use strict;
use warnings;
use Danga::Socket;
use Gearman::Client::Async;
my $count = shift || 1000;
my $client = Gearman::Client::Async->new(job_servers => ['127.0.0.1:7003']);
my $done = 0;
sub done {
exit if ++$done > $count;
new();
}
sub new {
$client->add_task(Gearman::Task->new(
test => \1 => {
on_complete => \&done,
on_fail => \&done,
}));
}
report();
new();
END { report() }
Danga::Socket->EventLoop;
sub report {
open my $stat_fh, '<', '/proc/self/status';
print "$1\n" if join('', <$stat_fh>) =~ /VmSize:\s+(\d+)\s+kB/;
}
use strict;
use warnings;
use Danga::Socket::AnyEvent;
use Gearman::Client::Async;
my $count = shift || 1000;
my $client = Gearman::Client::Async->new(job_servers => ['127.0.0.1:7003']);
my $cv = AnyEvent->condvar;
my $done = 0;
sub done {
exit if ++$done > $count;
new();
}
sub new {
$client->add_task(Gearman::Task->new(
test => \1 => {
on_complete => \&done,
on_fail => \&done,
}));
}
report();
new();
END { report() }
$cv->recv;
sub report {
open my $stat_fh, '<', '/proc/self/status';
print "$1\n" if join('', <$stat_fh>) =~ /VmSize:\s+(\d+)\s+kB/;
}
use strict;
use warnings;
use Gearman::Worker;
my $server = shift || "127.0.0.1:7003";
my $worker = Gearman::Worker->new;
$worker->job_servers($server);
$worker->register_function(test => sub {
return 1;
});
$worker->work while 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment