Golang goroutines 共享 RPC 连接

huangapple go评论97阅读模式
英文:

Golang goroutines sharing RPC connection

问题

我有一个使用Golang编写的服务器,它使用专用的goroutine来处理传入请求。这些goroutine将使用rpc/gob访问另一个后端go服务器。为了更好地重用连接以使Gob工作得更好(共享连接的请求可以重用元数据而无需重新发送,还可以节省TCP初始化的时间),我正在考虑实现类似连接池的机制(类似于mysql客户端池)。但在此之前,我是否遗漏了任何重要的事情?

有没有Go特定的方法来处理这种共享RPC客户端的情况?
或者有没有已经构建好的项目来处理这种情况?

英文:

I have a Golang server which serve inbound requests with dedicated goroutine. Those goroutines would access another backend go server using rpc/gob. In case of reusing the connection to make Gob works better (requests sharing connection may reuse meta data without resending, also save time for TCP initiation), I'm thinking of implementing connection pool alike mechanism (like mysql client pool), but before that have I missed anything important?

Any Go specific way to handle such Shared RPC client?
Or any project there built to handle this situation?

答案1

得分: 1

请参考 https://github.com/valyala/gorpc - 这个库在RPC优化方面更进一步 - 它使用独立的读写循环、消息批处理和压缩。与net/rpc相比,它还具有更简单的API。

在一个真实的生产项目中,从基于http的rpc切换到gorpc,可以将RPC网络带宽从300Mbit/s降低到24Mbit/s。

英文:

See https://github.com/valyala/gorpc - this library goes further with RPC optimization - it uses independent read and write loops, message batching and compression. It also has much simpler API comparing to net/rpc .

Switching from http-based rpc to gorpc in a real production project allowed reducing RPC network bandwidth from 300Mbit/s to 24Mbit/s.

答案2

得分: 0

经过一些调查,我发现在内置的客户端库中已经实现了一个池化机制,基于 http://golang.org/src/pkg/net/rpc/client.go 的代码,但我仍然很感兴趣,如果有人能与我分享更多见解的话。

英文:

After some investigation I found a pooling mechanism already been done in the built-in client lib, based on the code at http://golang.org/src/pkg/net/rpc/client.go , but I'm still interested if anyone can share with me more insights.

huangapple
  • 本文由 发表于 2014年7月31日 10:51:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/25050090.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定