-
Notifications
You must be signed in to change notification settings - Fork 65
Memory optimizations #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,8 @@ def initialize(config, connect_timeout:, read_timeout:, write_timeout:) | |
read_timeout: read_timeout, | ||
write_timeout: write_timeout, | ||
) | ||
|
||
@buffer = String.new(encoding: Encoding::BINARY, capacity: 127) | ||
rescue SystemCallError, OpenSSL::SSL::SSLError, SocketError => error | ||
raise CannotConnectError, error.message, error.backtrace | ||
end | ||
|
@@ -98,21 +100,22 @@ def write_timeout=(timeout) | |
end | ||
|
||
def write(command) | ||
buffer = RESP3.dump(command) | ||
@buffer.clear | ||
RESP3.dump(command, @buffer) | ||
Comment on lines
+103
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So So this save allocating a string slot, but will If we want to be smart we want to re-used that malloced region, but have to be careful not to end up with a giant buffer, so we'd need to clear it if it past a certain size. Unfortunately the only way to get the size of the We also have to be super careful not to leak data, as that happened in the past with a similar optimization ruby/net-protocol#19 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Can we currently do this from ruby? I see the proposed patch into ruby is not merged yet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Well, if you pass the string to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But we are using it just for write in this case ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yeah, sorry I missed we where passing it to I think if we call |
||
begin | ||
@io.write(buffer) | ||
@io.write(@buffer) | ||
rescue SystemCallError, IOError => error | ||
raise ConnectionError, error.message | ||
end | ||
end | ||
|
||
def write_multi(commands) | ||
buffer = nil | ||
@buffer.clear | ||
commands.each do |command| | ||
buffer = RESP3.dump(command, buffer) | ||
RESP3.dump(command, @buffer) | ||
end | ||
begin | ||
@io.write(buffer) | ||
@io.write(@buffer) | ||
rescue SystemCallError, IOError => error | ||
raise ConnectionError, error.message | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That
127
is quite arbitrary, would be worth putting some thoughts into it, or making it configurable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was taken from the buffer definition it already uses -
redis-client/lib/redis_client/ruby_connection/resp3.rb
Lines 53 to 55 in aa5a308