-
Notifications
You must be signed in to change notification settings - Fork 59
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
HostInfo: reduce mutex.Locks #165
HostInfo: reduce mutex.Locks #165
Conversation
host_source.go
Outdated
@@ -410,16 +410,43 @@ func (h *HostInfo) IsUp() bool { | |||
} | |||
|
|||
func (h *HostInfo) HostnameAndPort() string { | |||
// Fast path: in 99.9% hostname is not empty |
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.
How did you deduce this number?
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.
99.9% is certainly a big number.
We actively use the public methods Hostname()
and HostnameAndPort()
in metrics.QueryObserver
. Accordingly, for each request in scylladb we call Hostname()/HostnameAndPort()
, but if the cluster is stable and no reccconections occur, then hostname in most cases is not empty.
I'll attach go profile of mutex (before -> after) later
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.
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.
host_source.go
Outdated
addr, _ := h.connectAddressLocked() | ||
h.hostname = addr.String() | ||
} | ||
return net.JoinHostPort(h.hostname, strconv.Itoa(h.port)) | ||
} | ||
|
||
func (h *HostInfo) Hostname() string { | ||
// Fast path: in 99.9% hostname is not empty |
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.
Same as before
c9405f1
to
f8f2b91
Compare
f8f2b91
to
910c15c
Compare
Please add a descriptive commit message to your commit. |
I would recommend to use Since |
@moguchev - can you refresh the PR, addressing above comments? |
Yes, I’ll do it |
@moguchev , I have given a try to |
Thanks @moguchev for your contribution! |
1.14.2 was released with your contribution @moguchev - thanks again! |
I know that there is comment by @Zariel to reduce locking.
I didn't thoroughly refactor the code, but I found fast and cheap optimization in functions
(*HostInfo).HostName
and(*HostInfo).HostNameAndPort
.In our case of #164
(*HostInfo).HostName
leads to spending a lot of time in Lock...Also in
QueryObserver
andBatchObserver
we calls public methods ofHostInfo
(HostName
,HostNameAndPort
) for metrics and we have a lot of mutex locks.