Skip to content

Instantly share code, notes, and snippets.

@shaunlee
shaunlee / gist:6484676
Last active December 22, 2015 14:18
新老RPC协议TCP数据包大小对比

新老RPC协议TCP数据包大小对比

新协议

共计 682 字节(压缩后429),其中请求数据 149 字节(141)、返回数据 533 字节(288)

老协议

共计 1650 字节,其中请求数据 370 字节、返回数据 1280 字节(HTTP 头 136 字节 + 数据 1144 字节)

通讯协议规范

新 RPC 服务器采用自定义文本协议,并满足以下条件:

  1. 可以在各种语言中简单的实现
  2. 能被快速解析
  3. 方便 Telnet 调试

相对于二进制协议,新 RPC 服务器的文本协议议具有较高的可读性,也容易被实现, 减少在客户端实现中出现BUG,并且解析性可以做到与二进制协议接近。

@shaunlee
shaunlee / ConnectionPoolWrapper.go
Last active September 10, 2017 21:35 — forked from rday/gist:3504674
Connection Pool
type InitFunction func() (interface{}, error)
type ConnectionPoolWrapper struct {
size int
pool chan interface{}
}
/**
Call the init function size times. If the init function fails during any call, then
the creation of the pool is considered a failure.