Skip to content

Commit

Permalink
更新readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jerbe committed Sep 11, 2023
1 parent 386bd33 commit 1d738d6
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
/bin/
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ JIM (Jerbe's Instant Messaging) is a lightweight chat system with the following
4) Because we need to manage chat messages, when sending a message, the message is first stored in the database and then subscribed and pushed after being successfully stored.
5) Supports getting the latest X messages from each room and traversing historical messages.

## Related Unit Tests
### Test Sending Chat Record Speed
```bash
Testing sending speed, 5750 concurrent executions in 10 seconds. Each operation took 2151984 nanoseconds, approximately 2.151984 milliseconds. It doesn't feel fast enough, and there are quite a few allocations. Further optimization is needed. Limited by the machine configuration, it's unclear how it would perform on a high-end configuration.

> /usr/local/opt/go/libexec/bin/go test -c -o /data/github.com/jerbe/jim/bin/handler_BenchmarkChatSendMessageParallel.test github.com/jerbe/jim/handler #gosetup
> /data/github.com/jerbe/jim/bin/handler_BenchmarkChatSendMessageParallel.test -test.v -test.paniconexit0 -test.bench ^\QBenchmarkChatSendMessageParallel\E$ -test.run ^$ -test.benchmem -test.benchtime=10s
> goos: darwin
> goarch: amd64
> pkg: github.com/jerbe/jim/handler
> cpu: Intel(R) Core(TM) i5-4308U CPU @ 2.80GHz
> BenchmarkChatSendMessageParallel-4 5750 2151984 ns/op 469167 B/op 3090 allocs/op
```

## Design Diagrams


Expand Down Expand Up @@ -73,6 +87,7 @@ Here are the planned features:
- [x] Cannot log in if disabled
- [x] Cannot log in if deleted
- [ ] User Logout
- [ ] Recover Account
- [x] Account Information
- [ ] Password modification
- [ ] Avatar modification
Expand Down Expand Up @@ -126,7 +141,8 @@ Here are the planned features:
- [ ] Voice chat
- [ ] Video chat
- [ ] Mark messages as read
- [x] Cannot chat if blocked by a friend
- [ ] Retract Chat Content
- [x] Cannot chat if blocked by a friend
- [x] Cannot chat if deleted by a friend
- [x] Group Chat
- [x] Send plain text
Expand All @@ -138,6 +154,7 @@ Here are the planned features:
- [ ] Send location
- [ ] Voice chat
- [ ] Mark messages as read
- [ ] Retract Chat Content
- [x] Mute all
- [x] Mute specific group members
- [x] World Channel Chat
Expand Down
18 changes: 18 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ JIM(Jerbe's Instant Messaging) 是一个轻量的聊天系统,
3)在多服务实例的情况下,由于用户建立WS链接的服务器是随机的,所以我们在每个服务实例里使用`websocket.manager`包的管理器进行链接统一管理,订阅到的数据最终也有管理器进行分发到不同的用户链接上。
4)因为我们需要管理聊天消息,所以发消息时,消息是先入库,成功后再进行订阅推送。
5)支持获取每个房间的最近X条消息,及历史消息遍历。

## 相关单测
### 测试发送聊天记录速度
```bash
测试发送速度,10s执行了5750个并发,每个op耗时2151984纳秒,约等于2.151984毫秒感觉不够快,allocs还挺多的,得继续优化.受限于机器配置,不知道高配置怎么样

> /usr/local/opt/go/libexec/bin/go test -c -o /data/github.com/jerbe/jim/bin/handler_BenchmarkChatSendMessageParallel.test github.com/jerbe/jim/handler #gosetup
> /data/github.com/jerbe/jim/bin/handler_BenchmarkChatSendMessageParallel.test -test.v -test.paniconexit0 -test.bench ^\QBenchmarkChatSendMessageParallel\E$ -test.run ^$ -test.benchmem -test.benchtime=10s
> goos: darwin
> goarch: amd64
> pkg: github.com/jerbe/jim/handler
> cpu: Intel(R) Core(TM) i5-4308U CPU @ 2.80GHz
> BenchmarkChatSendMessageParallel-4 5750 2151984 ns/op 469167 B/op 3090 allocs/op
```

## 设计图纸

