跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[程序员] 求教,关于 im 中群组服务如何设计

发表于

群组信息应该持久化保存在 db 中,群组相关的操作在群组服务中进行写入和读取,通过 api 对群组进行操作(比如添加成员)那么将会采用一致性 hash 通过群组 id 找到对应的群组服务器中进行业务操作,那么群组信息写入后缓存的操作逻辑有两种:

1:对应请求后从 db 读取缓存在内存中加读写锁维护,进行写入时先写内存后写 db ,读只会读内存
2:纯粹作为缓存来读取,有写入时则删除缓存,后续请求需要再从 db 读取数据

第一种的问题是:如果群组集群有服务器 a 宕机,那么一个群组(id=xxx)就会被分配到新的服务器 b 上,当 b 服务器在写入时,a 服务器恢复上线就会造成 db 层数据不一致;或者是 b 服务器服务了一段时间后,a 重新上线,该群组又会回到 a 上处理,过了段时间又宕机,这时群组 xxx 又被分配到了 b 上,可 b 上的内存数据是旧数据 如果采用第一种感觉对 db 的操作会过于频繁,有什么更好的方案吗

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.