cloudflare / cloudflare/pingora

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

Open
#653 4 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
27.4k
Forks
1.7k
Avg merge
6h 22m
Merged PRs (30d)
3

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.