Forum: Ruby on Rails does anyone know whether ActiveRecord has supported connection pool?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6cbd6da748449cd184d96057fe34f398?d=identicon&s=25 Kang Peng (Guest)
on 2008-11-16 05:12
(Received via mailing list)
does anyone know whether ActiveRecord has supported connection pool? i
can't find articles talking about this, if so how to control it in
Rails apps.

thanks a lot.
24d2f8804e6bb4b7ea6bd11e0a586470?d=identicon&s=25 Jeremy Kemper (Guest)
on 2008-11-16 05:29
(Received via mailing list)
On Sat, Nov 15, 2008 at 8:11 PM, Kang Peng <okgoodsun@gmail.com> wrote:
> does anyone know whether ActiveRecord has supported connection pool? i
> can't find articles talking about this, if so how to control it in
> Rails apps.

In Rails 2.1 and earlier, Active Record uses a single persistent
connection per thread.

Beginning in Rails 2.2, Active Record uses a connection pool. Install
the 2.2rc2 release and give it a spin.

Best,
jeremy
6cbd6da748449cd184d96057fe34f398?d=identicon&s=25 kang peng (Guest)
on 2008-11-16 07:19
(Received via mailing list)
thanks. so before Rails2.2, each request will open new connection to
database according to 'Active Record uses a single persistent
connection per thread'? because as i know, each request will start a new
thread, is it correct?
24d2f8804e6bb4b7ea6bd11e0a586470?d=identicon&s=25 Jeremy Kemper (Guest)
on 2008-11-16 12:25
(Received via mailing list)
No, just one connection.
6cbd6da748449cd184d96057fe34f398?d=identicon&s=25 kang peng (Guest)
on 2008-11-16 14:25
(Received via mailing list)
ok, so i think ActiveRecord is thread safe, right? if so, each request
which
call to database will be processed one by one, not concurrent, this
seems
RoR's will be not good when faces big amont of requests in a short time.
is
it ture?
280b78a61a968391b7e07e912be102a8?d=identicon&s=25 Robert Walker (robert4723)
on 2008-11-17 00:37
kang peng wrote:
> ok, so i think ActiveRecord is thread safe, right? if so, each request
> which
> call to database will be processed one by one, not concurrent, this
> seems
> RoR's will be not good when faces big amont of requests in a short time.
> is
> it ture?

Do you have a scaling problem right now? If not then worry about this
when you do....

http://gettingreal.37signals.com/ch04_Scale_Later.php
6cbd6da748449cd184d96057fe34f398?d=identicon&s=25 kang peng (Guest)
on 2008-11-17 04:23
(Received via mailing list)
thanks for great suggestion :)

On Mon, Nov 17, 2008 at 7:37 AM, Robert Walker <
24d2f8804e6bb4b7ea6bd11e0a586470?d=identicon&s=25 Jeremy Kemper (Guest)
on 2008-11-17 07:14
(Received via mailing list)
Right. You need to use a nonblocking database driver to do concurrent
requests.

You can do this with neverblock's database drivers and Active Record
adapter (http://www.espace.com.eg/neverblock/benchmarks) or with
jruby.

Best,
jeremy
6cbd6da748449cd184d96057fe34f398?d=identicon&s=25 kang peng (Guest)
on 2008-11-17 08:11
(Received via mailing list)
thank you very much.
D22781eccd92073acd6a1ed350c3d136?d=identicon&s=25 boblu (Guest)
on 2008-11-17 08:32
(Received via mailing list)
Can anybody tell me about this?
Does this "connection pool" have something to do with multiple
database connection?
Or it is only for concurrent access with one database?
0f50b9a2ad85666d537d39bda49327ee?d=identicon&s=25 Jonathan Rochkind (jrochkind)
on 2008-11-24 22:56
It has to do with multiple connections to one database.

It has, however, always been possible to have some models living in one
database, and others living in others, if that's what you want.
Relationships accross databases don't always work perfectly, if you're
trying to do fancy things. (Like, pre-loading a relationship accross
databases).

For using multiple databases in your app, see:

http://wiki.rubyonrails.org/rails/pages/HowtoUseMu...

Incidentally, even pre Rails 2.2, I have had success using multiple
connections to a single db in different threads, using the mysql gem
adapter. Now I wonder if the mysql gem adapter is actually non-blocking
though, or if my different threads were still blocking on db access.

Jonathan

boblu wrote:
> Can anybody tell me about this?
> Does this "connection pool" have something to do with multiple
> database connection?
> Or it is only for concurrent access with one database?
This topic is locked and can not be replied to.