-
Notifications
You must be signed in to change notification settings - Fork 98
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
Replace mutex in autopaho with atomic pointer #279
Comments
Can you please provide more information re "lock contentions", have you identified a performance issue in a real application which this change fixes? I'm open to the use of |
The lock contentions stem from upper layer application, where there are many Go routines that Publish/Subscribe/Unsubscribe through the client. But with current Subscribe/Unsubscribe (and to certain extent Publish, as async Publish doesn't return broker ack) as blocking operations until ack from broker, funneling them through a single channel is not viable. |
And has the change to |
In grand scheme of things, this probably will not make large differences. I agree with you that using low-level atomics can be harder to understand and easier to make mistakes. However, for this use case, it can make the code cleaner and easier to understand. Currently there is cli (client) with 2 states connUp and connDown. Using atomic.Pointer allows these 2 states (actually they're more gates) to be associated with the client as one unit:
|
Is your feature request related to a problem? Please describe.
Autopaho currently use mutex for Publish/Subscribe/etc. It can lead to lock contentions.
Describe the solution you'd like
Replace mutex with atomic.Pointer. Put cli, connUp, and connDown into one struct, so it can be stored in one atomic operation.
Additional context
Here is the implementation, only autopaho/auto* are modified.
The text was updated successfully, but these errors were encountered: