-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Change SocketCache to be shared between nodes #2501
Conversation
c684e2e
to
972638b
Compare
Signed-off-by: Yuta Iwama <[email protected]>
9a77fa9
to
407f963
Compare
Signed-off-by: Yuta Iwama <[email protected]>
Signed-off-by: Yuta Iwama <[email protected]>
407f963
to
6c604fc
Compare
# This method is thread unsafe | ||
def expired?(key = Thread.current.object_id) | ||
@active_socks[key].timeout ? @active_socks[key].timeout < Time.now : false | ||
def expired_socket?(sock, time: Time.now) |
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 method is private so normal argument seems enough for time. Not important comment.
end | ||
end | ||
|
||
def clear | ||
def checkin(sock) |
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.
Hmm... checkin
is unclear for me. After checkin
, we are inflight for airplane but this method changes inflight to available. checkout
too. Maybe, we don't use checkout
for flight.
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.
I referred connection_pool gem to determine the name of them.
https://github.com/mperham/connection_pool/blob/99b81aa0a9dccb3b423260740ce2d603f1479356/lib/connection_pool.rb#L80
Any name is okay for me if it's clear for readers. Do you have any suggestions?
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.
Hmm.... I see. If this naming is popular in ruby, it is okay for me.
@inactive_sockets.clear | ||
end | ||
|
||
while (s = sockets.pop) |
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.
each
is more lightweight due to no sockets
update.
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.
right……… fixed eda267c
else | ||
@log.warn("Not found key for dec_ref: #{key}") | ||
end | ||
while (s = sockets.pop) |
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.
ditto
@log.debug("connect new socket #{new_tsock}") | ||
|
||
@inflight_sockets[val] = new_tsock | ||
return new_tsock.sock |
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.
To reduce return
by if
if tsock
tsock.sock
else
# same
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.
fixed 5dd10e6
Signed-off-by: Yuta Iwama <[email protected]>
Signed-off-by: Yuta Iwama <[email protected]>
if tsock | ||
tsock.sock | ||
else | ||
val = yield |
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.
sock
or new_sock
is better than val
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.
fixed 14985b3
Signed-off-by: Yuta Iwama <[email protected]>
looks good. |
Which issue(s) this PR fixes:
no
What this PR does / why we need it:
Old SocketCache isn't shared between other nodes since node's
port
andhost
is fixed at start time.In the situation nodes' port and host change dynamically, sharing SocketCache between nodes makes more efficient.
And recent refactoring can make SocketCache more simple.
Docs Changes:
no need
Release Note:
no need