Exemple #1
0
// Pub 执行Publish操作
func Pub(cfg *Config) {
	pub := &Publish{
		cfg:                cfg,
		lg:                 alog.NewALog(),
		lgData:             alog.NewALog(),
		groupData:          make(map[string]int),
		clients:            cmap.NewConcurrencyMap(),
		execComplete:       make(chan bool, 1),
		end:                make(chan bool, 1),
		startTime:          time.Now(),
		sendPacketStore:    bucket.NewBucketGroup(cfg.SendPacketStoreNum, cfg.SendPacketBucketNum),
		receivePacketStore: bucket.NewBucketGroup(cfg.ReceivePacketStoreNum, cfg.ReceivePacketBucketNum),
	}
	pub.lg.SetLogTag("PUBLISH")
	pub.lgData.SetLogTag("PUBLISH_DATA")
	session, err := mgo.Dial(cfg.MongoUrl)
	if err != nil {
		pub.lg.Errorf("数据库连接发生异常:%s", err.Error())
		return
	}
	pub.session = session
	err = pub.Init()
	if err != nil {
		pub.lg.Error(err)
		return
	}
	pub.ExecPublish()
	<-pub.end
	pub.handleEnd()
}
Exemple #2
0
// Gen 生成群组及组成员操作
func Gen(cfg Config) {
	gen := &Generate{
		cfg:            cfg,
		lg:             alog.NewALog(),
		groupWeight:    make(map[int]string),
		groupClientNum: make(map[string]int),
	}
	gen.lg.SetLogTag("GENERATE")
	session, err := mgo.Dial(cfg.MongoUrl)
	if err != nil {
		gen.lg.ErrorC("连接数据库出现异常:", err)
		return
	}
	gen.session = session
	gen.database = session.DB(config.Database)
	err = gen.GenGroup()
	if err != nil {
		gen.lg.ErrorC("生成群组出现异常:", err)
		return
	}
	err = gen.GenUser()
	if err != nil {
		gen.lg.ErrorC("生成组成员出现异常:", err)
		return
	}
	gen.lg.InfoC("群组及组成员生成完成")
}
Exemple #3
0
func Clear(cfg Config) {
	clr := &clear{
		lg: alog.NewALog(),
	}
	clr.lg.SetLogTag("CLEAR")
	session, err := mgo.Dial(cfg.MongoUrl)
	if err != nil {
		clr.lg.ErrorC("连接数据库出现异常:", err)
		return
	}
	clr.session = session
	clr.database = session.DB(config.DataBase)
	if cfg.Gen {
		err = clr.clearClients()
		if err != nil {
			clr.lg.ErrorC("清除客户端数据出现异常:", err)
			return
		}
	}
	if cfg.Pub {
		err = clr.clearPacket()
		if err != nil {
			clr.lg.ErrorC("清除包数据出现异常:", err)
			return
		}
	}
	clr.lg.InfoC("数据清除完成")
}
Exemple #4
0
// Pub 执行Publish操作
func Pub(cfg *Config) {
	pub := &Publish{
		cfg:             cfg,
		lg:              alog.NewALog(),
		clientIndexData: make(map[string]int),
		clients:         cmap.NewConcurrencyMap(),
		execComplete:    make(chan bool, 1),
		end:             make(chan bool, 1),
		startTime:       time.Now(),
	}
	pub.lg.SetLogTag("PUBLISH")
	session, err := mgo.Dial(cfg.MongoUrl)
	if err != nil {
		pub.lg.Errorf("数据库连接发生异常:%s", err.Error())
		return
	}
	pub.session = session
	pub.database = session.DB(config.DataBase)
	err = pub.Init()
	if err != nil {
		pub.lg.Error(err)
		return
	}
	pub.ExecPublish()
	<-pub.end
	pub.lg.Info("执行完成.")
	time.Sleep(time.Second * 2)
	os.Exit(0)
}
Exemple #5
0
// Gen 生成客户端数据
func Gen(cfg Config) {
	gen := &Generate{
		cfg:              cfg,
		lg:               alog.NewALog(),
		clientData:       make([]*config.ClientInfo, cfg.ClientNum),
		weightClientData: make(map[int][]string),
	}
	gen.lg.SetLogTag("GENERATE")
	session, err := mgo.Dial(cfg.MongoURL)
	if err != nil {
		gen.lg.Error("连接数据库出现异常:", err)
		return
	}
	gen.session = session
	gen.database = session.DB(config.DataBase)
	gen.InitClientData()
	err = gen.Store()
	if err != nil {
		gen.lg.Error("存储客户端发生错误:", err)
		return
	}
}
Exemple #6
0
// ExecCollect 执行汇总
func ExecCollect(cfg Config) {
	clt := &Collect{
		cfg:                cfg,
		lg:                 alog.NewALog(),
		chCollectPacket:    make(chan config.CollectPacket, 1),
		groupData:          make(map[string]int),
		collectPacketStore: bucket.NewBucketGroup(200, 100),
	}
	clt.lg.SetLogTag("COLLECT")
	session, err := mgo.Dial(clt.cfg.MongoUrl)
	if err != nil {
		clt.lg.Errorf("数据库连接发生异常:%s", err.Error())
		return
	}
	clt.session = session
	err = clt.Remove()
	if err != nil {
		clt.lg.Errorf("清除数据发生异常:%v", err)
		return
	}
	err = clt.Init()
	if err != nil {
		clt.lg.Errorf("数据初始化发生异常:%v", err)
		return
	}
	err = clt.StartCollect()
	if err != nil {
		clt.lg.Errorf("执行数据汇总发生异常:%v", err)
		return
	}
	err = clt.Statistics()
	if err != nil {
		clt.lg.Errorf("执行结果统计时发生异常:%v", err)
		return
	}
	clt.lg.Info("执行完成.")
}
Exemple #7
0
package taskpool

import (
	"github.com/antlinker/alog"
)

const (
	logTag = "TASKPOOL"
)

// Tlog 日志模块
var Tlog = alog.NewALog()

func init() {
	Tlog.SetLogTag(logTag)
	Tlog.SetEnabled(false)
}

// TlogInit 日志初始化
func TlogInit(configs string) {
	Tlog.ReloadConfig(configs)

	Tlog.SetLogTag(logTag)
}