优化,去除kafka中间件
This commit is contained in:
parent
27c7d38fba
commit
ce360714fe
@ -39,43 +39,6 @@ func BenchmarkClusterMsg(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkLog(b *testing.B) {
|
||||
runtime.GOMAXPROCS(2)
|
||||
t := game.G_getGameLogic()
|
||||
for i := 0; i < 10000; i++ {
|
||||
t.AddLog(&game.Log{
|
||||
EventName: "test_log",
|
||||
Param: map[string]interface{}{
|
||||
"test_key": "test_value",
|
||||
},
|
||||
})
|
||||
}
|
||||
t.MLogManager.Close()
|
||||
}
|
||||
|
||||
func BenchmarkLog2(b *testing.B) {
|
||||
// 准备耗时但不需要计入基准的初始化
|
||||
runtime.GOMAXPROCS(2)
|
||||
// 假设有个函数 NewGameLogicForBenchmark() 创建全新、独立的对象
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
// 每次迭代创建独立对象,避免副作用
|
||||
t := game.G_getGameLogic()
|
||||
b.StartTimer()
|
||||
// 被测操作:向日志管理器添加 1000 条日志
|
||||
for j := 0; j < 1000; j++ {
|
||||
t.AddLog(&game.Log{
|
||||
EventName: "test_log",
|
||||
Param: map[string]interface{}{
|
||||
"test_key": "test_value",
|
||||
},
|
||||
})
|
||||
}
|
||||
b.StopTimer()
|
||||
t.MLogManager.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func printMemUsage() {
|
||||
var m runtime.MemStats
|
||||
runtime.ReadMemStats(&m)
|
||||
|
||||
@ -77,7 +77,6 @@ type GameLogic struct {
|
||||
M_SvrGlobal db.SqlSvrGlobalStruct
|
||||
SeverInfo *ServerInfo
|
||||
|
||||
MLogManager *LogMgr // 日志管理器
|
||||
FriendMgr *FriendMgr // 好友管理器
|
||||
RankMgr *RankMgr // 排行榜管理器
|
||||
MailMgr *MailMgr // 邮件管理器
|
||||
@ -209,10 +208,6 @@ func (ad *GameLogic) NewAccountInsertDataToDB() bool {
|
||||
UpdataTime: int32(time.Now().Unix()),
|
||||
}
|
||||
db.FormatAllMemInsertDb(playerMod, "t_player_mod")
|
||||
G_GameLogicPtr.AddLog(&Log{
|
||||
Uid: insertId,
|
||||
EventName: "register",
|
||||
})
|
||||
// 创建玩家日志
|
||||
player := new(Player)
|
||||
BaseMod := player.PlayMod.getBaseMod()
|
||||
@ -469,7 +464,6 @@ func G_getGameLogic() *GameLogic {
|
||||
G_GameLogicPtr.RegisterNetWorkFunc() // 注册客户端接口
|
||||
G_GameLogicPtr.InitActivity() // 初始化活动
|
||||
G_GameLogicPtr.GetVersion() // 获取版本号
|
||||
G_GameLogicPtr.CreateLogManager() //加载日志管理器
|
||||
if conf.Server.ServerType == "center" {
|
||||
G_GameLogicPtr.CreateFriendMgr() //创建好友管理器
|
||||
G_GameLogicPtr.CreateChampshipMgr() // 创建竞标赛管理器
|
||||
@ -873,24 +867,10 @@ func (ad *GameLogic) RegisterNetWorkFunc() {
|
||||
RegisterMsgProcessFunc("ReqChargeReceive", ReqChargeReceive) // 礼包回复邮件
|
||||
}
|
||||
|
||||
func (ad *GameLogic) CreateLogManager() {
|
||||
ad.MLogManager = new(LogMgr)
|
||||
ad.MLogManager.InitManager()
|
||||
}
|
||||
|
||||
func (ad *GameLogic) InitActivity() {
|
||||
ad.m_CronEntryIDs = make(map[int]*LimitActPeriod)
|
||||
}
|
||||
|
||||
func (ad *GameLogic) AddLog(Log *Log) {
|
||||
Log.ServerId = conf.Server.ServerID
|
||||
Log.AppId = conf.Server.AppID
|
||||
Log.TimeStamp = time.Now().Unix()
|
||||
go func() {
|
||||
ad.MLogManager.AddLog(Log)
|
||||
}()
|
||||
}
|
||||
|
||||
func (ad *GameLogic) NotifyAll(m *MsgMod.Msg) {
|
||||
ad.M_Players.Range(func(k, v interface{}) bool {
|
||||
v.(*Player).Send(m)
|
||||
|
||||
@ -85,10 +85,6 @@ func (p *Player) Stop() {
|
||||
close(p.stopSignal)
|
||||
close(p.msgChan)
|
||||
}
|
||||
G_GameLogicPtr.AddLog(&Log{
|
||||
Uid: p.M_DwUin,
|
||||
EventName: "Login_Out",
|
||||
})
|
||||
p.McronSave.Stop()
|
||||
p.stop = true
|
||||
}
|
||||
@ -1056,11 +1052,6 @@ func (p *Player) AddLog(Uid int, Type int, Param string, Time int64) {
|
||||
}
|
||||
|
||||
func (p *Player) TeLog(Type string, Param map[string]interface{}) {
|
||||
G_GameLogicPtr.AddLog(&Log{
|
||||
Uid: p.M_DwUin,
|
||||
EventName: Type,
|
||||
Param: Param,
|
||||
})
|
||||
agent := p.GetAgent()
|
||||
if Param == nil {
|
||||
Param = make(map[string]interface{})
|
||||
@ -1078,11 +1069,7 @@ func (p *Player) TeLog(Type string, Param map[string]interface{}) {
|
||||
}
|
||||
|
||||
func (p *Player) Kafka(Type string, Param map[string]interface{}) {
|
||||
G_GameLogicPtr.AddLog(&Log{
|
||||
Uid: p.M_DwUin,
|
||||
EventName: Type,
|
||||
Param: Param,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// 初始化活动
|
||||
|
||||
@ -2,31 +2,12 @@ package kafkaMiddleware
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"server/conf"
|
||||
"server/pkg/github.com/name5566/leaf/log"
|
||||
|
||||
"github.com/segmentio/kafka-go"
|
||||
)
|
||||
|
||||
var KafkaMod *kafka.Writer
|
||||
|
||||
func init() {
|
||||
if conf.Server.GameName == "pet_home_local" {
|
||||
return
|
||||
}
|
||||
KafkaMod = newKafkaWriter(fmt.Sprintf("%s:%s", conf.Server.KafkaHost, conf.Server.KafkaPort), conf.Server.GameName)
|
||||
log.Debug("KafkaMod init")
|
||||
}
|
||||
|
||||
func newKafkaWriter(kafkaURL, topic string) *kafka.Writer {
|
||||
return &kafka.Writer{
|
||||
Addr: kafka.TCP(kafkaURL),
|
||||
Topic: topic,
|
||||
Balancer: &kafka.LeastBytes{},
|
||||
}
|
||||
}
|
||||
|
||||
func SendMsg(key, value []byte) error {
|
||||
if KafkaMod == nil {
|
||||
return nil
|
||||
|
||||
Loading…
Reference in New Issue
Block a user