cloudflare / cloudflare/pingora

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

Aperta
#653 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub
enhancement
Lingua principale
Rust
Stelle
27.4k
Fork
1.7k
Merge medio
6h 22m
PR unite (30g)
3

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia esaminando le API di HttpProxy, ProxyHttp, HttpServerApp, TransportConnector e ConnectionPool del crate pingora-proxy, quindi esamina l'esempio router_app nel PR indicato. Determina se il routing tra istanze on-demand di HttpProxy può mantenere pool e implementazioni separati, quindi documenta l'approccio consigliato o le modifiche API necessarie.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
rust
Ambito
backend-api-design, networking
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.