##### 消息发送基本架构图
Expand Down Expand Up @@ -65,6 +80,7 @@ JIM(Jerbe's Instant Messaging) 是一个轻量的聊天系统,
- [x] 被禁用无法登录
- [x] 被删除无法登录
- [ ] 用户登出
- [ ] 找回账户
- [x] 账户信息
- [ ] 密码修改
- [ ] 头型修改
Expand Down Expand Up @@ -118,6 +134,7 @@ JIM(Jerbe's Instant Messaging) 是一个轻量的聊天系统,
- [ ] 语音聊天
- [ ] 视频聊天
- [ ] 私聊消息已读
- [ ] 撤回聊天内容
- [x] 被好友拉黑无法对话
- [x] 被好友删除无法对话
- [x] 群聊
Expand All @@ -130,6 +147,7 @@ JIM(Jerbe's Instant Messaging) 是一个轻量的聊天系统,
- [ ] 语音聊天
- [ ] 视频聊天
- [ ] 消息已读
- [ ] 撤回聊天内容
- [x] 全体禁言
- [x] 某群成员禁言
- [x] 世界频道聊天
Expand Down
1 change: 1 addition & 0 deletions before.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#bin/bash
# mkdir ./bin
echo "删除已编译文件"
rm -rf ./*\.log
rm -rf ./bin/*

echo "复制配置文件"
Expand Down
9 changes: 5 additions & 4 deletions handler/chat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func BenchmarkChatSendMessageUseApi(b *testing.B) {
//r := gin.New()
jsonData := `{
"action_id":"随机字符串",
"receiver_id":2,
"target_id":2,
"session_type":1,
"type":1,
"body":{"text":"test"}
Expand Down Expand Up @@ -196,7 +196,7 @@ func BenchmarkChatSendMessage(b *testing.B) {
r := gin.New()
jsonData := `{
"action_id":"随机字符串",
"receiver_id":"2",
"target_id":"2",
"session_type":1,
"type":1,
"body":{"text":"test"}
Expand Down Expand Up @@ -259,7 +259,7 @@ func BenchmarkChatSendMessageParallel(b *testing.B) {
r := gin.New()
jsonData := `{
"action_id":"随机字符串",
"receiver_id":2,
"target_id":2,
"session_type":1,
"type":1,
"body":{"text":"test"}
Expand Down Expand Up @@ -307,6 +307,7 @@ func BenchmarkChatSendMessageParallel(b *testing.B) {
CheckAuthMiddleware()(ctx)
SendChatMessageHandler(ctx)

b.StopTimer()
go func(writer io.Writer, reader io.ReadCloser) {
defer reader.Close()
_, err = io.Copy(writer, reader)
Expand All @@ -319,7 +320,7 @@ func BenchmarkChatSendMessageParallel(b *testing.B) {
log.Println("134", err)
}
}(file, w.Result().Body)

b.StartTimer()
}
})

Expand Down
16 changes: 9 additions & 7 deletions handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"github.com/jerbe/jcache"
"github.com/jerbe/jim/config"
"github.com/jerbe/jim/database"
"github.com/jerbe/jim/log"
"github.com/jerbe/jim/pubsub"
"log"
"testing"
)

Expand All @@ -16,23 +16,25 @@ import (
*/

func TestMain(t *testing.M) {
log.Info().Msg("服务初始化中...")
defer log.Warn().Msg("服务已关闭")
log.Println("服务初始化中...")
defer log.Println("服务已关闭...")

// 加载配置
log.Println("加载配置中...")
cfg, err := config.Init()
if err != nil {
log.Fatal().Err(err).Msg("加载配置文件失败")
log.Println("加载配置文件失败")
}

log.Println("配置推收模块('pubsub')...")
err = pubsub.Init(cfg)
if err != nil {
log.Fatal().Err(err).Msg("初始化推收模块('pubsub')失败")
log.Fatalln("初始化推收模块('pubsub')失败")
}

// 配置数据库
if _, err = database.Init(cfg); err != nil {
log.Fatal().Err(err).Msg("初始化数据模块('database')失败")
log.Fatalln("初始化数据模块('database')失败")
}

jcacheCfg := jcache.Config{
Expand All @@ -47,7 +49,7 @@ func TestMain(t *testing.M) {
}
err = jcache.Init(&jcacheCfg)
if err != nil {
log.Fatal().Err(err).Msg("初始化缓存模块('cache')失败")
log.Fatalln("初始化缓存模块('cache')失败")
}
t.Run()
}
2 changes: 1 addition & 1 deletion pubsub/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var chatMessagePool = &sync.Pool{

var chatMessageBodyPool = &sync.Pool{
New: func() any {
return new(*ChatMessageBody)
return new(ChatMessageBody)
},
}

Expand Down

0 comments on commit 1d738d6

Please sign in to comment.