-
-
Notifications
You must be signed in to change notification settings - Fork 596
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
Publish batching in Redis Engine #84
Conversation
To summarize things done in this pr: Added |
return resp, nil | ||
} | ||
wg.Add(1) | ||
go func(channel Channel) { |
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, this works but it feels off to me...
It's intentionally creating overhead and contention on the publish channel etc as well as spawning maybe thousands of goroutines. Perhaps that's not too bad in practice, but in theory it would be possible to do this much more efficiently if we had a real async API in our engine interface.
Maybe something for the future?
Actually that was not so simple because we don't call engine method directly from But anyway I think I changed it in a way you suggested - not adding new engine method though but returning error channel from existing and added helper method to publish synchronously to Result is wonderful: broadcast now 2 times faster for 10000 channels than version with goroutines. So overall performance improvement for broadcast is about 11-12x |
Great! Will look at code again tomorrow but that just didn't look very efficient! Thanks
|
adminChannel := app.config.AdminChannel | ||
app.RUnlock() | ||
return app.engine.publish(adminChannel, message, nil) | ||
func (app *Application) enginePublish(chID ChannelID, message []byte, opts *publishOpts) error { |
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.
Nitpick but that name is a little bit confusing. It's real purpose is a synchronous helper so maybe publishSync
would be cleaner name?
Not a big deal if you disagree though.
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.
Agree, just deleted it
This looks great to me 👍 If I get a chance, I'll try it out, but don't wait if you are happy. |
ok, thanks a lot for looking! I can't find something I can improve here at moment - so going to merge this then. This async publish method in engine opens a road to further optimizations maybe - i.e. something like |
As part of #59