minor: fixes for pooling; updated history

This commit is contained in:
Kyle Banker 2009-12-21 09:06:28 -05:00
parent 5c1b3aed0f
commit 3858e70518
3 changed files with 22 additions and 13 deletions

12
HISTORY
View File

@ -1,3 +1,15 @@
0.18.2 2009-12-21
* Enabled support for keyf on group
* Signification GridStore performance improvement (thx., Sunny Hirai)
* Support :query option for Collection#distinct
* Support :finalize option for Collection#group
* (0.18.1) ObjectID#generation_time returns a created_at timestamp.
* Deprecated Command#group running as a JS eval; should now be run as a command.
* Deprecated Cursor#next_object for Cursor#next_document
* Character encoding fixes for C extension
* Enforce 4MB limit on document creation
* Simplified connection pooling code
0.18.1 2009-12-05 0.18.1 2009-12-05
* Fixed issue with negative dates in Ruby 1.9 * Fixed issue with negative dates in Ruby 1.9
* Minor refactorings for C extension and BSON classes * Minor refactorings for C extension and BSON classes

View File

@ -70,7 +70,6 @@ module Mongo
# this is the number of seconds to wait for a new connection # this is the number of seconds to wait for a new connection
# to be released before throwing an exception. # to be released before throwing an exception.
# #
#
# === Examples: # === Examples:
# #
# # localhost, 27017 # # localhost, 27017
@ -106,7 +105,10 @@ module Mongo
# Pool size and timeout. # Pool size and timeout.
@size = options[:pool_size] || 1 @size = options[:pool_size] || 1
@timeout = options[:timeout] || 1.0 @timeout = options[:timeout] || 5.0
# Number of seconds to wait for threads to signal availability.
@thread_timeout = @timeout >= 5.0 ? (@timeout / 4.0) : 1.0
# Mutex for synchronizing pool access # Mutex for synchronizing pool access
@connection_mutex = Monitor.new @connection_mutex = Monitor.new
@ -294,11 +296,6 @@ module Mongo
private private
# Get a socket from the pool, mapped to the current thread.
def checkout
obtain_socket
end
# Return a socket to the pool. # Return a socket to the pool.
def checkin(socket) def checkin(socket)
@connection_mutex.synchronize do @connection_mutex.synchronize do
@ -337,14 +334,14 @@ module Mongo
# Check out an existing socket or create a new socket if the maximum # Check out an existing socket or create a new socket if the maximum
# pool size has not been exceeded. Otherwise, wait for the next # pool size has not been exceeded. Otherwise, wait for the next
# available socket. # available socket.
def obtain_socket def checkout
connect_to_master if !connected? connect_to_master if !connected?
start_time = Time.now start_time = Time.now
loop do loop do
if (Time.now - start_time) > 30 if (Time.now - start_time) > @timeout
raise ConnectionTimeoutError, "could not obtain connection within " + raise ConnectionTimeoutError, "could not obtain connection within " +
"#{@timeout} seconds. The max pool size is currently #{@size}; " + "#{@timeout} seconds. The max pool size is currently #{@size}; " +
"consider increasing it." "consider increasing the pool size or timeout."
end end
@connection_mutex.synchronize do @connection_mutex.synchronize do
@ -364,13 +361,13 @@ module Mongo
# Ruby 1.9's Condition Variables don't support timeouts yet; # Ruby 1.9's Condition Variables don't support timeouts yet;
# until they do, we'll make do with this hack. # until they do, we'll make do with this hack.
def wait def wait
Timeout.timeout(@timeout) do Timeout.timeout(@thread_timeout) do
@queue.wait @queue.wait
end end
end end
else else
def wait def wait
@queue.wait(@timeout) @queue.wait(@thread_timeout)
end end
end end

View File

@ -6,7 +6,7 @@ class TestThreadingLargePool < Test::Unit::TestCase
include Mongo include Mongo
@@db = Connection.new('localhost', 27017, :pool_size => 50, :timeout => 1).db('ruby-mongo-test') @@db = Connection.new('localhost', 27017, :pool_size => 50, :timeout => 10).db('ruby-mongo-test')
@@coll = @@db.collection('thread-test-collection') @@coll = @@db.collection('thread-test-collection')
def set_up_safe_data def set_up_safe_data