open-im-server icon indicating copy to clipboard operation
open-im-server copied to clipboard

大量客户端连接,严重问题(无任何业务,cpu很高)

Open situnan opened this issue 3 years ago • 6 comments

分析:ws_server.go文件中,维护的map(wsUserToConn ,wsConnToUser ),当存储很多client信息(200w)的时候,内存很高,这样gc间隔扫描全部大内存,导致耗时费cpu,请修正。(这样的client不做任何业务,只是保活)

type WServer struct { wsAddr string wsMaxConnNum int wsUpGrader *websocket.Upgrader wsConnToUser map[*UserConn]map[string]string wsUserToConn map[string]map[string]*UserConn }

situnan avatar Feb 28 '22 08:02 situnan

What is your optimization plan?

skiffer-git avatar Mar 01 '22 08:03 skiffer-git

Need to customize a map implementation.for golang, map value has no pointer, gc is not scanned, and slices are not scanned (the tube has a pointer) etc:

type LMap struct { objSlice []LMapObj idxMap map[int]int maxIdx int }

situnan avatar Mar 01 '22 08:03 situnan

hi situnan, did you just guess without real test?

circlestriker avatar Mar 18 '22 02:03 circlestriker

This is an obvious problem and is a limitation of golang, map usage. You can test the small units yourself

situnan avatar Mar 18 '22 02:03 situnan

in your design, you make more than 100,000 clients connect to one server?

circlestriker avatar Mar 18 '22 03:03 circlestriker

"当存储很多client信息(200w)的时候", this wouldn't happen in a server in practice, I think this issue could be closed. @situnan

circlestriker avatar Mar 20 '22 00:03 circlestriker

从您举出的例子的场景来看, 是有性能问题的. 但实际上, 客户端200w连接不可能打在一台服务器的, 这个不可能的断言是从业务侧来考虑的. 当您的业务会出现同时w人在线的时候, 那么业务团队就基本上会考虑集群部署了. 单体架构也许会存在各种黑科技优化策略, 可以支持百万连接与并发, 但实际生产过程中, 随着业务流量的增加会从单体逐步拓展为集群服务器, 既能分担压力也能保证可用性. 可以参考书籍 https://weread.qq.com/web/bookDetail/cc1326e05bcc52cc1669fc0 来获取架构演变相关的知识. 如果您因为特殊性的原因执意要单服务器支撑百万流量, 那么我很希望能学到您的优化策略

BaiMoHan avatar Oct 26 '22 09:10 BaiMoHan

/inivte

skiffer-git avatar May 19 '23 12:05 skiffer-git

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


/invite

kubbot avatar May 19 '23 12:05 kubbot