Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bparli/convey
Layer 4 load balancer with dynamic configuration loading
https://github.com/bparli/convey
load-balancer rust tcp tokio
Last synced: about 1 month ago
JSON representation
Layer 4 load balancer with dynamic configuration loading
- Host: GitHub
- URL: https://github.com/bparli/convey
- Owner: bparli
- License: mit
- Created: 2018-12-26T02:57:12.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-06-17T17:43:56.000Z (over 3 years ago)
- Last Synced: 2024-08-01T20:48:00.948Z (4 months ago)
- Topics: load-balancer, rust, tcp, tokio
- Language: Rust
- Homepage:
- Size: 467 KB
- Stars: 337
- Watchers: 5
- Forks: 45
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-rust - Convey - Layer 4 Load Balancer with dynamic configuration loading. (Libraries / Cloud)
- awesome-rust-cn - Convey - 具有动态配置加载的第4层负载平衡器. (库 Libraries / 云 Cloud)
- awesome-rust - Convey - Layer 4 Load Balancer with dynamic configuration loading. (Libraries / Cloud)
- fucking-awesome-rust - Convey - Layer 4 Load Balancer with dynamic configuration loading. (Libraries / Cloud)
- fucking-awesome-rust - Convey - Layer 4 Load Balancer with dynamic configuration loading. (Libraries / Cloud)
README
# Convey
Layer 4 load balancer with dynamic configuration loading featuring proxy, passthrough and direct server return modes## Features
- Stats page (at /stats) with basic connection/bytes counters and backend server pool statuses
- Dynamic configuration re-loading of backend servers and associated weights. Configuration is loaded via a .toml file (see sample.toml for a full example).
- Tcp-based health checking of backend servers at a configured interval. If a server fails its health check it will be automatically removed from selection and added back once its health checks are successful.### Proxy Features
- Event-driven TCP load balancer built on [tokio].
- Weighted round-robin load balancing. For uniform round robin simply leave out the weights or set them to be equal.
- TCP connection termination### Passthrough and Direct Server Return (DSR) Features
- Packet forwarding (no TCP termination)
- Minimal internal connection tracking
- NAT## Usage
```
Convey 0.3.5Usage:
convey
convey --config=
convey (-p | --passthrough) --config=
convey (-d | --dsr) --config=
convey (-p | --passthrough)
convey (-d | --dsr)
convey (-h | --help)
convey (-v | --version)Options:
-h, --help Show this screen.s
-p, --passthrough Run load balancer in passthrough mode (instead of default proxy mode)
-d, --dsr Run load balancer in direct server mode (instead of default proxy mode)
--config= Config file location [default config.toml].
-v, --version Show version.
```### Passthrough mode
For passthrough mode we need a couple iptables rules on the convey load balancer to handle ingress packets from the client and responses from the backend load balanced servers. Since TCP is not terminating we need to ensure the OS does not send a RST in response to any packets destined for a port that does not have a process bound to it. We need to do the same for any packets came back through from a backend server. Convey internally assigns ephemeral ports 32768-61000 to map connections to clients.![passthrough](https://docs.google.com/drawings/d/e/2PACX-1vS1umK8iY4EryR0hV4s1lad2r5BrO4_nbFTCua9jqkPP7fSQXodXCZ8XD7kvkfeXxdphtMFczIij-K1/pub?w=581&h=326)
For passthrough mode on the convey load balancer
```
sudo iptables -t raw -A PREROUTING -p tcp --dport -j DROP
sudo iptables -t raw -A PREROUTING -p tcp --sport --dport 33768:61000 -j DROP
```To run
```
sudo ./target/release/convey --passthrough --config=sample-passthrough.toml
```### DSR Mode
For dsr mode we need the same iptables rule for ingress packets. Responses from the backend load balanced servers will be going directly to the clients. The "listening" port on the convey load balancer must match the backend load balanced servers listening ports in this mode.![dsr](https://docs.google.com/drawings/d/e/2PACX-1vTkBC0326E1hZwRw_KBbdiP3npNL_2KGq2QdUiS2J05xX1y5uhKIDegpEmviyvBWz4NmHbgVTB6jmsq/pub?w=581&h=326)
For dsr mode on the convey load balancer
```
sudo iptables -t raw -A PREROUTING -p tcp --dport -j DROP
```In dsr mode the backend servers "participate" in that their response packets must be sent directly to the client. Convey does not do any encapsulation so, for example, a gre tunnel is not an option. Instead, [Traffic Control] can be used as an egress nat.
For dsr mode on backend servers
```
sudo tc qdisc add dev root handle 10: htbsudo tc filter add dev parent 10: protocol ip prio 1 u32 match ip src match ip sport 0xffff match ip dst action ok
sudo tc filter add dev parent 10: protocol ip prio 10 u32 match ip src match ip sport 0xffff action nat egress
```To run
```
sudo ./target/release/convey --dsr --config=sample-passthrough.toml
```### Proxy
No special setup neccessary![proxy](https://docs.google.com/drawings/d/e/2PACX-1vQC7fAvVEs0Xb0kcAFfCLIVukhkIrlu-DS_tbrtgpRonmsHO9STpnXvI7NogXiBVUON9gS-L4MLqYV2/pub?w=581&h=326)
To run
```
sudo ./target/release/convey --config=sample-proxy.toml
```## Tests
The easiest way to run tests is to run them as superuser. This is because some of the tests spin up test servers as well as a convey load balancer instance.
```
sudo ~/.cargo/bin/cargo test
```## AF_XDP
The `feature/xdp` branch is a WIP using AF_XDP to loadbalance in passthrough and DSR modes. For now it will be maintained in a separate branch since it requires kernel versions 5.4 or greater.## Build
```cargo build --release```[tokio]: https://tokio.rs
[Traffic Control]: http://tldp.org/HOWTO/Traffic-Control-HOWTO/index.html