Git Product home page Git Product logo

Comments (4)

coopernurse avatar coopernurse commented on July 24, 2024

Hi,

If acquire() returns false it simply means that the pool is full and new
resources will not be created (but existing ones will be reused). In all
cases your callback is queued. The source to acquire() is really short,
and may do a better job of answering your question:

me.acquire = function (callback, priority) {
if (draining) {
throw new Error("pool is draining and cannot accept work");
}
waitingClients.enqueue(callback, priority);
dispense();
return (count < factory.max);
};

cheers

-- James

On Fri, Jan 20, 2012 at 2:54 PM, Clint Berry <
[email protected]

wrote:

I just had a question about when aquire returns false. If it does this,
that means all connections are currently in use. Does it automatically hold
the request and wait for a connection to open up or does it just skip all
remaining requests?


Reply to this email directly or view it on GitHub:
#28

James Cooper
http://blog.bitmechanic.com/

from node-pool.

clintberry avatar clintberry commented on July 24, 2024

Thank you for the extremely fast response! So in other words, if I have a pool of 10 connections, and I rapidly call aquire 100 times, it will not wait to call the last 90, but will instead reuse the connections already in use. So it is up to me to create my own message queue if I don't want more than one process on each connection.

from node-pool.

coopernurse avatar coopernurse commented on July 24, 2024

If you create a pool with a max size of 10, and you call acquire() 100
times, then the first 10 calls will result in resources being created and
added to the pool. then next 90 calls will queue internally in the pool.
when your callback function calls release(), then that resource is released
back to the pool, and one of the 90 waiting callbacks will be dispensed the
resource. this cycle continues until there are no callbacks waiting.

This example assumes that your callback function performs some async
operation (like a db query). If your callbacks have no async code in them
then using this pool is not meaningful.

So you shouldn't have to do any mutexes or locks around your resources.
That's what the pool is for. It will ensure that each resource in the
pool is handed to a single callback function at a time.

And of course, it's very important that your callbacks always release the
resource given to them. Otherwise you'll leak resources and potentially
starve the pool.

hope that helps

-- James

On Fri, Jan 20, 2012 at 3:15 PM, Clint Berry <
[email protected]

wrote:

Thank you for the extremely fast response! So in other words, if I have a
pool of 10 connections, and I rapidly call aquire 100 times, it will not
wait to call the last 90, but will instead reuse the connections already in
use. So it is up to me to create my own message queue if I don't want more
than one process on each connection.


Reply to this email directly or view it on GitHub:
#28 (comment)

James Cooper
http://blog.bitmechanic.com/

from node-pool.

clintberry avatar clintberry commented on July 24, 2024

That helps immensely. Thank you!

from node-pool.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.