问题描述
对于我的应用程序,我使用 https://github.com/felixge/node-mysql 何时何地使用
I use https://github.com/felixge/node-mysql for my application When and Why use
db_pool = mysql.createConnection(db);
或
db_pool = mysql.createPool(db);
有什么区别?以及何时使用它们?
what are the differences? and when to use them?
推荐答案
单个连接正在阻塞.在执行一个查询时,它无法执行其他查询.因此,您的数据库吞吐量可能会降低.
A single connection is blocking. While executing one query, it cannot execute others. Hence, your DB throughput may be reduced.
池管理着许多延迟创建的(在felixge的模块中)连接.当一个连接正忙于运行查询时,其他连接可用于执行后续查询.这样可以并行运行多个查询,从而提高应用程序性能.
A pool manages many lazily-created (in felixge's module) connections. While one connection is busy running a query, others can be used to execute subsequent queries. This can result in an increase in application performance as it allows multiple queries to be run in parallel.
这篇关于当使用poolConnection或CreateConnection felixge/node-mysql时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!