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

Improve concurrency: fewer goroutines #62

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

snej
Copy link
Contributor

@snej snej commented May 9, 2023

CBG-2952

  • Don't create new goroutines to encode/decode Message bodies.
  • Message state that's only needed while receiving or sending is broken out into new structs msgSender and msgStreamer.
  • New API for handling requests. Added AsyncHandler type, Dispatcher interface, and some Dispatcher implementations for typical tasks like handler-per-Profile and limited concurrency.
  • New ThreadPool class for handling requests asynchronously without spawning more goroutines.
  • receiver goroutine blocks and stops reading from the socket when the total size of received-but-unhandled requests exceeds a limit. (This exerts backpressure on the client.)

Note to reviewers:

The two commits here are best reviewed individually. One contains the real work; the rest just fixes a bunch of Go compiler warnings that have accumulated over time (mostly about capitalized error messages.)

@snej snej force-pushed the CBG-2952-better-concurrency branch 3 times, most recently from 85478ad to 2d6ce1a Compare May 10, 2023 23:50
snej added 2 commits May 10, 2023 17:03
- Don't create new goroutines to encode/decode Message bodies.
- Message state that's only needed while receiving or sending is broken out
  into new structs msgSender and msgStreamer.
- New API for handling requests. Added AsyncHandler type, Dispatcher interface,
  and some Dispatcher implementations for typical tasks like handler-per-Profile
  and limited concurrency.
- New ThreadPool class for handling requests asynchronously without spawning
  more goroutines.
- receiver goroutine blocks and stops reading from the socket when the total
  size of received-but-unhandled requests exceeds a limit. (This exerts
  backpressure on the client.)

CBG-2952
Most of them were about capitalized error messages...
@snej snej force-pushed the CBG-2952-better-concurrency branch from 2d6ce1a to 011516c Compare May 11, 2023 00:04
@snej snej marked this pull request as ready for review May 11, 2023 00:24
@snej snej requested a review from bbrks May 11, 2023 00:24
@snej snej assigned snej and bbrks and unassigned snej May 30, 2023
If an incomplete incoming reply has already been dispatched to the app, don't
change its body to an error when the connection closes.

Also made receiver.closePendingResponses() be called on the receiver's
parseLoop's goroutine, not the sender's.
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