obsidian/笔记文件/2.笔记/性能检测平台 临时记录_第二章.md
2025-05-23 17:04:49 +08:00

104 lines
2.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#灵感
确认一下 c_sharp内存接口是否正确
![[Pasted image 20250423151707.png]]
记录的创建时间,异常
![[Pasted image 20250423155344.png]]
需要按照时间,分表处理
![[Pasted image 20250423155528.png]]
ip没有采集
![[Pasted image 20250423161418.png]]
把Player的数据也一起放到性能表去统计因为同一个帐户有可能在不同设备登录
![[Pasted image 20250423161736.png]]
三消玩家登录
![[Pasted image 20250423162317.png]]
添加编辑器标识:
![[Pasted image 20250521103852.png]]
服务端,对应处理数据库相关的逻辑接口:`send2dbAndNotify`
![[Pasted image 20250521104258.png]]
这里是性能采集的,数据入口
``` go
r.POST("/collect", func(c *gin.Context)
```
![[Pasted image 20250521110041.png]]
断点调试可以看到PostForm这个数据结构是在Request里面的可以取到客户端发送过来的对应字段名称相关数据
![[Pasted image 20250521111118.png]]
有一个需求:例如后续,要添加某个字段的数据,线上运行的
数据库,也要在已有的数据库中,也添加该字段的数据,更新表结构,使用[[GORM]]的`AutoMigrate`接口即可;
如果是新表,直接使用,最新结构,创建表即可;
``` go
// 创建新表时自动使用最新结构
dbInfo.db.Table(tableName).Migrator().CreateTable(&FPSStat{})
```
数据库的结构体添加一下迁移标记map的布尔映射
![[Pasted image 20250521162238.png]]
初始化构建
![[Pasted image 20250521161801.png]]
表存在与否,判断处理即可:
这里的逻辑是重启服务才会判断一次是否要AutoMigrate
``` go
// 新增检查FPS表的方法
func checkCreateFpsTable(dbInfo *DbInfo, tableName string) {
// 首次检查表存在性
if !dbInfo.tableMap[tableName] {
dbInfo.tableMap[tableName] = true
if !dbInfo.db.Migrator().HasTable(tableName) {
// 创建新表时自动使用最新结构
dbInfo.db.Table(tableName).Migrator().CreateTable(&FPSStat{})
} else {
// 表已存在时,仅在服务启动后首次访问时迁移
if !dbInfo.migrated[tableName] {
dbInfo.db.Table(tableName).AutoMigrate(&FPSStat{})
dbInfo.migrated[tableName] = true
}
}
}
}
```
可以看到,数据过来,会更新一下表(只会是第一个有新数据的玩家过来,会触发)
![[Pasted image 20250521162638.png]]
表结构的更新,是需要比较多的时间,特别是大型表:
``` go
2025/05/21 11:51:50 C:/Users/admin/Downloads/code/git/lgcollecter/server/main.go:650 SLOW SQL >= 200ms
[574.640ms] [rows:0] ALTER TABLE `performance_2025-05-21` ADD `score` bigint
```
对玩家是无感知的:
![[Pasted image 20250521162842.png]]
![[Pasted image 20250521163027.png]]