minor style and doc fixes. warning about logging performance issues.

This commit is contained in:
Kyle Banker 2011-01-31 15:51:39 -05:00
parent 8a7296599b
commit 9c83ca6b3e
3 changed files with 17 additions and 9 deletions

View File

@ -321,7 +321,7 @@ module Mongo
message.put_int(0) message.put_int(0)
message.put_binary(BSON::BSON_CODER.serialize(selector, false, true).to_s) message.put_binary(BSON::BSON_CODER.serialize(selector, false, true).to_s)
@connection.instrument( :remove, :database => @db.name, :collection => @name, :selector => selector ) do @connection.instrument(:remove, :database => @db.name, :collection => @name, :selector => selector) do
if safe if safe
@connection.send_message_with_safe_check(Mongo::Constants::OP_DELETE, message, @db.name, nil, safe) @connection.send_message_with_safe_check(Mongo::Constants::OP_DELETE, message, @db.name, nil, safe)
else else
@ -368,7 +368,7 @@ module Mongo
message.put_binary(BSON::BSON_CODER.serialize(selector, false, true).to_s) message.put_binary(BSON::BSON_CODER.serialize(selector, false, true).to_s)
message.put_binary(BSON::BSON_CODER.serialize(document, false, true).to_s) message.put_binary(BSON::BSON_CODER.serialize(document, false, true).to_s)
@connection.instrument( :update, :database => @db.name, :collection => @name, :selector => selector, :document => document ) do @connection.instrument(:update, :database => @db.name, :collection => @name, :selector => selector, :document => document) do
if safe if safe
@connection.send_message_with_safe_check(Mongo::Constants::OP_UPDATE, message, @db.name, nil, safe) @connection.send_message_with_safe_check(Mongo::Constants::OP_UPDATE, message, @db.name, nil, safe)
else else
@ -840,7 +840,7 @@ module Mongo
end end
raise InvalidOperation, "Exceded maximum insert size of 16,000,000 bytes" if message.size > 16_000_000 raise InvalidOperation, "Exceded maximum insert size of 16,000,000 bytes" if message.size > 16_000_000
@connection.instrument( :insert, :database => @db.name, :collection => collection_name, :documents => documents ) do @connection.instrument(:insert, :database => @db.name, :collection => collection_name, :documents => documents) do
if safe if safe
@connection.send_message_with_safe_check(Mongo::Constants::OP_INSERT, message, @db.name, nil, safe) @connection.send_message_with_safe_check(Mongo::Constants::OP_INSERT, message, @db.name, nil, safe)
else else

View File

@ -61,7 +61,8 @@ module Mongo
# on initialization. # on initialization.
# @option opts [Boolean] :slave_ok (false) Must be set to +true+ when connecting # @option opts [Boolean] :slave_ok (false) Must be set to +true+ when connecting
# to a single, slave node. # to a single, slave node.
# @option opts [Logger, #debug] :logger (nil) Logger instance to receive driver operation log. # @option opts [Logger, #debug] :logger (nil) A Logger instance for debugging driver ops. Note that
# logging negatively impacts performance; therefore, it should not be used for high-performance apps.
# @option opts [Integer] :pool_size (1) The maximum number of socket connections allowed per # @option opts [Integer] :pool_size (1) The maximum number of socket connections allowed per
# connection pool. Note: this setting is relevant only for multi-threaded applications. # connection pool. Note: this setting is relevant only for multi-threaded applications.
# @option opts [Float] :timeout (5.0) When all of the connections a pool are checked out, # @option opts [Float] :timeout (5.0) When all of the connections a pool are checked out,
@ -534,8 +535,10 @@ module Mongo
end end
end end
# execute the block and log the operation as described by name/payload # Execute the block and log the operation described by name
def instrument( name, payload = {}, &blk ) # and payload.
# TODO: Not sure if this should take a block.
def instrument(name, payload = {}, &blk)
res = yield res = yield
log_operation(name, payload) log_operation(name, payload)
res res
@ -572,7 +575,12 @@ module Mongo
@primary = nil @primary = nil
@primary_pool = nil @primary_pool = nil
@logger = opts[:logger] || nil @logger = opts[:logger] || nil
if @logger
@logger.debug("MongoDB logging. Please note that logging negatively impacts performance " +
"and should be disabled for high-performance production apps.")
end
should_connect = opts.fetch(:connect, true) should_connect = opts.fetch(:connect, true)
connect if should_connect connect if should_connect
@ -596,7 +604,7 @@ module Mongo
## Logging methods ## Logging methods
def log_operation( name, payload ) def log_operation(name, payload)
return unless @logger return unless @logger
msg = "#{payload[:database]}['#{payload[:collection]}'].#{name}(" msg = "#{payload[:database]}['#{payload[:collection]}'].#{name}("
msg += payload.values_at(:selector, :document, :documents, :fields ).compact.map(&:inspect).join(', ') + ")" msg += payload.values_at(:selector, :document, :documents, :fields ).compact.map(&:inspect).join(', ') + ")"

View File

@ -378,7 +378,7 @@ module Mongo
false false
else else
message = construct_query_message message = construct_query_message
@connection.instrument( :find, instrument_payload ) do @connection.instrument(:find, instrument_payload) do
results, @n_received, @cursor_id = @connection.receive_message( results, @n_received, @cursor_id = @connection.receive_message(
Mongo::Constants::OP_QUERY, message, nil, @socket, @command) Mongo::Constants::OP_QUERY, message, nil, @socket, @command)
@returned += @n_received @returned += @n_received