cloudflare / cloudflare/pingora

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

Đang mở
#653 4 bình luận 0 reaction 0 người được giao Xem trên GitHub
enhancement
Ngôn ngữ chính
Rust
Star
27.4k
Fork
1.7k
Merge trung bình
6 giờ 22 phút
Pull request đã merge (30 ngày)
3

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.