修复时间轮系统bug
This commit is contained in:
parent
223289de32
commit
68e3b4360c
@ -7,7 +7,7 @@ import (
|
|||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
//启动服务
|
// 启动服务
|
||||||
func Run(service core.IService, mod ...core.IModule) {
|
func Run(service core.IService, mod ...core.IModule) {
|
||||||
cpuNum := runtime.NumCPU() //获得当前设备的cpu核心数
|
cpuNum := runtime.NumCPU() //获得当前设备的cpu核心数
|
||||||
runtime.GOMAXPROCS(cpuNum) //设置需要用到的cpu数量
|
runtime.GOMAXPROCS(cpuNum) //设置需要用到的cpu数量
|
||||||
@ -27,7 +27,7 @@ func Run(service core.IService, mod ...core.IModule) {
|
|||||||
log.Infof("服务【%s】关闭成功", service.GetId())
|
log.Infof("服务【%s】关闭成功", service.GetId())
|
||||||
}
|
}
|
||||||
|
|
||||||
//错误采集
|
// 错误采集
|
||||||
func Recover(tag string) {
|
func Recover(tag string) {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
buf := make([]byte, 1024)
|
buf := make([]byte, 1024)
|
||||||
|
@ -2,8 +2,8 @@ package timewheel
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"go_dreamfactory/lego"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
"runtime"
|
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
@ -88,7 +88,7 @@ func (t *Task) Reset() {
|
|||||||
t.circle = false
|
t.circle = false
|
||||||
}
|
}
|
||||||
|
|
||||||
//启动时间轮
|
// 启动时间轮
|
||||||
func (this *TimeWheel) Start() {
|
func (this *TimeWheel) Start() {
|
||||||
// onlye once start
|
// onlye once start
|
||||||
this.onceStart.Do(
|
this.onceStart.Do(
|
||||||
@ -114,12 +114,12 @@ func (this *TimeWheel) Remove(task *Task) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//停止时间轮
|
// 停止时间轮
|
||||||
func (this *TimeWheel) Stop() {
|
func (this *TimeWheel) Stop() {
|
||||||
this.stopC <- struct{}{}
|
this.stopC <- struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
//此处写法 为监控时间轮是否正常执行
|
// 此处写法 为监控时间轮是否正常执行
|
||||||
func (this *TimeWheel) tickGenerator() {
|
func (this *TimeWheel) tickGenerator() {
|
||||||
if this.tickQueue == nil {
|
if this.tickQueue == nil {
|
||||||
return
|
return
|
||||||
@ -137,7 +137,7 @@ func (this *TimeWheel) tickGenerator() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//调度器
|
// 调度器
|
||||||
func (this *TimeWheel) schduler() {
|
func (this *TimeWheel) schduler() {
|
||||||
queue := this.ticker.C
|
queue := this.ticker.C
|
||||||
if this.tickQueue != nil {
|
if this.tickQueue != nil {
|
||||||
@ -160,7 +160,7 @@ func (this *TimeWheel) schduler() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//清理
|
// 清理
|
||||||
func (this *TimeWheel) collectTask(task *Task) {
|
func (this *TimeWheel) collectTask(task *Task) {
|
||||||
index := this.bucketIndexes[task.id]
|
index := this.bucketIndexes[task.id]
|
||||||
delete(this.bucketIndexes, task.id)
|
delete(this.bucketIndexes, task.id)
|
||||||
@ -185,8 +185,9 @@ func (this *TimeWheel) handleTick() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if task.async {
|
if task.async {
|
||||||
go func(task *Task) {
|
go func(_task *Task) {
|
||||||
go this.calltask(task, task.args...)
|
this.calltask(_task, _task.args...)
|
||||||
|
this.collectTask(task)
|
||||||
}(task)
|
}(task)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -200,9 +201,9 @@ func (this *TimeWheel) handleTick() {
|
|||||||
this.putCircle(task, modeIsCircle)
|
this.putCircle(task, modeIsCircle)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if !task.async { //异步模式下不能清理
|
||||||
// gc
|
this.collectTask(task)
|
||||||
this.collectTask(task)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if this.currentIndex == this.bucketsNum-1 {
|
if this.currentIndex == this.bucketsNum-1 {
|
||||||
@ -213,15 +214,13 @@ func (this *TimeWheel) handleTick() {
|
|||||||
this.currentIndex++
|
this.currentIndex++
|
||||||
}
|
}
|
||||||
|
|
||||||
//执行时间轮事件 捕捉异常错误 防止程序崩溃
|
// 执行时间轮事件 捕捉异常错误 防止程序崩溃
|
||||||
func (this *TimeWheel) calltask(task *Task, args ...interface{}) {
|
func (this *TimeWheel) calltask(task *Task, args ...interface{}) {
|
||||||
defer func() { //程序异常 收集异常信息传递给前端显示
|
defer lego.Recover("TimeWheel")
|
||||||
if r := recover(); r != nil {
|
if task.callback == nil {
|
||||||
buf := make([]byte, 4096)
|
log.Error("sys.timeWheel task callback err!", log.Field{Key: "task", Value: task})
|
||||||
l := runtime.Stack(buf, false)
|
return
|
||||||
log.Errorf("timewheel err:%s", string(buf[0:l]))
|
}
|
||||||
}
|
|
||||||
}()
|
|
||||||
task.callback(task, task.args...)
|
task.callback(task, task.args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ func (this *apiComp) Agree(session comm.IUserSession, req *pb.FriendAgreeReq) (e
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
event.TriggerEvent(comm.EventFriendChange, uid, len(self.FriendIds))
|
event.TriggerEvent(comm.EventFriendChange, uid, int32(len(self.FriendIds)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拥有xx个好友
|
// 拥有xx个好友
|
||||||
|
@ -412,6 +412,8 @@ const (
|
|||||||
ErrorCode_PassonHeroNumNotEnough ErrorCode = 4701 //英雄数量不足
|
ErrorCode_PassonHeroNumNotEnough ErrorCode = 4701 //英雄数量不足
|
||||||
ErrorCode_PassonHeroUnavailable ErrorCode = 4702 //当前英雄不可用
|
ErrorCode_PassonHeroUnavailable ErrorCode = 4702 //当前英雄不可用
|
||||||
ErrorCode_PassonSeatStateErr ErrorCode = 4703 //传功塔状态错误
|
ErrorCode_PassonSeatStateErr ErrorCode = 4703 //传功塔状态错误
|
||||||
|
//战令
|
||||||
|
ErrorCode_WarorderNoOpen ErrorCode = 4801 //活动未开启
|
||||||
)
|
)
|
||||||
|
|
||||||
// Enum value maps for ErrorCode.
|
// Enum value maps for ErrorCode.
|
||||||
@ -766,6 +768,7 @@ var (
|
|||||||
4701: "PassonHeroNumNotEnough",
|
4701: "PassonHeroNumNotEnough",
|
||||||
4702: "PassonHeroUnavailable",
|
4702: "PassonHeroUnavailable",
|
||||||
4703: "PassonSeatStateErr",
|
4703: "PassonSeatStateErr",
|
||||||
|
4801: "WarorderNoOpen",
|
||||||
}
|
}
|
||||||
ErrorCode_value = map[string]int32{
|
ErrorCode_value = map[string]int32{
|
||||||
"Success": 0,
|
"Success": 0,
|
||||||
@ -1117,6 +1120,7 @@ var (
|
|||||||
"PassonHeroNumNotEnough": 4701,
|
"PassonHeroNumNotEnough": 4701,
|
||||||
"PassonHeroUnavailable": 4702,
|
"PassonHeroUnavailable": 4702,
|
||||||
"PassonSeatStateErr": 4703,
|
"PassonSeatStateErr": 4703,
|
||||||
|
"WarorderNoOpen": 4801,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1151,7 +1155,7 @@ var File_errorcode_proto protoreflect.FileDescriptor
|
|||||||
|
|
||||||
var file_errorcode_proto_rawDesc = []byte{
|
var file_errorcode_proto_rawDesc = []byte{
|
||||||
0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74,
|
0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74,
|
||||||
0x6f, 0x2a, 0xa3, 0x40, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12,
|
0x6f, 0x2a, 0xb8, 0x40, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12,
|
||||||
0x0b, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10,
|
0x0b, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10,
|
||||||
0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x45, 0x78, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6f, 0x6e,
|
0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x45, 0x78, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6f, 0x6e,
|
||||||
0x10, 0x01, 0x12, 0x11, 0x0a, 0x0d, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76,
|
0x10, 0x01, 0x12, 0x11, 0x0a, 0x0d, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76,
|
||||||
@ -1665,8 +1669,9 @@ var file_errorcode_proto_rawDesc = []byte{
|
|||||||
0xdd, 0x24, 0x12, 0x1a, 0x0a, 0x15, 0x50, 0x61, 0x73, 0x73, 0x6f, 0x6e, 0x48, 0x65, 0x72, 0x6f,
|
0xdd, 0x24, 0x12, 0x1a, 0x0a, 0x15, 0x50, 0x61, 0x73, 0x73, 0x6f, 0x6e, 0x48, 0x65, 0x72, 0x6f,
|
||||||
0x55, 0x6e, 0x61, 0x76, 0x61, 0x69, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x10, 0xde, 0x24, 0x12, 0x17,
|
0x55, 0x6e, 0x61, 0x76, 0x61, 0x69, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x10, 0xde, 0x24, 0x12, 0x17,
|
||||||
0x0a, 0x12, 0x50, 0x61, 0x73, 0x73, 0x6f, 0x6e, 0x53, 0x65, 0x61, 0x74, 0x53, 0x74, 0x61, 0x74,
|
0x0a, 0x12, 0x50, 0x61, 0x73, 0x73, 0x6f, 0x6e, 0x53, 0x65, 0x61, 0x74, 0x53, 0x74, 0x61, 0x74,
|
||||||
0x65, 0x45, 0x72, 0x72, 0x10, 0xdf, 0x24, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62,
|
0x65, 0x45, 0x72, 0x72, 0x10, 0xdf, 0x24, 0x12, 0x13, 0x0a, 0x0e, 0x57, 0x61, 0x72, 0x6f, 0x72,
|
||||||
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
0x64, 0x65, 0x72, 0x4e, 0x6f, 0x4f, 0x70, 0x65, 0x6e, 0x10, 0xc1, 0x25, 0x42, 0x06, 0x5a, 0x04,
|
||||||
|
0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
Loading…
Reference in New Issue
Block a user