The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Queue::Mmap - Perl extension for shared queue over mmap-ed file

SYNOPSIS

        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";

DESCRIPTION

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.

new %params

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
        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
pop
        poped top value from queue with block
        return C<undef> on empty queue
top
        copy top value from queue without block
        return C<undef> on empty queue
drop
        drop top value from queue with block
length
        return number of records in queue
stat
        return array
        top - index top records
        bottom - index last records
        que_len - capacity of queue
        rec_len - lenth one record
aligments

Length of record align for 4 bytes. Length of file align for 4k.

TODO

Tested only on linux.

EXPORT

None by default.

SEE ALSO

AUTHOR

Ildar Efremov, <iefremov@2reallife.com<gt>

COPYRIGHT AND LICENSE

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:

Around line 77:

'=item' outside of any '=over'

Around line 126:

You forgot a '=back' before '=head1'