简体   繁体   English

使用Node.js进行MySQL连接池

[英]Mysql connection pooling with Node.js

I've searched around for a while but I am still not sure of the advantages and disadvantages of a connection pool vs a single permanent connection (using the mysql package ). 我已经搜索了一段时间,但是仍然不确定连接池与单个永久连接(使用mysql包 )的优缺点。

Currently am using the single connection option but due to scalability issues I am thinking of switching to a pool. 当前正在使用单个连接选项,但是由于可伸缩性问题,我正在考虑切换到池。

I am not really sure what common pitfalls I have to look for, but here are some I think. 我不确定要寻找哪些常见的陷阱,但是我认为这是一些陷阱。

a) SELECT/UPDATE (s) that need to be sequential must be used inside a transaction. a)必须在事务内使用需要顺序的SELECT/UPDATE

b) release each connection in the narrowest scope possible. b)在尽可能小的范围内释放每个连接。

c) Be careful of selecting data about to be changed and updated so use FOR UPDATE to lock them. c)注意选择要更改和更新的数据,因此请使用FOR UPDATE锁定它们。

Generally I would like to know about the pitfalls. 通常,我想了解一些陷阱。 Also, suppose I use a transaction into each and every query, would that make it perform the same as having a single connection? 另外,假设我在每个查询中都使用了事务,这会使它的性能与具有单个连接的性能相同吗?

It's super simple. 非常简单。 Are you going to do more than 1 MySQL query in parallel, you need it. 您打算并行执行多个1个MySQL查询吗?

Whether you do that depends on your application. 是否执行此操作取决于您的应用程序。 Is it a webserver serving more than 1 user? 它是一台为多个用户服务的网络服务器吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM