Skip to content
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

Merged
merged 6 commits into from
Jul 24, 2019

Conversation

ganmacs
Copy link
Member

@ganmacs ganmacs commented Jul 16, 2019

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 and host 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

@ganmacs ganmacs self-assigned this Jul 16, 2019
@ganmacs ganmacs changed the title Socket cache udpate Change SocketCache to be shared with threads Jul 16, 2019
@ganmacs ganmacs changed the title Change SocketCache to be shared with threads Change SocketCache to be shared with nodes Jul 16, 2019
@ganmacs ganmacs force-pushed the socket-cache-udpate branch from c684e2e to 972638b Compare July 17, 2019 07:10
Signed-off-by: Yuta Iwama <[email protected]>
@ganmacs ganmacs force-pushed the socket-cache-udpate branch 4 times, most recently from 9a77fa9 to 407f963 Compare July 19, 2019 06:01
@ganmacs ganmacs force-pushed the socket-cache-udpate branch from 407f963 to 6c604fc Compare July 19, 2019 06:07
@ganmacs ganmacs changed the title Change SocketCache to be shared with nodes Change SocketCache to be shared between nodes Jul 19, 2019
@ganmacs ganmacs requested a review from repeatedly July 19, 2019 06:13
@ganmacs ganmacs marked this pull request as ready for review July 19, 2019 06:15
# 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)
Copy link
Member

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)
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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)
Copy link
Member

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.

Copy link
Member Author

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)
Copy link
Member

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
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed 5dd10e6

ganmacs added 2 commits July 23, 2019 12:28
Signed-off-by: Yuta Iwama <[email protected]>
Signed-off-by: Yuta Iwama <[email protected]>
if tsock
tsock.sock
else
val = yield
Copy link
Member

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

Copy link
Member Author

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]>
@repeatedly repeatedly merged commit 4635aab into fluent:master Jul 24, 2019
@repeatedly
Copy link
Member

looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants