scylladb / gocql

Package gocql implements a fast and robust ScyllaDB client for the Go programming language.
https://docs.scylladb.com/stable/using-scylla/drivers/cql-drivers/scylla-go-driver.html
BSD 3-Clause "New" or "Revised" License
169 stars 47 forks source link

HostInfo: reduce mutex.Locks #165

Closed moguchev closed 3 weeks ago

moguchev commented 3 months ago

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 https://github.com/scylladb/gocql/pull/164 (*HostInfo).HostName leads to spending a lot of time in Lock... Also in QueryObserver and BatchObserver we calls public methods of HostInfo (HostName , HostNameAndPort) for metrics and we have a lot of mutex locks.

roydahan commented 2 months ago

Please add a descriptive commit message to your commit.

dkropachev commented 1 month ago

I would recommend to use atomic.Pointer instead, please take a look this paper

Since HostInfo experiance mostly read access, referred solution is going to be up to 90 times faster than this one.

mykaul commented 1 month ago

@moguchev - can you refresh the PR, addressing above comments?

moguchev commented 1 month ago

@moguchev - can you refresh the PR, addressing above comments?

Yes, I’ll do it

dkropachev commented 1 month ago

@moguchev , I have given a try to atomic update, it is too intrusive and is going to create lot's of conflict with upstream, so it is better not to do that

mykaul commented 3 weeks ago

Thanks @moguchev for your contribution!

mykaul commented 1 week ago

1.14.2 was released with your contribution @moguchev - thanks again!