Comments (15)
Could be done, but we'd need to make attach
return a Promise.
Basic design:
- pool has two new internal attributes: a list of waiters and an an EventEmitter instance
- when the pool is constructed, add an event listener to the
EventEmitter
instance which listens for the 'connection-added' event - when
attach
is called, if the pool is full, create a Promise, append it to the wait list on the pool and return it - whenever a connection is returned to the pool, a 'connection-added' event is emitted
- when the 'connection-added' listener fires, the called function pulls the first waiter from the wait list and fulfills the promise with the recently added connection
from nodejs-idb-pconnector.
Original comment by Kerim Güney (Bitbucket: TaskForce_Kerim, GitHub: KerimG).
I was thinking of the same solution as @aaronbartell . Once all connections are in use, the next ones are queued and time out until a connections is available again.
from nodejs-idb-pconnector.
@KerimG So after the pool size as reached its max, what do propose should occur?
from nodejs-idb-pconnector.
Original comment by Kerim Güney (Bitbucket: TaskForce_Kerim, GitHub: KerimG).
+1
I like that. I wouldn't mind a default value, either. MySQL 5.5's default value is 151 it seems, PostgreSQL 100.
from nodejs-idb-pconnector.
@ThePrez @aaronbartell @brianmjerome the maxSize can be option passed part of the config
object.
Class: DBPool
Manages a list of DBPoolConnection instances.
Constructor: DBPool(database , config)
Constructor to instantiate a new instance of a DBPool class given the database
and config
.
Parameters:
-
database:
Object
with the properties:url
:String
location of the database, use*LOCAL
for a local database.username
:String
for the database user.password
:String
for the database user.
-
config:
Object
with the properties:incrementSize
:Number
is an integer that sets the desired size of theDBPool
, defaults to 8 connections.maxSize
:Number
is an integer that sets max number of connections theDBPool
can contain, defaults tonull
.debug
:boolean
setting it to true will display verbose output to the console, defaults to false.
from nodejs-idb-pconnector.
Original comment by Brian Jerome (Bitbucket: bjerome, GitHub: brianmjerome).
I think the max size should only be defined by the user.
from nodejs-idb-pconnector.
Original comment by Aaron Bartell (Bitbucket: aaronbartell, GitHub: aaronbartell).
Thoughts should we set a max pool size option that when reached, will queue further attach() attempts?
Had a customer parse an Excel spreadsheet this week and this was an issue. I believe they said they had many database jobs because of it, which makes sense. So yeah, a way to declare the max and then wait for a connection to become available with a timeout would be good.
from nodejs-idb-pconnector.
@KerimG Thanks for the suggestion!
pool.attach() will scan the list of connections for an available one, If all the connections are currently unavailable the pool will add new connections.
The number of connections added will depend on the incrementSize
option set on the pool, by default incrementSize = 8
;
when pool.detach() is called if the connection had a statement previously it is closed before its set to available again.
That way each statement corresponds to one connection, avoiding the reuse of 1 connection for multiple statements (issue referenced above).
You bring up a valid point about not having a limit on the connection pool size.
If for some reason pool.detach() is never called the connection can constantly be unavailable.
Thus causing the pool to keep creating connections, wasting resources.
For now make sure to call pool.detach() is called to free up the connection after your done.
@ThePrez @aaronbartell @brianmjerome Thoughts should we set a max pool size option that when reached, will queue further attach() attempts?
from nodejs-idb-pconnector.
I'm sure we simply cap the number connections in the pool with maxSize
property mentioned before.
When the max is reached a call to attach() will throw an error.
Also would like to add an additional property initalSize
to differentiate it from incrementSize
Not sure how we would implement the queuing feature you mentioned though.
any thoughts on possibly adding queuing as suggested?
@ThePrez @kadler @markdirish @bjeromeHCS
from nodejs-idb-pconnector.
👋 Hi! This issue has been marked stale due to inactivity. If no further activity occurs, it will automatically be closed.
from nodejs-idb-pconnector.
Keeping This issue Alive
from nodejs-idb-pconnector.
We'll need to set up labels to keep things open, see https://github.com/actions/stale/blob/master/action.yml#L21
from nodejs-idb-pconnector.
👋 Hi! This issue has been marked stale due to inactivity. If no further activity occurs, it will automatically be closed.
from nodejs-idb-pconnector.
hello guys,
first of all thank you for the great work here.
recently, we are considering developing a nodejs application which needs to connect to db2 on ibm machine,
so I have a question,
is there any plan to release this feature this year?
from nodejs-idb-pconnector.
Currently there are no plans to release this feature by end of year. I would recommend considering node-odbc which does implment limiting the max number of connections pool will contain. See https://github.com/markdirish/node-odbc#parameters-11
from nodejs-idb-pconnector.
Related Issues (20)
- setLibraryList and sql user defined functions HOT 5
- dbpool failed to detach HOT 19
- Run linter during PR HOT 1
- Fix eslint errors
- Max number of simultaneous connections HOT 8
- Drop standard-version as its now deprecated HOT 2
- Calling Store Proc passing well IN parms , not getting OUT parm HOT 2
- DBPool example is incomplete.. HOT 1
- Please make more clear how to call a Stored Procedure HOT 7
- No clear explanation on how to call stored procedure. Not receiving output.
- More examples HOT 5
- bindParam() is deprecated and you should use bindParameters() instead HOT 8
- Fix copyright headers on source files
- Add package-lock.json HOT 1
- DBPool 'new connection' event emitter issues HOT 1
- build: Add standard-version HOT 1
- Migrate docs to readthedocs HOT 1
- Add exempt-pr-label
- DBPool.prepareExecute should provide a way to enable numeric type conversion HOT 7
- fetchAll keys lower case HOT 3
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 nodejs-idb-pconnector.