p-alik / perl-Gearman

9 stars 10 forks source link

Gearman::Worker->work ignores some of job servers #23

Closed p-alik closed 6 years ago

p-alik commented 7 years ago

simple client/worker implementation:

use v5.10;
use strict;
use warnings;

use Gearman::Client;
use DateTime;

my @js = (
    {
        host => "localhost",
        port => 4730,
    },
    {
        host => "localhost",
        port => 4731,
    }
);

foreach my $s (@js) {
    my $c = Gearman::Client->new(job_servers => $s);
    my $dt = DateTime->now;
    my $v = join ' ', $dt->dmy, $dt->hms;
    my $h = eval {$c->dispatch_background("morning_bag", $v)};

    say join ' ', $s->{host}, $v, $h || '', $@ ||'';
    sleep(int(rand(1))+1);
}
use v5.10;
use strict;
use warnings;

use Gearman::Worker;

my @js = (
    {
        host => "localhost",
        port => 4730,
    },
    {
        host => "localhost",
        port => 4731,
    }
);

my $w = Gearman::Worker->new(job_servers => [@js]);
$w->register_function(
    "morning_bag",
    sub {
        say join ' ', $_[0]->handle, $_[0]->arg || '';
        return 1;
    }
);

$w->work();

worker runs endless. After a while worker does not work on some of the job servers.

davel commented 7 years ago

We have seen a similar problem in which the worker does not fetch jobs from either of our two configured gearmand servers, despite many outstanding jobs existing. The worker goes into a loop calling select,

getpeername(3, {sa_family=AF_INET, sin_port=htons(4730), sin_addr=inet_addr("1.2.3.4")}, [16]) = 0 getpeername(4, {sa_family=AF_INET, sin_port=htons(4730), sin_addr=inet_addr("5.6.7.8.9")}, [16]) = 0 select(8, [3 4], NULL, NULL, {11, 829717}) = 0 (Timeout) (IP addresses changed.) According to "workers" on the gearmand server, no functions are registered for our worker.

Hope this helps.

Dave

p-alik commented 7 years ago

thanks, @davel

p-alik commented 7 years ago

@davel, I can't reproduce the issue. It doesn't appear anymore. Is it an issue with particular gearmand version?

davel commented 7 years ago

We are running gearmand 1.0.6 under Ubuntu 14.04 in round-robin mode.

p-alik commented 7 years ago

thanks, @davel.

esabol commented 7 years ago

Maybe try upgrading to gearmand 1.1.17, @davel ?

p-alik commented 6 years ago

@davel, it looks to me the bug is fixed. If you want, you could use upstream. New release will be uploaded to CPAN next days.

p-alik commented 6 years ago

v2.004.009 available on CPAN