Giter Club home page Giter Club logo

Comments (15)

kadler avatar kadler commented on August 16, 2024 3

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.

abmusse avatar abmusse commented on August 16, 2024

Original comment by Kerim Güney (Bitbucket: TaskForce_Kerim, GitHub: KerimG).


@abmusse

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.

abmusse avatar abmusse commented on August 16, 2024

@KerimG So after the pool size as reached its max, what do propose should occur?

from nodejs-idb-pconnector.

abmusse avatar abmusse commented on August 16, 2024

Original comment by Kerim Güney (Bitbucket: TaskForce_Kerim, GitHub: KerimG).


@abmusse

+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.

abmusse avatar abmusse commented on August 16, 2024

@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 the DBPool, defaults to 8 connections.
    • maxSize: Number is an integer that sets max number of connections the DBPool can contain, defaults to null.
    • debug: boolean setting it to true will display verbose output to the console, defaults to false.

from nodejs-idb-pconnector.

abmusse avatar abmusse commented on August 16, 2024

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.

abmusse avatar abmusse commented on August 16, 2024

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.

abmusse avatar abmusse commented on August 16, 2024

@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.

abmusse avatar abmusse commented on August 16, 2024

@KerimG

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.

github-actions avatar github-actions commented on August 16, 2024

👋 Hi! This issue has been marked stale due to inactivity. If no further activity occurs, it will automatically be closed.

from nodejs-idb-pconnector.

abmusse avatar abmusse commented on August 16, 2024

Keeping This issue Alive

from nodejs-idb-pconnector.

kadler avatar kadler commented on August 16, 2024

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.

github-actions avatar github-actions commented on August 16, 2024

👋 Hi! This issue has been marked stale due to inactivity. If no further activity occurs, it will automatically be closed.

from nodejs-idb-pconnector.

wuhaibo avatar wuhaibo commented on August 16, 2024

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.

abmusse avatar abmusse commented on August 16, 2024

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)

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.