Queue::Mmap - Perl extension for shared queue over mmap-ed file
use Queue::Mmap; my $q = new Queue::Mmap( file => "file.dat", queue => 10, # length of queue length => 20, # length one record (if data longer record, data placed in some records) mod => 0666, # make mode for file ); unless($q->push("abcdefghijklmnopqrstuvwxyz")){ die "fail push"; } my $w = $q->push("abcdefghijk"); printf "%.6f\n",$w; my ($t,$l) = $q->push("abcdefghijk"); printf "total = %.6f, wait lock %.6f\n",$t,$l; print "length of queue is ",$q->length,"\n"; my $top = $q->top; while(defined(my $v = $q->pop)){ print $v,"\n"; } print "no data\n";
Queue::Mmap - Shared circle-queue over mmap-ed file.
Usefull for multy process task queue. One process(es) push task message, and other process(es) pop and execute that tasks. Access with locking(fcntl) guaranted right order without conflict. If pushed data has size greater that record len data placed in some records. If pushed data has size greater that capacity (record * queue) push has return undef.
Create new queue object
my $q = new Queue::Mmap( file => "file.dat", queue => 10, # length of queue length => 20, # length one record (if data longer record, data placed in some records) mod => 0666, # make mode for file );
push $string into queue with block return false on failure return ($time_spend,$time_wait_lock) in array context return $time_spend in scalar context
poped top value from queue with block return C<undef> on empty queue
copy top value from queue without block return C<undef> on empty queue
drop top value from queue with block
return number of records in queue
return array top - index top records bottom - index last records que_len - capacity of queue rec_len - lenth one record
Length of record align for 4 bytes. Length of file align for 4k.
Tested only on linux.
None by default.
Ildar Efremov, <iefremov@2reallife.com<gt>
Copyright (C) 2010 by Ildar Efremov
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
2 POD Errors
The following errors were encountered while parsing the POD:
'=item' outside of any '=over'
You forgot a '=back' before '=head1'
To install Queue::Mmap, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Queue::Mmap
CPAN shell
perl -MCPAN -e shell install Queue::Mmap
For more information on module installation, please visit the detailed CPAN module installation guide.