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

make WriteTo non-blocking #525

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aldernero
Copy link
Contributor

What this PR does:
This PR makes the WriteTo function non-blocking, and adds a configurable maximum writes parameter to control concurrency.

Which issue(s) this PR fixes:
#192

Fixes #

Checklist

  • Tests updated
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Comment on lines +435 to +439
t.writeCh <- struct{}{}
go func() {
defer func() { <-t.writeCh }()
t.writeToAsync(b, addr)
}()
Copy link
Member

Choose a reason for hiding this comment

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

Instead of starting new goroutine for each write, shall we have a pool of writing goroutines, and pass them messages to write via channel?

@@ -426,7 +432,15 @@ func (t *TCPTransport) getAdvertisedAddr() string {
func (t *TCPTransport) WriteTo(b []byte, addr string) (time.Time, error) {
t.sentPackets.Inc()
t.sentPacketsBytes.Add(float64(len(b)))
t.writeCh <- struct{}{}
Copy link
Member

Choose a reason for hiding this comment

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

Is WriteTo only called from single goroutine? If not, it just became more blocking.

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.

2 participants