minor style and doc fixes. warning about logging performance issues.
This commit is contained in:
parent
8a7296599b
commit
9c83ca6b3e
@ -321,7 +321,7 @@ module Mongo
|
||||
message.put_int(0)
|
||||
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
|
||||
@connection.send_message_with_safe_check(Mongo::Constants::OP_DELETE, message, @db.name, nil, safe)
|
||||
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(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
|
||||
@connection.send_message_with_safe_check(Mongo::Constants::OP_UPDATE, message, @db.name, nil, safe)
|
||||
else
|
||||
@ -840,7 +840,7 @@ module Mongo
|
||||
end
|
||||
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
|
||||
@connection.send_message_with_safe_check(Mongo::Constants::OP_INSERT, message, @db.name, nil, safe)
|
||||
else
|
||||
|
@ -61,7 +61,8 @@ module Mongo
|
||||
# on initialization.
|
||||
# @option opts [Boolean] :slave_ok (false) Must be set to +true+ when connecting
|
||||
# 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
|
||||
# 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,
|
||||
@ -534,8 +535,10 @@ module Mongo
|
||||
end
|
||||
end
|
||||
|
||||
# execute the block and log the operation as described by name/payload
|
||||
def instrument( name, payload = {}, &blk )
|
||||
# Execute the block and log the operation described by name
|
||||
# and payload.
|
||||
# TODO: Not sure if this should take a block.
|
||||
def instrument(name, payload = {}, &blk)
|
||||
res = yield
|
||||
log_operation(name, payload)
|
||||
res
|
||||
@ -572,7 +575,12 @@ module Mongo
|
||||
@primary = 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)
|
||||
connect if should_connect
|
||||
@ -596,7 +604,7 @@ module Mongo
|
||||
|
||||
## Logging methods
|
||||
|
||||
def log_operation( name, payload )
|
||||
def log_operation(name, payload)
|
||||
return unless @logger
|
||||
msg = "#{payload[:database]}['#{payload[:collection]}'].#{name}("
|
||||
msg += payload.values_at(:selector, :document, :documents, :fields ).compact.map(&:inspect).join(', ') + ")"
|
||||
|
@ -378,7 +378,7 @@ module Mongo
|
||||
false
|
||||
else
|
||||
message = construct_query_message
|
||||
@connection.instrument( :find, instrument_payload ) do
|
||||
@connection.instrument(:find, instrument_payload) do
|
||||
results, @n_received, @cursor_id = @connection.receive_message(
|
||||
Mongo::Constants::OP_QUERY, message, nil, @socket, @command)
|
||||
@returned += @n_received
|
||||
|
Loading…
Reference in New Issue
Block a user