notes icon indicating copy to clipboard operation
notes copied to clipboard

【基于 golang 的消息推送系统 gotify 的设计实现原理 】之上的一些想法

Open Owen-Zhang opened this issue 1 year ago • 0 comments

你提出的新想法中: type API struct { clients map[uint][]*client //我个人感觉这个还可以优化一些 lock sync.RWMutex pingPeriod time.Duration pongTimeout time.Duration upgrader *websocket.Upgrader } //个人想法 type API struct { clients map[uint]*userInfo lock sync.RWMutex pingPeriod time.Duration pongTimeout time.Duration upgrader *websocket.Upgrader }

type userInfo struct { userId uint clientLock sync.RWMutex allClients []*client //还可以保留一些其它信息 }

//这样的好处是 外层的锁只会做很少的事 //内层加锁是不影响到其他用户的,而且slice是有datarace问题的,不加锁会有问题

Owen-Zhang avatar Mar 31 '23 06:03 Owen-Zhang