另外一张地图可以轻松处理一百万条记录。



如果您真的想担心未来扩展,请弄清楚如何让您的应用程序的两个实例在负载上一起工作。然后将其增加到N个实例。


I wrote a web chat app, using websockets. It uses one connection per page to push new messages to online users.

websocket.Conn
onlineUser = map[int] *websocket.Conn

I am very worried about the map when 1,000,000 pages are open.

websocket.Conn

Erlang's inner database can be used to store an erlang socket.

websocket.Conn

1,000,000 concurrent users is a nice problem to have. :)

Your primary problem is that the websocket spec requires the connection to be maintained open. This means that you can't serialize and cache them.

However, if you could GOB encode them, and every user sent one message a second (unrealistically high IMO) a million GOB decodes per second isn't going to dominate your load.

Also a map can easily handle a million entries.

If you really want to worry about future scaling, figure out how to get two instances of your application to work together on the load. Then increase that to N instances.

这篇关于在golang中存储websocket连接的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!