Comments (4)
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.
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.
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.
That helps immensely. Thank you!
from node-pool.
Related Issues (20)
- Im not getting any performance using a pool connection vs reusing one connection
- waitingClientsCount function has disappeared HOT 1
- resource release not getting called HOT 2
- NPM installation faliure HOT 2
- Add param to factory
- Feature: add pool.use method. HOT 1
- Borrowed resources never go higher than 1 HOT 2
- Share pool between servers in a cluster HOT 3
- How to work maxWaitingClients? HOT 1
- Add destroy timeout to prevent pool.clear from hanging when destroy promise never resolves HOT 4
- testOnReturn = no-op?
- What does happen if I don't release the resource and close the node? HOT 2
- Resource not currently part of this pool HOT 1
- `ready` method from Pool is missing from the TS definitions (v3.8.2)
- .use does not handle synchronous work functions
- Consistently occuring `ResourceRequest timed out` Error HOT 1
- TimeoutError: ResourceRequest timed out HOT 2
- Suggested Feature: borrowTimeoutMillis HOT 2
- Pool does not maintain the minimum HOT 1
- Suggestion on softEvictConnections
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-pool.