简体   繁体   English

rails中的线程是否会自动打开数据库连接?

[英]Do threads in rails automatically open database connections?

I have a rails app running on Heroku that makes use of threads, and it occasionally runs into database connection errors. 我有一个在Heroku上运行的rails应用程序,它使用线程,偶尔会遇到数据库连接错误。 Is this just because I am accessing the database within the threads or does each thread automatically open a database connection? 这只是因为我在线程中访问数据库还是每个线程自动打开数据库连接? I would like to learn more about threading in rails, and any resources are appreciated. 我想了解更多关于rails中的线程,并且赞赏任何资源。

This question varies largely depending on how many instances you have running, how many requests your receiving, and more importantly your database. 此问题在很大程度上取决于您运行的实例数,接收的请求数,以及更重要的数据库数。 Databases can and will have a maximum number of concurrent connections. 数据库可以并且将具有最大数量的并发连接。 You can read more about Heroku/concurrent connections here in the Heroku official documentary , it's probably more informative than what I can tell you in a single comment. 您可以在Heroku官方纪录片中阅读更多关于Heroku /并发连接的内容 ,它可能比我在一条评论中告诉您的信息更丰富。

That being said, your question was a little vague and it's hard to figure out what's going on. 话虽这么说,你的问题有点模糊,很难弄清楚发生了什么。 Can you tell us a little more about what error you're getting (like the specific error) and maybe a small backtrace? 你能告诉我们一些关于你得到的错误(比如具体的错误)以及可能是一个小的回溯吗? Are you getting these errors on the same pages or different pages? 您是在同一页面还是不同页面上收到这些错误? Would you say your site is particularly high traffic? 你会说你的网站流量特别高吗?

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

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