修改了参数,尽可能吃满共享内存

This commit is contained in:
Pan Qiancheng 2025-04-24 18:18:12 +08:00
parent 88e62a7962
commit 628e170473
2 changed files with 36 additions and 6 deletions

View File

@ -71,3 +71,33 @@ func (r *Rule) ToJSONRule() JSONRule {
Args: args,
}
}
// func init() {
// // 计算一个Rule结构体的大小
// ruleSize := int(unsafe.Sizeof(Rule{}))
// // 计算ConfigData结构体的总大小
// configSize := int(unsafe.Sizeof(ConfigData{}))
// // 转换为MB的函数
// toMB := func(bytes int) float64 {
// return float64(bytes) / 1024 / 1024
// }
// // 验证共享内存大小是否足够
// if configSize > constants.ShmSize {
// panic(fmt.Sprintf("Shared memory size is too small to hold ConfigData structure. "+
// "Required size: %d bytes (%.2f MB), "+
// "Current size: %d bytes (%.2f MB)",
// configSize, toMB(configSize),
// constants.ShmSize, toMB(constants.ShmSize)))
// }
// // 打印详细信息便于调试
// log.Printf("Memory allocation details:")
// log.Printf("- Single Rule size: %d bytes (%.2f MB)", ruleSize, toMB(ruleSize))
// log.Printf("- Total ConfigData size: %d bytes (%.2f MB)", configSize, toMB(configSize))
// log.Printf("- Shared memory size: %d bytes (%.2f MB)", constants.ShmSize, toMB(constants.ShmSize))
// log.Printf("- Available space: %d bytes (%.2f MB)",
// constants.ShmSize-configSize, toMB(constants.ShmSize-configSize))
// }

View File

@ -1,12 +1,12 @@
package constants
const (
MaxRules = 256 // 最大规则数量
MaxArgs = 64 // 每条规则的最大参数数量
MaxRuleCmdLength = 256 // 规则命令的最大长度
MaxRuleTypeLength = 32 // 规则类型的最大长度
MaxRuleMsgLength = 256 // 规则消息的最大长度
MaxArgLength = 128 // 单个参数的最大长度
MaxRules = 512 + 64 + 32 // 最大规则数量(尽可能把空间占用完)
MaxArgs = 128 // 每条规则的最大参数数量
MaxRuleCmdLength = 256 // 规则命令的最大长度(可执行文件路径受到ext4限制为255)
MaxRuleTypeLength = 32 // 规则类型的最大长度warnerrorinfo
MaxRuleMsgLength = 4096 // 规则消息的最大长度(可以很复杂的内容,长一点)
MaxArgLength = 256 + 128 // 单个参数的最大长度最大可能就是255的文件路径加上前缀
ShmKey = 0x78945 // 共享内存的键值
ShmSize = 32 * 1024 * 1024 // 共享内存的大小(字节)