Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

ruby - MongoDB: What is connection pooling and timeout?

So my Passenger spins up 5 instances of my Rails app

I connect to MongoDB using Connection.new("localhost", 3000, :pool_size => 1, :timeout => 5)

Why would I need a "pool of connections" if I only incur overhead when starting up my Rails app, not per request? Why would a single process need more than 1 connection?

And what is the purpose of the timeout? Why would I want the connection to timeout? Shouldn't it be persist through the Rails process' lifetime?

So confused...

This question is specific to Ruby and Mongo but I guess it applies to other languages/databases.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You don't need to use connection pooling here. As you're using Passenger, just make sure that each instance uses a separate connection by catching the start_worker_process event. This is documented in the driver README.

Connection pooling can be useful for certain multi-threaded apps. pool_size is the max number of concurrent threads the connection will handle, and timeout is the maximum number of seconds a thread can wait for an available socket before an exception is thrown.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...