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

NAME

Build Status codecov

IPC::LeaderBoard - fast per-symbol online get/update information

VERSION

0.02

STATUS

SYNOPSIS

use IPC::LeaderBoard;

# in master-process
my $master = IPC::LeaderBoard::create(
    n_slots           => 2,                          # number of symbols
    slot_shared_size  => 4,                          # number integers per slot, concurrent access
    slot_private_size => 2,                          # number integers per slot, non-concurrent access
    mmaped_file       => "/var/run/data/my.scores",  # mmaped file
);
# ... initialize data here

# in slave processes
my $slave  = IPC::LeaderBoard::attach(
  # exactly the same parameters as for master
);

my $leader_board = $slave; # or $master, does not matter

# get shared and private arrays of integers for the 0-th slot
my ($shared, $private) = $leader_board->read_slot(0);

# update shared integers with values 1,2,3,4 and 0-th private integer
# with value 6
my $success = $leader_board->update(0, [1, 2, 3, 4], 0 => 6, 1 => 8)

# $shared = [1, 2, 3, 4], $private = [6, 8]
($shared, $private) = $leader_board->read_slot(0);

# update just private integer with index 1 with value 2
$leader_board->update(0, 1 => 2);

# update just shared values of 0-th slot
my $success = $leader_board->update(0, [1, 2, 3, 4]);

DESCRIPTION

LeaderBoard uses shared memory IPC to fast set/get integers on arbitrary row, (slot) defined by it's index.

There are the following assumptions:

The update process should be rather simple: killall $slave_1, $slave_2, ... $master and then start all together. create / attach should be wrappend into eval (or Try::Tiny & friends), to repeat seveal attempts with some delay.

The update method might fail, (i.e. it does not returns true), when it detects, that somebody else already has changed an row. It is assumed that no any harm in it. If needed the row can be refreshed (re-read), and the next update might be successfull.

It is assumed, that if read returs outdated data and the update decision has been taken, than update will silently fail (return false), without any loud exceptions; so, the next read-update cycle might be successful, but probably, the updated values are already correct, so, no immediate update would occur.

AUTHOR

binary.com, <perl at binary.com>

BUGS

Please report any bugs or feature requests to https://github.com/binary-com/perl-IPC-LeaderBoard/issues.

LICENSE AND COPYRIGHT

Copyright (C) 2016 binary.com

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0

Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.