什么时候应该在NodeJS中将连接池与MySQL一起使用 [英] When should I use connection pooling with MySQL in NodeJS

查看:130
本文介绍了什么时候应该在NodeJS中将连接池与MySQL一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Node-MySql 模块:

据我了解,多线程程序比单线程程序受益于池化连接。

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

这是真的吗?如果在Node.JS应用程序中连接池有益是什么情况?

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

推荐答案

无论是单线程还是多线程,在允许重新使用打开的连接,而不是仅在以下情况后才关闭以立即打开另一个连接:

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:


完成连接后,只需调用 connection.release(),然后该连接将返回到池中,可供以下人员再次使用

多线程的另一个好处是该池还可以管理多个并发连接:

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


连接是由池延迟创建的。如果将池配置为最多允许100个连接,但仅同时使用5个,则只会建立5个连接。

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.

明确地说,Node是多线程的。它使用的模型不同于通常的模型-1个执行JavaScript的 application 线程和多个处理异步I / O冲击的 worker 线程。

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.

这篇关于什么时候应该在NodeJS中将连接池与MySQL一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