本文介绍了是否有任何理由使用与ActiveRecord的数据库连接池?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是使用外部连接池的好处是什么?

我听说大多数其他应用程序将打开每个工作单元的连接。在Rails中,例如,我认为这意味着每个请求可以打开一个新的连接。我假设一个连接池会做到这一点。

我能想到的唯一的好处是,它可以让你有1000前端流程,而无需运行1000 Postgres处理。

是否还有其他的好处?

解决方案

Rails有建于连接池:

这已经可以从版本2.2 。你会看到一个在参数的的database.yml 控制它:

我不认为会有什么意义分层它下面的另一个池系统,它甚至可能混淆AR的池,如果你尝试过了。

What are the benefits to using an external connection pool?

I've heard that most other applications will open up a connection for each unit of work. In Rails, for example, I'd take that to mean that each request could open a new connection. I'm assuming a connection pool would make that possible.

The only benefit I can think of is that it allows you to have 1,000 frontend processes without having 1,000 postgres processes running.

Are there any other benefits?

解决方案

Rails has connection pooling built in:

This has been available since version 2.2. You'll see a pool parameter in your database.yml for controlling it:

I don't think there would be much point in layering another pooling system underneath it and it could even confuse AR's pooling if you tried it.

这篇关于是否有任何理由使用与ActiveRecord的数据库连接池?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 01:15