Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Owen-Zhang opened this issue Mar 31, 2023 · 0 comments

Comments

@Owen-Zhang
Copy link

你提出的新想法中:
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问题的,不加锁会有问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant