Skip to content

Open new connections to keep pool "warm" #1229

Closed
@acorbi

Description

@acorbi

Here is my scenario:

On a multi-instance nodejs server application I am expecting high traffic peaks in which it would be beneficial to have a Connection Pool with many open and free connections waiting for the request bursts to come. By doing that, the requests would be served instantaneously without having the CPU overhead of opening them all of a sudden. In my scenario, the connectionLimit is rather high ( ~400 per node instance ) and opening that big number of connections at once can cause high CPU peaks on the database instance.

On the Pool module https://github.com/felixge/node-mysql/blob/master/lib/Pool.js#L22-L70 I can see the getConnection method which first checks if free/released connections are available and acquires them before creating new ones, but what I am actually interested in is to create a max of connectionLimit number of free connections to be acquired by threads running actual queries on the mentioned high traffic situations.

My approach:

On acorbi@f7e10e1 you can see my approach. In a nutshell, it consists on adding a new function to the Pool module which allows to create those connections (as long as the limit allows it) without checking first if there are free connections available.

After calling getNewConnection method I am releasing the connection by calling connection.release():

this.getNewConnection(function(err, connection) {
     connection.release();
});

My questions:

Does my approach actually make sense? Would you suggest other alternatives to achieve this warm-up without tweaking the actual node-mysql implementation? In case you "like" this feature, would you suggest any other "more elegant" way of implementing this. Would you be interested in a PR?

Greetings

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions