When should I use the MySQL connection pool in NodeJS

Work with Node -MySql module:

From my understanding, multithreaded programs benefit more from combining connections than with single-threaded ones. It's true?

And if this logic proves which pooling scenario is useful in a Node.JS application?

+4
source share
1 answer

Regardless of whether one or multithreading is used, a union can be useful in allowing you to use open connections for reuse , rather than closing only to open another immediately after:

When you finish the connection, just call connection.release() and the connection will return to the pool, ready for others to reuse.

An additional benefit of multithreading is that the pool can also manage multiple concurrent connections:

Links are lazily created by the pool. If you configure the pool for up to 100 connections, but only ever use 5 at a time, only 5 connections will be made.

Although, to be clear, Node is multithreaded. It just uses a different model than it seems typical - a stream of "applications" that runs JavaScript and several "work" threads that handle basic asynchronous I / O.

+3
source

Source: https://habr.com/ru/post/1491075/


All Articles