open-im-server
open-im-server copied to clipboard
大量客户端连接,严重问题(无任何业务,cpu很高)
分析: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 }
What is your optimization plan?
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 }
hi situnan, did you just guess without real test?
This is an obvious problem and is a limitation of golang, map usage. You can test the small units yourself
in your design, you make more than 100,000 clients connect to one server?
"当存储很多client信息(200w)的时候", this wouldn't happen in a server in practice, I think this issue could be closed. @situnan
从您举出的例子的场景来看, 是有性能问题的. 但实际上, 客户端200w连接不可能打在一台服务器的, 这个不可能的断言是从业务侧来考虑的. 当您的业务会出现同时w人在线的时候, 那么业务团队就基本上会考虑集群部署了. 单体架构也许会存在各种黑科技优化策略, 可以支持百万连接与并发, 但实际生产过程中, 随着业务流量的增加会从单体逐步拓展为集群服务器, 既能分担压力也能保证可用性. 可以参考书籍 https://weread.qq.com/web/bookDetail/cc1326e05bcc52cc1669fc0 来获取架构演变相关的知识. 如果您因为特殊性的原因执意要单服务器支撑百万流量, 那么我很希望能学到您的优化策略
/inivte
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
/invite