Can db connections be shared

If I have an application that makes numerous calls to a database for
CRUD stuff over a period, does another user on a different PC when
accessing the same database and same user make use of that existing
connection. Or is another new connection opened, for the second user.

When is the connection closed? When is it re-used? Is it any different
if using multiple Mongrels and Proxy Load Balancer with Apache?

Thanks

Andrew

No, none of them are shared. Each one is a separate connection. It would
be the same with multiple instances of mongrel.

-Bill

Andrew C. wrote:

Andrew


Sincerely,

William P.

On 8 Oct 2007, at 14:47, Andrew C. wrote:

If I have an application that makes numerous calls to a database for
CRUD stuff over a period, does another user on a different PC when
accessing the same database and same user make use of that existing
connection. Or is another new connection opened, for the second user.

When is the connection closed? When is it re-used? Is it any different
if using multiple Mongrels and Proxy Load Balancer with Apache?

Unless you start establishing connections by hand, each instance of
mongrel has one database connection, which it will reuse until it
dies. If you only had one mongrel then there would only ever be 1
connection.

Fred

On 8 Oct 2007, at 16:30, William P. wrote:

You will get multiple connections regardless of whether you create
them by hand, even if it’s using a named pipe. I fired up 2
connections by hand to illustrate the point:

What do you mean by “fire up 2 connections”. I always see one
connection per mongrel (+ instances of query browser etc… obviously)

You will get multiple connections regardless of whether you create them
by hand, even if it’s using a named pipe. I fired up 2 connections by
hand to illustrate the point:

netstat -an | grep mysql.sock
unix 2 [ ACC ] STREAM LISTENING 7235
/var/lib/mysql/mysql.sock
unix 3 [ ] STREAM CONNECTED 2373005
/var/lib/mysql/mysql.sock
unix 3 [ ] STREAM CONNECTED 2372935
/var/lib/mysql/mysql.sock

-Bill

Frederick C. wrote:


Sincerely,

William P.

You said “by hand”, which I assumed to mean running mysql from the
command line. How are you creating a connection by hand with Mongrel?

Frederick C. wrote:

Frederick C. wrote:


Sincerely,

William P.

I read your post again. I misinterpreted it to read that if you create
connections by hand, those connections would be shared. Just a
misinterpretation.

-Bill

William P. wrote:

/var/lib/mysql/mysql.sock

connection. Or is another new connection opened, for the second user.


Sincerely,

William P.

On 8 Oct 2007, at 16:37, William P. wrote:

You said “by hand”, which I assumed to mean running mysql from the
command line. How are you creating a connection by hand with Mongrel?

Well obviously that creates extra connections. By ‘by hand’ I mean
calling ActiveRecord::Base.establish_connection. My point was that
unless you go out of your way, your rails app will use one connection
per instance of mongrel.

Fred