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

Cap the resource used by each connection #221

Open
lming opened this issue Jul 7, 2021 · 2 comments
Open

Cap the resource used by each connection #221

lming opened this issue Jul 7, 2021 · 2 comments
Assignees
Labels
enhancement New feature or request proposal Proposal for this repo waiting for response waiting for the response from commenter
Milestone

Comments

@lming
Copy link

lming commented Jul 7, 2021

it's important for gnet to cap per connection resource usage as other systems do, for example Linux kernal has options for per connection send/recv buffer size. In gnet's case, per connection's send buf size and async tasks number should be capped.

Suggestion: to expose per conn options MaxPendingWriteTasksPerConn and MaxWriteBuffSizePerConn
When client calls AsyncWrite:

  • The conn's NumPendingTasks is checked, returns error if it reaches the limit
  • The conn's write buf size is checked (TotalWriteBuffSizeInPendingTasks + len(c.outboundBuffer) < `MaxWriteBuffSizePerConn), returns error if the write buf size reaches the limit

With this change, the caller is aware of the error immediately when one of the two limits is reached. I am not sure how difficult to do the buf size check within AsyncWrite in a lock-free fashion though.

@lming lming added enhancement New feature or request proposal Proposal for this repo labels Jul 7, 2021
@xscode-auto-reply
Copy link

Thanks for opening a new issue. The team has been notified and will review it as soon as possible.
For urgent issues and priority support, visit https://xscode.com/panjf2000/gnet

@panjf2000
Copy link
Owner

With this change, the caller is aware of the error immediately when one of the two limits is reached. I am not sure how difficult to do the buf size check within AsyncWrite in a lock-free fashion though.

Maybe consider not doing it in a synchronous way but asynchronous approach: callback or channel, I don't want this change to cause any data race or introduce a mutex.

@panjf2000 panjf2000 added the waiting for response waiting for the response from commenter label Jul 10, 2021
@panjf2000 panjf2000 added this to the v2 milestone Oct 7, 2021
@panjf2000 panjf2000 modified the milestones: v2, Long term Jan 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request proposal Proposal for this repo waiting for response waiting for the response from commenter
Projects
None yet
Development

No branches or pull requests

2 participants