NAME
PGObject::Util::AsyncPool - An Async Connection Pooler for PGObject
VERSION
Version 0.03
SYNOPSIS
This module provides a basic, simple async connection pool PostgreSQL applications.
It can be used with or without the rest of the PGObject framework.
my $pool = PGObject::Util::AsyncPool->new($connstring,
$username,
$password,
{RaiseError => 0},
{pollfreq => 5, maxconns => 5},
);
my $callback = sub { my $sth = shift; say STDERR $sth->rows; };
for my $query (@queries){
$pool->run($query, $callback);
}
$pool->poll;
...
$pool->poll_loop; # blocks until all queries done
CONSTRUCTOR SYNTAX
PGObject::Util::AsyncPool->new($connstr, $user, $pass, $dbiopts, $poolopts)
The first three arguments are passed to the DBI->connect clause directly.
The dbiopts has Autocommit overridden to avoid unpredictable behavior with statement dependencies. Explicit transactions are not supported in this module.
The poolopts argument configures the connection pool. Currently there are two supported arguments:
- maxconns
-
Sets the maximum number of connections used. Connections are created lazily until this limit is reached. The default is 1.
- pollfreq
-
Sets the amount of time to sleep (in seconds) in the poll_loop function between pollings.
The default is 1.
METHODS
run($query, $callback, [$args])
Queues the query for running as soon as possible. Queries are started on a FIFO basis but no guarantees are made as to what other queries have finished.
Queuing queries begins with a polling call so connections may be reused if a lot of fast are run. This is necessary to avoid conditions where we might queue up lots of queries without checking to see what has finished running first.
int $pool->poll
poll_loop
While there are still running queries, runs through a periodic polling.
This blocks until all queued queries have completed.
CALLBACKS
AUTHOR
Chris Travers, <chris.travers at adjust.com>
BUGS
Please report any bugs or feature requests to bug-pgobject-util-asyncpool at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=PGObject-Util-AsyncPool. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc PGObject::Util::AsyncPool
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=PGObject-Util-AsyncPool
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
Copyright 2018 Chris Travers.
This program is distributed under the (Simplified) BSD License: http://www.opensource.org/licenses/BSD-2-Clause
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.