aio-libs / aio-libs/aiohttp

Add keepalive_time parameter to the RequestHandler, or custom logic to decide to terminate the connection.

Ouverte
#7,804 5 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
enhancement
Langage dominant
Python
Étoiles
16.5k
Forks
2.4k
Merge moyen
17 h 22 min
PR mergées (30 j)
212

Description

### Is your feature request related to a problem?

In case the aiohttp app runs in multiple replicas behind the TCP-based load-balancing, it keeps the same connection pointing to the same replica, and with high keep-alive, this effectively bypasses the load-balancing. This can be solved on client-side by using short keep-alive, but we would like to have it solved on the side of server, using aiohttp.
I don't want to set `tcp_keepalive=False`, in the `RequestHandler`, because that would lead to lots of time being spent on establishing new connection.

### Describe the solution you'd like

I would like to have a new parameter, called `keepalive_time` in the `RequestHandler`, which would mimick the behavior of http://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_time so it would let me terminate the connection after some time.
Or it could be based on number of requests, that there would be a parameter for max. amount of request to be allowed to be processed inside the same connection and then the connection would be closed.

### Describe alternatives you've considered

I have considered using `tcp_keepalive=False` in `RequestHandler` but that is quite drastic. I also considered overloading the https://github.com/aio-libs/aiohttp/blob/v3.8.6/aiohttp/web_protocol.py#L405-L421 `_process_keepalive` method, but because it's not meant to be public, I want to avoid abusing the internals like this.
The `tcp_keepalive` does not have anything in common with the http keep-alive.

### Related component

Server

### Additional context

We have aiohttp deployed to k8s in multiple replicas, where we have the tcp-based load-balancing and being able to handle this on the server instead of client would be great.

### Code of Conduct

- [X] I agree to follow the aio-libs Code of Conduct

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.