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

fix #164 and respect ratelimit for bulk joins #165

Merged
merged 22 commits into from
Dec 19, 2021
Merged

fix #164 and respect ratelimit for bulk joins #165

merged 22 commits into from
Dec 19, 2021

Conversation

gempir
Copy link
Owner

@gempir gempir commented Oct 9, 2021

Ratelimiting implemented based on a slice with times in it. All the other examples of sliding window implementations looked super complicated to me and not so straight forward.

I'm not sure if this is the correct way to solve this problem, but at least my tests run now. Which they haven't done for any implementation before as you can see by the build history.

One slight weird thing still is I added a 100ms extra sleep, because on CI it kept failing, locally I could run it fine. This is slightly alarming because I'm wondering if on different systems it could behave even differently.

But running go test -race brings up no issues.

@coveralls
Copy link

coveralls commented Oct 10, 2021

Coverage Status

Coverage increased (+0.02%) to 97.95% when pulling 1029d5d on bulk-joins into 5da4523 on master.

ratelimit.go Outdated Show resolved Hide resolved
@deefdragon

This comment has been minimized.

@gempir

This comment has been minimized.

@deefdragon

This comment has been minimized.

@gempir gempir marked this pull request as ready for review December 18, 2021 18:39
@gempir gempir requested a review from pajlada December 18, 2021 18:40
}
}

func (r *RateLimiter) Throttle() {
func (r *RateLimiter) Throttle(count int) {
Copy link

@deefdragon deefdragon Dec 18, 2021

Choose a reason for hiding this comment

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

Should there be a mutex on this internally to the ratelimiter, or is it/are you planning on handling it externally?

Copy link
Owner Author

@gempir gempir Dec 18, 2021

Choose a reason for hiding this comment

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

The writer runs in with channel so there should be not concurrent access of this function

client.go Outdated Show resolved Hide resolved
Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
Copy link
Collaborator

@pajlada pajlada left a comment

Choose a reason for hiding this comment

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

Looks good to me!

}
if sb.Len() == len(baseMessage) {
sb.WriteString(" #" + channel)
channelsWritten++
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be more clear to increment channelsWritten after the if-else? I'm not sold on moving it or leaving it as is myself

Copy link
Owner Author

Choose a reason for hiding this comment

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

I was unsure as well, but this is probably good.

In a way it also documents each branch of the if statement

@gempir gempir merged commit 0a43a55 into master Dec 19, 2021
@gempir gempir deleted the bulk-joins branch December 19, 2021 14:07
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.

4 participants