When should I use connection pooling with MySQL in NodeJS

自古美人都是妖i 提交于 2019-12-06 00:17:03

问题


Working with the Node-MySql module:

From my understanding multithreaded programs benefit more from pooling connections than singlethreaded ones. Is this true?

And if this logic proves true, what scenario is connection pooling beneficial in a Node.JS application?


回答1:


Whether single or multithreaded, pooling can still be beneficial in allowing open connections to be reused rather than being closed only to open another immediately after:

When you are done with a connection, just call connection.release() and the connection will return to the pool, ready to be used again by someone else.

The added benefit with multithreading is that the pool can also manage multiple, concurrent connections:

Connections are lazily created by the pool. If you configure the pool to allow up to 100 connections, but only ever use 5 simultaneously, only 5 connections will be made.

Though, to be clear, Node is multithreaded. It just uses a different model than seems to be typical -- 1 "application" thread which executes JavaScript and multiple "worker" threads handling the brunt of asynchronous I/O.



来源:https://stackoverflow.com/questions/17610793/when-should-i-use-connection-pooling-with-mysql-in-nodejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!