Total Pageviews

Sunday, 15 November 2015

TCP路由代理-ProxyMachine

Proxy Machine 是一个简单的 7 层 TCP 路由代理,基于 EventMachine 构建,可使用 Ruby 语言配置路由规则。如果你需要将不同的请求内容转发到后端不同的服务器上,那么 ProxyMachine 非常适合你。
ProxyMachine 主要为 Github 的集群架构而开发,每天可代理几百万请求,性能和内存占用表现良好。

安装:
$ gem install proxymachine -s http://gemcutter.org

Usage:
  proxymachine -c <config file> [-h <host>] [-p <port>]

Options:
  -c, --config CONFIG              Configuration file
  -h, --host HOST                  Hostname to bind. Default 0.0.0.0
  -p, --port PORT                  Port to listen on. Default 5432
-----------

Description

ProxyMachine is a simple content aware (layer 7) TCP routing proxy built on EventMachine that lets you configure the routing logic in Ruby.
If you need to proxy connections to different backend servers depending on the contents of the transmission, then ProxyMachine will make your life easy!
The idea here is simple. For each client connection, start receiving data chunks and placing them into a buffer. Each time a new chunk arrives, send the buffer to a user specified block. The block's job is to parse the buffer to determine where the connection should be proxied. If the buffer contains enough data to make a determination, the block returns the address and port of the correct backend server. If not, it can choose to do nothing and wait for more data to arrive, close the connection, or close the connection after sending custom data. Once the block returns an address, a connection to the backend is made, the buffer is replayed to the backend, and the client and backend connections are hooked up to form a transparent proxy. This bidirectional proxy continues to exist until either the client or backend close the connection.
ProxyMachine was developed for GitHub's federated architecture and is successfully used in production to proxy millions of requests every day. The performance and memory profile have both proven to be excellent.
from https://github.com/mojombo/proxymachine