So my Passenger spins up 5 instances of my Rails app
所以我的乘客生成了5个Rails应用实例
I connect to MongoDB using Connection.new("localhost", 3000, :pool_size => 1, :timeout => 5)
我使用连接连接到MongoDB。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?
如果我只在启动Rails应用程序时产生开销,而不是每个请求时,为什么需要一个“连接池”?为什么一个进程需要多个连接?
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?
暂停的目的是什么?为什么我希望连接超时?难道它不应该在Rails进程的生命周期中一直存在吗?
So confused...
所以困惑…
This question is specific to Ruby and Mongo but I guess it applies to other languages/databases.
这个问题是Ruby和Mongo特有的,但是我猜它也适用于其他语言/数据库。
1 个解决方案
#1
3
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.
这里不需要使用连接池。在使用Passenger时,只要通过捕获start_worker_process事件确保每个实例都使用一个单独的连接。这在驱动程序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.
连接池对于某些多线程应用程序非常有用。pool_size是连接将要处理的并发线程的最大数量,timeout是线程在抛出异常之前等待一个可用套接字的最大秒数。
#1
3
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.
这里不需要使用连接池。在使用Passenger时,只要通过捕获start_worker_process事件确保每个实例都使用一个单独的连接。这在驱动程序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.
连接池对于某些多线程应用程序非常有用。pool_size是连接将要处理的并发线程的最大数量,timeout是线程在抛出异常之前等待一个可用套接字的最大秒数。