Getty: A Layered Go Network Framework – Design, Optimization, and Performance Insights
Getty is a Go-based, layered network framework that provides data interaction, business control, and network layers with extensible monitoring interfaces, featuring custom SDKs, goroutine pool optimizations, lazy reconnection, sync.Pool tuning, and benchmark results demonstrating high throughput and low resource usage.
The author, with over ten years of experience in internet infrastructure, built a personal C SDK and later a Go SDK, eventually creating Getty, a Go‑based network framework that follows a strict layered architecture.
Getty separates concerns into three layers: the Data Interaction Layer, which defines a ReadWriter interface for serialization; the Business Control Layer, composed of Connection and Session abstractions; and the Network Layer, which exposes WebSocket‑style monitoring APIs such as OnOpen , OnClose , OnMessage , OnError and OnCron .
The Data Interaction Layer requires users to implement Read and Write methods; the Read method returns three values to handle TCP stream issues (nil,0,error), (nil,0,nil), (nil,pkgLen,nil) or (pkg,0,error) depending on packet completeness.
In the Business Control Layer, Session manages a single connection’s lifecycle, while Connection abstracts TCP, UDP, and WebSocket transports ( gettyTCPConn , gettyUDPConn , gettyWSConn ). Users plug their own EventListener implementation to process messages via OnMessage and schedule tasks via OnCron .
Getty originally used two goroutines per connection (one for receive + logic, one for send + cron). To improve throughput, a dedicated Goroutine Pool was introduced, evolving from a simple 1:1 model to scalable M:N models, and finally to an unlimited pool inspired by "A Million WebSockets and Go". The pool separates packet reception, logic handling, and sending, reducing per‑connection goroutine count.
A "lazy reconnect" strategy was later added: the sending goroutine, upon detecting a closed session, checks the session pool size and, if needed, initiates a new connection without a separate polling goroutine. This eliminates the need for a dedicated reconnection goroutine.
Getty also used sync.Pool to cache bytes.Buffer objects for packet handling. In high‑short‑connection scenarios this caused memory bloat, so the pool was tuned to limit buffer sizes (1 KiB‑20 KiB) and object count, and a fallback to direct allocation was added. Example code: var defaultPool *ObjectPool func init() { defaultPool = NewObjectPool(func() PoolObject { return new(bytes.Buffer) }) } func GetBytesBuffer() *bytes.Buffer { return defaultPool.Get().(*bytes.Buffer) } func PutBytesBuffer(buf *bytes.Buffer) { defaultPool.Put(buf) }
Benchmarking on a typical Alibaba environment showed Getty achieving 12 556 TPS, ~11 MiB/s throughput, with CPU usage under 6 % and memory under 100 MiB. The server uses a single goroutine per TCP connection after the optimizations.
Since its first release in 2016, Getty has added UDP support, protobuf/json RPC, service discovery (Zookeeper/etcd), fixed‑size and unlimited goroutine pools, timer‑wheel integration, and extensive performance testing. The project is now maintained by the Apache Dubbo community.
High Availability Architecture
Official account for High Availability Architecture.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.