Optimize MongoDB::Connection#receive_response_header by using raw string operations and unpack() instead of the slower ByteBuffer.
This commit is contained in:
parent
e1bf168767
commit
c6206eddf4
|
@ -768,17 +768,14 @@ module Mongo
|
||||||
end
|
end
|
||||||
|
|
||||||
def receive_response_header(sock)
|
def receive_response_header(sock)
|
||||||
header_buf = BSON::ByteBuffer.new
|
header_buf = receive_message_on_socket(RESPONSE_HEADER_SIZE, sock)
|
||||||
header_buf.put_array(receive_message_on_socket(RESPONSE_HEADER_SIZE, sock).unpack("C*"))
|
|
||||||
if header_buf.length != RESPONSE_HEADER_SIZE
|
if header_buf.length != RESPONSE_HEADER_SIZE
|
||||||
raise "Short read for DB response header; " +
|
raise "Short read for DB response header; " +
|
||||||
"expected #{RESPONSE_HEADER_SIZE} bytes, saw #{header_buf.length}"
|
"expected #{RESPONSE_HEADER_SIZE} bytes, saw #{header_buf.length}"
|
||||||
end
|
end
|
||||||
header_buf.rewind
|
flags, cursor_id_a, cursor_id_b, starting_from, number_remaining = header_buf.unpack('VVVVV')
|
||||||
check_response_flags(header_buf.get_int)
|
check_response_flags(flags)
|
||||||
cursor_id = header_buf.get_long
|
cursor_id = (cursor_id_b << 32) + cursor_id_a
|
||||||
starting_from = header_buf.get_int
|
|
||||||
number_remaining = header_buf.get_int
|
|
||||||
[number_remaining, cursor_id]
|
[number_remaining, cursor_id]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue