Net::ZooKeeper::Semaphore
Distributed semaphores via Apache ZooKeeper
my $fqdn = Sys::Hostname::FQDN::fqdn(); my $zkh = Net::ZooKeeper->new(...); my $cpu_semaphore = Net::ZooKeeper::Semaphore->new( count => 1, path => "/semaphores/${fqdn}_cpu", total => Sys::CPU::cpu_count(), zkh => $zkh, ); my %mem_info = Linux::MemInfo::get_mem_info(); my $mem_semaphore = Net::ZooKeeper::Semaphore->new( count => 4E6, # 4GB data => $$, path => "/semaphores/${fqdn}_mem", total => $mem_info{MemTotal}, zkh => $zkh, ); undef $cpu_semaphore; # to delete lease
Object creation doesn't block. Undef is returned if it isn't possible to acquire a lease. An exception is raised on any ZooKeeper errors. A lease is held as long as the object lives.
Parameters:
Resource amount to be leased. Must be an integer (negative values are to be added to total).
Optional. Data for lease znode. Must be a string, default is '0'.
Path in ZooKeeper that identifies the semaphore. If it doesn't exist, it will be created. Also path/lock and path/leases will be created.
Total amount of available resource. If there are any active leases for the given path that were created with a different total, an exception will be raised.
Net::ZooKeeper handle object
Oleg Komarov <komarov@cpan.org>
This software is copyright (c) 2013 by Yandex LLC.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
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 Net::ZooKeeper::Semaphore, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::ZooKeeper::Semaphore
CPAN shell
perl -MCPAN -e shell install Net::ZooKeeper::Semaphore
For more information on module installation, please visit the detailed CPAN module installation guide.