Sail.js启动多个连接 [英] Sail.js multiple connections on start

查看:344
本文介绍了Sail.js启动多个连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个奇怪的问题 - 在启动我的sails应用程序(连接postgres并部署在heroku上)时,有多个连接(大约10)到数据库,并且因为它是免费帐户,所以如果我尝试启动本地主机上的应用程序来测试一些新的代码我得到一个错误一个角色的连接太多。所以有人知道为什么有这么多的数据库连接,我可以改变它,每个应用程序只有一个连接?



编辑:
创建连接到Postgresql:错误:太多角色连接
xwoellnkvjcupt
创建到Postgresql的连接时出错:错误:连接过多的角色
xwoellnkvjcupt
错误:挂钩未能加载:orm(错误:太多的角色连接xwoellnkv
jcupt)
错误:加载Sails核心时遇到错误!
错误:错误:在Connection.parseE上的角色xwoellnkvjcupt
的连接太多(C:\Studia\szachman2\\\
ode_modules\sails-postgresql\\\
ode
_modules\\ \\pg\lib\connection.js:561:11)在Connection.parseMessage处的
(C:\Studia\szachman2\\\
ode_modules\sails-postgresq
l\\\
ode_modules\pg \lib\connection.js:390:17)
at null。 (C:\Studia\szachman2\\\
ode_modules\sails-postgresql\\\
ode_
modules\pg\lib\connection.js:98:18)在CleartextStream.EventEmitter上
。在CleartextStream发出(events.js:95:17)
。 (_stream_readable.js:746:14)
at CleavedExtStream.EventEmitter.emit(events.js:92:17)
at emitReadable_(_stream_readable.js:408:10)
at _stream_readable。 js:401:7
at process._tickDomainCallback(node.js:459:13)

这是我经常在尝试测试时遇到的错误新的代码在本地主机上。

解决方案

@jantar @ sgress454我刚刚在 sails-postgresql 中添加了一条故障排除信息,尝试使其更好。以下是它的内容:


- > 也许您的 poolSize 配置为设置得太高?例如如果你的Postgresql数据库只支持20个并发连接,你应该确保你的 poolSize 设置为< 20.默认 poolSize 为10。



覆盖默认的 poolSize ,在相关的Postgresql连接配置对象上指定一个 poolSize 属性。如果您使用的是Sails,它通常位于 config / connections.js 中,或者设置了特定于环境的数据库配置。



- > 您是否有多个共享相同Postgresql数据库的Sails实例?每个Sails实例最多可以使用配置的 poolSize 连接数量。假设所有的Sails实例只是彼此的副本(一个合理的最佳实践),我们可以通过乘以配置的 poolSize 来计算实际使用的Postgresql连接数(C)( P)乘以Sails实例的数量(N)。如果连接的实际数量(C)超过了Postgresql数据库(V)的 AVAILABLE 连接总数,那么您遇到了问题。如果这适用于您,请尝试减少您的 poolSize 配置。合理的 poolSize 设置为V / N。



I've got an odd problem - on start of my sails app (which is connecting with postgres and deployed on heroku ) there are multiple connections (around 10) to database, and since it's free account, if I then try to launch app on localhost to test some new code I get an error "too many connections for a role". So does anyone know why there are so many connections to database and can I change it, to have only one connection per app?

EDIT: Error creating a connection to Postgresql: error: too many connections for role "xwoellnkvjcupt" Error creating a connection to Postgresql: error: too many connections for role "xwoellnkvjcupt" error: Hook failed to load: orm (error: too many connections for role "xwoellnkv jcupt") error: Error encountered while loading Sails core! error: error: too many connections for role "xwoellnkvjcupt" at Connection.parseE (C:\Studia\szachman2\node_modules\sails-postgresql\node _modules\pg\lib\connection.js:561:11) at Connection.parseMessage (C:\Studia\szachman2\node_modules\sails-postgresq l\node_modules\pg\lib\connection.js:390:17) at null. (C:\Studia\szachman2\node_modules\sails-postgresql\node_ modules\pg\lib\connection.js:98:18) at CleartextStream.EventEmitter.emit (events.js:95:17) at CleartextStream. (_stream_readable.js:746:14) at CleartextStream.EventEmitter.emit (events.js:92:17) at emitReadable_ (_stream_readable.js:408:10) at _stream_readable.js:401:7 at process._tickDomainCallback (node.js:459:13)

this is an error I am getting often when trying to test some new code on localhost.

解决方案

@jantar @sgress454 I just added a troubleshooting message in sails-postgresql to try and make this better. Here's what it says:

-> Maybe your poolSize configuration is set too high? e.g. If your Postgresql database only supports 20 concurrent connections, you should make sure you have your poolSize set as something < 20. The default poolSize is 10.

To override the default poolSize, specify a poolSize property on the relevant Postgresql "connection" config object. If you're using Sails, this is generally located in config/connections.js, or wherever your environment-specific database configuration is set.

-> Do you have multiple Sails instances sharing the same Postgresql database? Each Sails instance may use up to the configured poolSize # of connections. Assuming all of the Sails instances are just copies of one another (a reasonable best practice) we can calculate the actual # of Postgresql connections used (C) by multiplying the configured poolSize (P) by the number of Sails instances (N). If the actual number of connections (C) exceeds the total # of AVAILABLE connections to your Postgresql database (V), then you have problems. If this applies to you, try reducing your poolSize configuration. A reasonable poolSize setting would be V/N.

这篇关于Sail.js启动多个连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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