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

[Feature Request] KEEP_ALIVE_CONNECTIONS #1272

Open
halaei opened this issue Jul 24, 2018 · 3 comments
Open

[Feature Request] KEEP_ALIVE_CONNECTIONS #1272

halaei opened this issue Jul 24, 2018 · 3 comments

Comments

@halaei
Copy link

halaei commented Jul 24, 2018

It will be nice if a keepalive config similar to what nginx upstream has gets added to sanic. Basically, it limits the number of idle connections, and closes the least recently used one when the limit is exceeded. I am not entirely sure, but I think it will be more useful than the current KEEP_ALIVE_TIMEOUT config.

reference: http://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive

@LittleLampLight
Copy link

Hi! Is there anyone working on that? I'd like to try to implement that, but not sure if that's desired by core developers.

Also, extra thoughts on realisation appreciated.

@ahopkins
Copy link
Member

ahopkins commented Dec 25, 2018

@LittleLampLight It does sound like something that should not be too difficult to add.

Take a look at https://github.com/huge-success/sanic/blob/master/sanic/server.py, and you will see that connections currently are handled as a set(). I guess we would need to store them in some sort of an LRU cache instead. Using the standard library module would likely not be enough because we need to remove them ONLY if they are idle, and it probably would not be efficient to maintain both idle and active connections in a separate structure. But, we can discuss implementation details separately.

I am also curious to see if this is something that any of the ASGI frameworks have already implemented. We plan to make a push towards becoming ASGI compliant after the 1st of the year.

So, as for whether it is or is not a worthwhile use of your time, the answer sort of depends to what degree we adopt and push ASGI. However, it is my personal opinion that even if we jumped fully into that bucket, we will still be supporting and there will still be a need to handle this inside Sanic itself for some time. And if so, as long as there were no performance penalties, I see this as a worthwhile enhancement.

@stale
Copy link

stale bot commented May 14, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is incorrect, please respond with an update. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants