如何在Go中高效处理数千个保持连接的连接?

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

How to efficiently handle thousands of keep alive connections in Go?

问题

使用golang的net/http服务器处理连接时,有没有一种更好的模式来处理每秒相对较低的10,000个保持连接的连接?

我的基准性能大约是每秒50,000个请求,但是在实际流量(来自实时竞价交易所)中,我很难达到每秒8,000个请求。

我知道硬件负载均衡器可以进行连接复用,但是在Go中似乎也可以实现相同类型的模式。

英文:

Using golang's net/http server to handle connections, is there a pattern to better handle 10,000 keep alive connections with relatively low requests per second each?

my benchmark performance with something like Wrk is 50,000 requests per second, and with real traffic (from realtime bidding exchanges) I have a hard time beating 8,000 requests per second.

I know connection multiplexing from a hardware loadbalancer is possible, but it seems like the same type of pattern can be achieved in Go.

答案1

得分: 1

你可以使用 IPC 协议(例如 JSON RPC)通过 UNIX 和 TCP sockets 在本地和远程服务器上分发负载。

相关链接:https://stackoverflow.com/questions/9366550/go-inter-process-communication

至于性能瓶颈,这个问题在 go-nuts 邮件列表上已经广泛讨论过。在撰写本文时,运行时的 goroutine 调度器和全局停顿垃圾收集器是性能瓶颈。

核心团队最近对运行时进行了重大改进,以缓解这个问题,但仍有改进的空间。举个例子:

由于运行时和网络库之间的紧密耦合,网络操作所需的上下文切换更少。

英文:

You can distribute load on local and remote servers using an IPC protocol like JSON RPC through e.g. UNIX and TCP sockets.

Related: https://stackoverflow.com/questions/9366550/go-inter-process-communication

As to the performance bottleneck; it has been discussed extensively on the go-nuts mailing list. At the time of writing it is the runtime's goroutine scheduler and world-stopping garbage collector.

The core team has recently made major improvements to the runtime to alleviate this problem yet there still is room for improvement. To quote one example:

> Due to tighter coupling of the run-time and network libraries, fewer context switches are required on network operations.

huangapple
  • 本文由 发表于 2013年9月6日 09:03:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/18648278.html
匿名

发表评论

匿名网友

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

确定