简体   繁体   English

nodejs集群模式下如何处理连接池

[英]How to handle connection pooling in cluster mode of nodejs

I am using MySQL and creating MySQL connection pool once and reusing in all other modules where needed.我正在使用 MySQL 并创建 MySQL 连接池一次,并在需要的所有其他模块中重用。

When my code is running on single core this is working fine but when I use clustering and running app on multiple cores system, my connection pool is getting initialized multiple times [Based on number of cores].当我的代码在单核上运行时,这工作正常,但是当我在多核系统上使用集群和运行应用程序时,我的连接池被多次初始化[基于核数]。

How to fix this.如何解决这个问题。

mysql.init(function (error) {
    if (error) {
        throw error;
    }

    var server = http.createServer(app);
    server.listen(app.get('port'), function () {
        logger.info('Express server listening on port ' + app.get('port'));
    });
});

That's normal .那很正常。 Cluster mode means that you have a copy of your application running in each core .集群模式意味着您有一个在每个核心中运行的应用程序副本。 This process don't share memory .此进程不共享内存。 Are individual process.是个人过程。 This aren't threads .这不是线程。

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

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