优化 耗时测试
This commit is contained in:
parent
4a3ca9166e
commit
37fea2cb80
@ -101,7 +101,45 @@ func TimerStar() {
|
|||||||
//this.module.Debugf("=====%d,", time.Since(star).Milliseconds())
|
//this.module.Debugf("=====%d,", time.Since(star).Milliseconds())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 定义结构体
|
||||||
|
type sumy struct {
|
||||||
|
a int
|
||||||
|
b string
|
||||||
|
// 嵌入字段
|
||||||
|
float32
|
||||||
|
bool
|
||||||
|
next *sumy
|
||||||
|
}
|
||||||
|
|
||||||
func Test_Main(t *testing.T) {
|
func Test_Main(t *testing.T) {
|
||||||
|
|
||||||
|
// 值包装结构体
|
||||||
|
d := reflect.ValueOf(sumy{
|
||||||
|
next: &sumy{},
|
||||||
|
})
|
||||||
|
// 获取字段数量
|
||||||
|
fmt.Println("NumField", d.NumField())
|
||||||
|
// 获取索引为2的字段(float32字段)
|
||||||
|
floatField := d.Field(2)
|
||||||
|
// 输出字段类型
|
||||||
|
fmt.Println("Field", floatField.Type())
|
||||||
|
// 根据名字查找字段
|
||||||
|
fmt.Println("FieldByName(\"b\").Type", d.FieldByName("b").Type())
|
||||||
|
// 根据索引查找值中, next字段的int字段的值
|
||||||
|
fmt.Println("FieldByIndex([]int{4, 0}).Type()", d.FieldByIndex([]int{4, 0}).Type())
|
||||||
|
|
||||||
|
var a int = 1024
|
||||||
|
// 获取变量a的反射值对象
|
||||||
|
valueOfA := reflect.ValueOf(a)
|
||||||
|
|
||||||
|
fmt.Println(reflect.TypeOf(a), a)
|
||||||
|
typeofA := reflect.TypeOf(a).Elem().Kind()
|
||||||
|
// 获取interface{}类型的值, 通过类型断言转换
|
||||||
|
var getA int = valueOfA.Interface().(int)
|
||||||
|
// 获取64位的值, 强制类型转换为int类型
|
||||||
|
var getA2 int = int(valueOfA.Int())
|
||||||
|
fmt.Println(getA, getA2, typeofA)
|
||||||
|
|
||||||
cron.AddFunc("0 0 5 /* * ?", TimerStar) //每月第一天5点执行一次
|
cron.AddFunc("0 0 5 /* * ?", TimerStar) //每月第一天5点执行一次
|
||||||
sz := make([]string, 0)
|
sz := make([]string, 0)
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
|
@ -237,6 +237,8 @@ func (this *ModelHero) resetJuexingProperty(hero *pb.DBHero) {
|
|||||||
hero.JuexProperty[comm.Atk] += int32(math.Floor((float64(value) / 1000) * float64(hero.Property[comm.Atk])))
|
hero.JuexProperty[comm.Atk] += int32(math.Floor((float64(value) / 1000) * float64(hero.Property[comm.Atk])))
|
||||||
case comm.ResonanceDefPro:
|
case comm.ResonanceDefPro:
|
||||||
hero.JuexProperty[comm.Def] += int32(math.Floor((float64(value) / 1000) * float64(hero.Property[comm.Def])))
|
hero.JuexProperty[comm.Def] += int32(math.Floor((float64(value) / 1000) * float64(hero.Property[comm.Def])))
|
||||||
|
default:
|
||||||
|
this.moduleHero.Errorf("unkonw Resonance property:%s", key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -603,7 +605,9 @@ func (this *ModelHero) AddCardExp(session comm.IUserSession, hero *pb.DBHero, ex
|
|||||||
|
|
||||||
// 玩家离线 清除缓存
|
// 玩家离线 清除缓存
|
||||||
func (this *ModelHero) RemoveUserHeroInfo(session comm.IUserSession) (err error) {
|
func (this *ModelHero) RemoveUserHeroInfo(session comm.IUserSession) (err error) {
|
||||||
|
//star := configure.Now()
|
||||||
this.BatchDelLists(session.GetUserId())
|
this.BatchDelLists(session.GetUserId())
|
||||||
|
//this.moduleHero.Debugf("=====%d,", time.Since(star).Milliseconds())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +202,8 @@ func (this *ModuleBase) SendMsgToUsers(mainType, subType string, msg proto.Messa
|
|||||||
data, _ := anypb.New(msg)
|
data, _ := anypb.New(msg)
|
||||||
for k, v := range gateways {
|
for k, v := range gateways {
|
||||||
for k1, v1 := range v {
|
for k1, v1 := range v {
|
||||||
ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
|
|
||||||
|
ctx, _ := context.WithTimeout(context.Background(), time.Second*5) //
|
||||||
if _, err = this.service.AcrossClusterRpcGo(ctx, k, fmt.Sprintf("%s/%s", comm.Service_Gateway, k1), string(comm.Rpc_GatewaySendBatchMsg), &pb.BatchMessageReq{
|
if _, err = this.service.AcrossClusterRpcGo(ctx, k, fmt.Sprintf("%s/%s", comm.Service_Gateway, k1), string(comm.Rpc_GatewaySendBatchMsg), &pb.BatchMessageReq{
|
||||||
UserSessionIds: v1,
|
UserSessionIds: v1,
|
||||||
MainType: mainType,
|
MainType: mainType,
|
||||||
|
@ -20,6 +20,7 @@ const (
|
|||||||
///配置管理基础组件
|
///配置管理基础组件
|
||||||
type configureComp struct {
|
type configureComp struct {
|
||||||
modules.MCompConfigure
|
modules.MCompConfigure
|
||||||
|
module *Pagoda
|
||||||
hlock sync.RWMutex
|
hlock sync.RWMutex
|
||||||
_pagodaMap map[int64]*cfg.GamePagodaData
|
_pagodaMap map[int64]*cfg.GamePagodaData
|
||||||
_checkType map[int32][]*cfg.GamePassCheckData // key type
|
_checkType map[int32][]*cfg.GamePassCheckData // key type
|
||||||
@ -28,6 +29,7 @@ type configureComp struct {
|
|||||||
//组件初始化接口
|
//组件初始化接口
|
||||||
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||||
err = this.MCompConfigure.Init(service, module, comp, options)
|
err = this.MCompConfigure.Init(service, module, comp, options)
|
||||||
|
this.module = module.(*Pagoda)
|
||||||
err = this.LoadMultiConfigure(map[string]interface{}{
|
err = this.LoadMultiConfigure(map[string]interface{}{
|
||||||
//game_pagoda: cfg.NewGame_pagoda,
|
//game_pagoda: cfg.NewGame_pagoda,
|
||||||
game_pagodaseasonreward: cfg.NewGamePagodaSeasonReward,
|
game_pagodaseasonreward: cfg.NewGamePagodaSeasonReward,
|
||||||
@ -35,35 +37,9 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp
|
|||||||
})
|
})
|
||||||
|
|
||||||
this._pagodaMap = make(map[int64]*cfg.GamePagodaData, 0)
|
this._pagodaMap = make(map[int64]*cfg.GamePagodaData, 0)
|
||||||
configure.RegisterConfigure(game_pagoda, cfg.NewGamePagoda, func() {
|
configure.RegisterConfigure(game_pagoda, cfg.NewGamePagoda, this.LoadPagodaData)
|
||||||
if v, err := this.GetConfigure(game_pagoda); err == nil {
|
|
||||||
if configure, ok := v.(*cfg.GamePagoda); ok {
|
|
||||||
this.hlock.Lock()
|
|
||||||
defer this.hlock.Unlock()
|
|
||||||
for _, value := range configure.GetDataList() {
|
|
||||||
this._pagodaMap[int64(value.PagodaType<<16)+int64(value.LayerNum)] = value
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.Errorf("get game_pagoda conf err:%v", err)
|
|
||||||
return
|
|
||||||
})
|
|
||||||
this._checkType = make(map[int32][]*cfg.GamePassCheckData, 0)
|
this._checkType = make(map[int32][]*cfg.GamePassCheckData, 0)
|
||||||
configure.RegisterConfigure(game_passcheck, cfg.NewGamePassCheck, func() {
|
configure.RegisterConfigure(game_passcheck, cfg.NewGamePassCheck, this.LoadPassCheck)
|
||||||
if v, err := this.GetConfigure(game_passcheck); err == nil {
|
|
||||||
if configure, ok := v.(*cfg.GamePassCheck); ok {
|
|
||||||
this.hlock.Lock()
|
|
||||||
defer this.hlock.Unlock()
|
|
||||||
for _, value := range configure.GetDataList() {
|
|
||||||
this._checkType[value.PasscheckType] = append(this._checkType[value.PasscheckType], value)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.Errorf("get game_pagoda conf err:%v", err)
|
|
||||||
return
|
|
||||||
})
|
|
||||||
|
|
||||||
_data := this.GetPagodaSeasonReward()
|
_data := this.GetPagodaSeasonReward()
|
||||||
fmt.Printf("%v", _data)
|
fmt.Printf("%v", _data)
|
||||||
@ -96,22 +72,13 @@ func (this *configureComp) GetConfigure(name string) (v interface{}, err error)
|
|||||||
// 爬塔奖励
|
// 爬塔奖励
|
||||||
func (this *configureComp) GetPagodaRewardconfig(id int32) (data *cfg.GamePagodaTaskRewardData) {
|
func (this *configureComp) GetPagodaRewardconfig(id int32) (data *cfg.GamePagodaTaskRewardData) {
|
||||||
if v, err := this.GetConfigure(game_pagodataskreward); err == nil {
|
if v, err := this.GetConfigure(game_pagodataskreward); err == nil {
|
||||||
var (
|
if configure, ok := v.(*cfg.GamePagodaTaskReward); ok {
|
||||||
configure *cfg.GamePagodaTaskReward
|
return configure.Get(id)
|
||||||
ok bool
|
|
||||||
)
|
|
||||||
if configure, ok = v.(*cfg.GamePagodaTaskReward); !ok {
|
|
||||||
log.Errorf("%T no is *cfg.Game_pagodaData", v)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if data, ok = configure.GetDataMap()[id]; ok {
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Errorf("get game_pagodataskreward conf err:%v", err)
|
log.Errorf("get game_pagodataskreward conf err:%v", err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,6 +122,7 @@ func (this *configureComp) GetPassCheckPointByTtype(cType int32) string {
|
|||||||
return data[0].PayId
|
return data[0].PayId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.module.Errorf("can't find PassCheckPointByTtype err Type:%d", cType)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,15 +138,43 @@ func (this *configureComp) GetPassCheckByID(id int32) *cfg.GamePassCheckData {
|
|||||||
|
|
||||||
// 获取
|
// 获取
|
||||||
func (this *configureComp) GetPagodaSeasonReward() []*cfg.GamePagodaSeasonRewardData {
|
func (this *configureComp) GetPagodaSeasonReward() []*cfg.GamePagodaSeasonRewardData {
|
||||||
|
|
||||||
if v, err := this.GetConfigure(game_pagodaseasonreward); err == nil {
|
if v, err := this.GetConfigure(game_pagodaseasonreward); err == nil {
|
||||||
var (
|
if configure, ok := v.(*cfg.GamePagodaSeasonReward); ok {
|
||||||
configure *cfg.GamePagodaSeasonReward
|
|
||||||
ok bool
|
|
||||||
)
|
|
||||||
if configure, ok = v.(*cfg.GamePagodaSeasonReward); ok {
|
|
||||||
return configure.GetDataList()
|
return configure.GetDataList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *configureComp) LoadPagodaData() {
|
||||||
|
var err error
|
||||||
|
if v, err := this.GetConfigure(game_pagoda); err == nil {
|
||||||
|
if configure, ok := v.(*cfg.GamePagoda); ok {
|
||||||
|
this.hlock.Lock()
|
||||||
|
defer this.hlock.Unlock()
|
||||||
|
for _, value := range configure.GetDataList() {
|
||||||
|
this._pagodaMap[int64(value.PagodaType<<16)+int64(value.LayerNum)] = value
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Errorf("get game_pagoda conf err:%v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *configureComp) LoadPassCheck() {
|
||||||
|
var err error
|
||||||
|
if v, err := this.GetConfigure(game_passcheck); err == nil {
|
||||||
|
if configure, ok := v.(*cfg.GamePassCheck); ok {
|
||||||
|
this.hlock.Lock()
|
||||||
|
defer this.hlock.Unlock()
|
||||||
|
for _, value := range configure.GetDataList() {
|
||||||
|
this._checkType[value.PasscheckType] = append(this._checkType[value.PasscheckType], value)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Errorf("get game_pagoda conf err:%v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -259,51 +259,3 @@ func (this *configureComp) GetSmithyTask(taskId int32) (data *cfg.GameSmithyTask
|
|||||||
this.module.Errorf("GetSmithyTask notfound taskId:%d", taskId)
|
this.module.Errorf("GetSmithyTask notfound taskId:%d", taskId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (this *configureComp) GetSmithyDropData(dropId int32) (data []*cfg.GameSmithyDropData) {
|
|
||||||
// data = this._dropMap[dropId]
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func (this *configureComp) GetSmithyDropReward(dropId int32) (result []*cfg.Gameatn) {
|
|
||||||
// result = make([]*cfg.Gameatn, 0)
|
|
||||||
|
|
||||||
// data := this.GetSmithyDropData(dropId)
|
|
||||||
// if len(data) == 0 {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// szW := make([]int32, 0)
|
|
||||||
// for _, value := range data {
|
|
||||||
// szW = append(szW, value.P)
|
|
||||||
// }
|
|
||||||
// index := comm.GetRandW(szW)
|
|
||||||
// result = append(result, data[index].Prize...)
|
|
||||||
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func (this *configureComp) LoadSmithyDropData() {
|
|
||||||
|
|
||||||
// if v, err := this.GetConfigure(game_smithyDrop); err == nil {
|
|
||||||
// if configure, ok := v.(*cfg.GameSmithyDrop); ok {
|
|
||||||
// this.hlock.Lock()
|
|
||||||
// defer this.hlock.Unlock()
|
|
||||||
// for _, value := range configure.GetDataList() {
|
|
||||||
// if value.Condition == 0 {
|
|
||||||
// this._dropMap[value.Dropid] = append(this._dropMap[value.Dropid], value)
|
|
||||||
// } else {
|
|
||||||
// key := value.Condition
|
|
||||||
// key = value.Dropid*100 + key
|
|
||||||
// this._dropMap[key] = append(this._dropMap[key], value)
|
|
||||||
// for _, v1 := range this._dropMap[value.Dropid] {
|
|
||||||
// this._dropMap[key] = append(this._dropMap[key], v1)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// } else {
|
|
||||||
// log.Errorf("get game_pagoda conf err:%v", err)
|
|
||||||
// }
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
Loading…
Reference in New Issue
Block a user