简体   繁体   English

具有单个应用程序服务器实例的数据库连接池

[英]Database Connection Pool with a Single Application Server Instance

I am connecting to a remote MySQL database in my node.js server code for a web app. 我正在使用Web应用程序的node.js服务器代码连接到远程MySQL数据库。 Is there any advantage to using a connection pool when I only have a single instance of a node.js application server running? 当我只有一个node.js应用服务器实例运行时,使用连接池有什么好处吗?

Connection pools are per instance of application. 连接池是每个应用程序实例。 When you connect to the db, you are doing it from that particular instance and hence the pool is in the scope of that instance. 当您连接到数据库时,您是从该特定实例执行此操作的,因此该池在该实例的范围内。 The advantage of creating a pool is that you don't create / close connections very often, as this is, in general, a very expensive process. 创建池的优点是您不必经常创建/关闭连接,因为通常这是一个非常昂贵的过程。 Rather, you maintain a set of connections open, in idle state, ready to be used if there is a need. 相反,您可以保持一组空闲状态下打开的连接,可以在需要时使用。

Update 更新资料

In node there is async.parallel() construct which allows you to launch a set of tasks in async manner. 在节点中,存在async.parallel()构造,该构造允许您以异步方式启动一组tasks Immagine that those tasks represent each one a single query. 想象一下,这些tasks代表一个查询。 If you have a single connection to use, each process should use that same one, and it will quickly become a bottelneck. 如果要使用单个连接,则每个进程应使用相同的连接,它将很快成为僵局。 Instead, if you have a pool of available connections, each task can use a separate connection until the pool is completely used. 相反,如果您有可用连接池,则每个任务可以使用单独的连接,直到完全使用该池为止。 Check this for more detailed reference. 检查以获得更多详细参考。

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

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