Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A queueing system for Perl

I'm working on a Perl project which needs a FIFO message queue for distributing tasks between several processes on a single machine (UNIX). The queue size may grow up to 1M jobs.

I've tried IPC::DirQueue, but it becomes awfully slow with 50k or so jobs enqueued. What are good alternatives to this module which can be used in Perl?

like image 530
Eugene Yarmash Avatar asked Apr 13 '12 13:04

Eugene Yarmash


2 Answers

I've had pretty good success with using ZeroMQ for this sort of problem, both with Perl and other languages.

In my experience, the ZeroMQ module appears to be the most reliable binding for Perl currently.

like image 144
rafl Avatar answered Nov 06 '22 00:11

rafl


I haven't tried it under the conditions you list, but Thread::Queue has proven useful to me. Combined with forks, it can be used to communicate with processes, as long as those processes were spawned by the queue creator.

use forks;  # If you want to use processes instead of threads.
use Thread::Queue qw( );

A worker model is usually ideal.

my $q = Thread::Queue->new();

my @workers;
for (1..$NUM_WORKERS) {
   push @workers, async {
      while (my $item = $q->dequeue()) {
         ...
      }
   };
}

# ... Enqueue requests [ $q->enqueue($request); ] ...

# Signal termination
$q->enqueue(undef) for 1..@workers;

# Collect workers.
$_->join() for @workers;
like image 20
ikegami Avatar answered Nov 06 '22 00:11

ikegami