cloudflare / cloudflare/pingora

Question: how to dynamically route a request to an instance of HttpProxy<SV>?

Abierto
#653 4 comentarios 0 reacciones 0 asignados Ver en GitHub
enhancement
Lenguaje dominante
Rust
Estrellas
27.4k
Forks
1.7k
Merge medio
6 h 22 min
PR fusionados (30 d)
3

Descripción

Hi!

I'm evaluating the possibility of using Pingora to replace a solution based on Nginx and OpenResty. For that, I'm trying to route the HTTP request to one of many possible instances of `HttpProxy` based on the request's HTTP headers.

My reason to have multiple instances of `HttpProxy` is because I would like to have one connection pool per load balancer/upstream configuration and it seems to me that it is not possible at the moment when using a single `HttpProxy`. I have the expectation of being able to limit the number of TCP connections to a peer using the `TransportConnector`, or the `ConnectionPool` under it, at some point or, perhaps, patching them.

My other reason to have multiple instances of `HttpProxy` is because it is "statically linked" to the `ProxyHttp` and therefore one service will use a single `ProxyHttp` implementation. Meanwhile, my upstreams might require distinct behaviour which could be better constructed using isolated `ProxyHttp` implementations.

I also intend for these `HttpProxy` instances to be created on demand and eventually destroyed when no-longer required.

Initially I though about implementing the router as a `ProxyHttp` which would call the specialized implementations of `ProxyHttp` for each upstream, but then I realized that the connection pool is managed at the `HttpProxy` level, which implied that all my `ProxyHttp` implementations and their instances would share the same connection pool, hence the idea of implementing the router as a `HttpServerApp` and having it routing the requests to one of multiple instances of `HttpProxy`, each one with its own pool. For that I had to duplicate some code from `HttpProxy` and change the visibility of some methods in the crate `pingora-proxy` (see link below).

It crossed my mind that another possible implementation could route the request using Unix Domain Sockets internally. A "front end" `ProxyHttp` could route the request to one of many Unix Domain Sockets connected to "back end" instances of the specialized `ProxyHttp`. But it sounds to me that I will be adding unnecessary processing with that approach.

To illustrate what I'm trying to do, I created a PR that adds a `router_app` example to the `pingora-proxy` crate with the required visibility changes.

At last, my question: Is that a reasonable approach? How would you do it instead?

Example: https://github.com/lmalheiro/pingora/pull/1

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.