func main() { var err error // Parse cmd-line arguments flag.Parse() log.Info("web ver: \"%s\" start", ver.Version) if err = InitConfig(); err != nil { panic(err) } // Set max routine runtime.GOMAXPROCS(Conf.MaxProc) // init log log.LoadConfiguration(Conf.Log) defer log.Close() // init zookeeper zkConn, err := InitZK() if err != nil { if zkConn != nil { zkConn.Close() } panic(err) } // start pprof http perf.Init(Conf.PprofBind) // start http listen. StartHTTP() // process init if err = process.Init(Conf.User, Conf.Dir, Conf.PidFile); err != nil { panic(err) } // init signals, block wait signals signalCH := InitSignal() HandleSignal(signalCH) log.Info("web stop") }
func (c *Client) Must(result *Result, err *AppError) *Result { if err != nil { l4g.Close() time.Sleep(time.Second) panic(err) } return result }
// MustGeneric is a convenience function used for testing. func (c *Client) MustGeneric(result interface{}, err *AppError) interface{} { if err != nil { l4g.Close() time.Sleep(time.Second) panic(err) } return result }
func Must(sc StoreChannel) interface{} { r := <-sc if r.Err != nil { l4g.Close() time.Sleep(time.Second) panic(r.Err) } return r.Data }
func UpdateUserToTeamAdmin(user *model.User, team *model.Team) { utils.DisableDebugLogForTest() tm := &model.TeamMember{TeamId: team.Id, UserId: user.Id, Roles: model.ROLE_TEAM_ADMIN} if tmr := <-Srv.Store.Team().UpdateMember(tm); tmr.Err != nil { l4g.Error(tmr.Err.Error()) l4g.Close() time.Sleep(time.Second) panic(tmr.Err) } }
func LinkUserToTeam(user *model.User, team *model.Team) { utils.DisableDebugLogForTest() err := JoinUserToTeam(team, user) if err != nil { l4g.Error(err.Error()) l4g.Close() time.Sleep(time.Second) panic(err) } utils.EnableDebugLogForTest() }
func main() { // parse cmd-line arguments flag.Parse() log.Info("comet ver: \"%s\" start", ver.Version) // init config if err := InitConfig(); err != nil { panic(err) } // set max routine runtime.GOMAXPROCS(Conf.MaxProc) // init log log.LoadConfiguration(Conf.Log) defer log.Close() // start pprof perf.Init(Conf.PprofBind) // create channel // if process exit, close channel UserChannel = NewChannelList() defer UserChannel.Close() // start stats StartStats() // start rpc if err := StartRPC(); err != nil { panic(err) } // start comet if err := StartComet(); err != nil { panic(err) } // init zookeeper zkConn, err := InitZK() if err != nil { if zkConn != nil { zkConn.Close() } panic(err) } // process init if err = process.Init(Conf.User, Conf.Dir, Conf.PidFile); err != nil { panic(err) } // init signals, block wait signals signalCH := InitSignal() HandleSignal(signalCH) // exit log.Info("comet stop") }
func configureLog(s *model.LogSettings) { l4g.Close() if s.EnableConsole { level := l4g.DEBUG if s.ConsoleLevel == "INFO" { level = l4g.INFO } else if s.ConsoleLevel == "WARN" { level = l4g.WARNING } else if s.ConsoleLevel == "ERROR" { level = l4g.ERROR } lw := l4g.NewConsoleLogWriter() lw.SetFormat("[%D %T] [%L] %M") l4g.AddFilter("stdout", level, lw) } if s.EnableFile { var fileFormat = s.FileFormat if fileFormat == "" { fileFormat = "[%D %T] [%L] %M" } level := l4g.DEBUG if s.FileLevel == "INFO" { level = l4g.INFO } else if s.FileLevel == "WARN" { level = l4g.WARNING } else if s.FileLevel == "ERROR" { level = l4g.ERROR } flw := l4g.NewFileLogWriter(GetLogFileLocation(s.FileLocation), false) flw.SetFormat(fileFormat) flw.SetRotate(true) flw.SetRotateLines(LOG_ROTATE_SIZE) l4g.AddFilter("file", level, flw) } }
func (me *TestHelper) CreateTeam() *model.Team { id := model.NewId() team := &model.Team{ DisplayName: "dn_" + id, Name: "name" + id, Email: "success+" + id + "@simulator.amazonses.com", Type: model.TEAM_OPEN, } utils.DisableDebugLogForTest() var err *model.AppError if team, err = CreateTeam(team); err != nil { l4g.Error(err.Error()) l4g.Close() time.Sleep(time.Second) panic(err) } utils.EnableDebugLogForTest() return team }
func (me *TestHelper) CreatePost(channel *model.Channel) *model.Post { id := model.NewId() post := &model.Post{ UserId: me.BasicUser.Id, ChannelId: channel.Id, Message: "message_" + id, } utils.DisableDebugLogForTest() var err *model.AppError if post, err = CreatePost(post, channel.TeamId, false); err != nil { l4g.Error(err.Error()) l4g.Close() time.Sleep(time.Second) panic(err) } utils.EnableDebugLogForTest() return post }
func main() { flag.Parse() log.Info("message ver: \"%s\" start", ver.Version) if err := InitConfig(); err != nil { panic(err) } // Set max routine runtime.GOMAXPROCS(Conf.MaxProc) // init log log.LoadConfiguration(Conf.Log) defer log.Close() // start pprof http perf.Init(Conf.PprofBind) // Initialize redis if err := InitStorage(); err != nil { panic(err) } // init rpc service if err := InitRPC(); err != nil { panic(err) } // init zookeeper zk, err := InitZK() if err != nil { if zk != nil { zk.Close() } panic(err) } // process init if err = process.Init(Conf.User, Conf.Dir, Conf.PidFile); err != nil { panic(err) } // init signals, block wait signals sig := InitSignal() HandleSignal(sig) // exit log.Info("message stop") }
func (me *TestHelper) CreateUser() *model.User { id := model.NewId() user := &model.User{ Email: "success+" + id + "@simulator.amazonses.com", Username: "******" + id, Nickname: "nn_" + id, Password: "******", EmailVerified: true, } utils.DisableDebugLogForTest() var err *model.AppError if user, err = CreateUser(user); err != nil { l4g.Error(err.Error()) l4g.Close() time.Sleep(time.Second) panic(err) } utils.EnableDebugLogForTest() return user }
func (me *TestHelper) createChannel(team *model.Team, channelType string) *model.Channel { id := model.NewId() channel := &model.Channel{ DisplayName: "dn_" + id, Name: "name_" + id, Type: channelType, TeamId: team.Id, CreatorId: me.BasicUser.Id, } utils.DisableDebugLogForTest() var err *model.AppError if channel, err = CreateChannel(channel, true); err != nil { l4g.Error(err.Error()) l4g.Close() time.Sleep(time.Second) panic(err) } utils.EnableDebugLogForTest() return channel }
func flushLogAndExit(code int) { l4g.Close() time.Sleep(time.Second) os.Exit(code) }
func main() { defer logger.Close() flag.Parse() cpus := runtime.NumCPU() logger.Info("CPU核心数=%d,\t并发数=%d,\t单线程请求数=%d,\t每次请求间隔时间=%d,\t请求地址=%s", cpus, *coroutines, *reqnum, *interval, *url) timeStart := time.Now().UnixNano() runtime.GOMAXPROCS(cpus) coroutinesNum := *coroutines subCoroutinesNum := *reqnum count := coroutinesNum * subCoroutinesNum ch := make(chan service.IaxResponse, count) defer close(ch) for i := 0; i < coroutinesNum; i++ { go func(index int) { // Start Coroutines for j := 0; j < subCoroutinesNum; j++ { st := time.Now().UnixNano() req := service.IaxRequest{Id: index, SubId: j, Descr: "haha", Url: *url} res := Request(req) end := time.Now().UnixNano() useTimeNano := end - st if *interval > 0 && useTimeNano < int64(*interval*1000*1000) { sleepTime := int64(*interval*1000*1000) - useTimeNano time.Sleep(time.Nanosecond * time.Duration(sleepTime)) } end = time.Now().UnixNano() useTime := float64(end-st) / 1000.00 / 1000.00 res.UseTime = float32(round(useTime, 2)) ch <- res } }(i) } resultList := make([]service.IaxResponse, count) next := true var index int = 0 for next { select { case result := <-ch: resultList[index] = result index += 1 if index == count { next = false } } } timeEnd := time.Now().UnixNano() useTime := timeEnd - timeStart minUseTime := resultList[0] // 最小用时 maxUseTime := minUseTime // 最大用时 success := 0 //成功总数 successMinUseTime := minUseTime // 状态成功最小用时 successMaxUseTime := successMinUseTime // 状态成功最大用时 successResult := 0 noAdsCount := 0 for index, value := range resultList { if value.StatusCode == 200 { success += 1 if value.UseTime < successMinUseTime.UseTime { successMinUseTime = value } if value.UseTime > successMaxUseTime.UseTime { successMaxUseTime = value } var result models.Result bodyText := value.Body bodyText = strings.Replace(bodyText, "window.admaxADMAX_1.serve.callback(", "", -1) bodyText = strings.Replace(bodyText, ")", "", -1) bodyText = strings.Replace(bodyText, "\n", "", -1) bodyText = strings.Replace(bodyText, "\t", "", -1) err := json.Unmarshal([]byte(bodyText), &result) if err != nil { logger.Error("%+v", err) } value.Result = result if result.Success { successResult += 1 } if len(result.Ads[0].Link) < 100 || strings.HasPrefix(result.Ads[0].Link, "http") { noAdsCount += 1 logger.Debug(" index=%d use=%.2f-ms\t ----> %s, %s\n", index, value.UseTime, result.Ads[0].BidId, result.Ads[0].Link) } } if value.UseTime < minUseTime.UseTime { minUseTime = value } if value.UseTime > maxUseTime.UseTime { maxUseTime = value } //logger.Info("%d,%+v", index, value) } successRate := float64(success) / float64(count) * 100.0 // 成功比例 successAdRate := float64(count-noAdsCount) / float64(count) * 100.0 //DSP参与广告竟价的比例 //successRate = round(successRate, 2) allUseTime := float64(useTime) / 1000.00 / 1000.00 // 总用时 avgUseTime := allUseTime / float64(count) // 平均用时 allTimeSecond := float64(allUseTime) / 1000.00 if allTimeSecond <= 0 { allTimeSecond = 1 } qps := float64(count) / allTimeSecond if qps < 1 && count > 0 { qps = 1 } logger.Info("\n\tGame over, All use Time=%.2f-ms, avg use time=%.2f-ms, min time=%.2f, max time=%.2f, success min time=%.2f, success max time=%.2f, request count=%d, success count=%d, result success count=%d, no ads count=%d, failure=%d, success rate=%.2f%s, success ad rate=%.2f%s, QPS=%d \n", allUseTime, avgUseTime, minUseTime.UseTime, maxUseTime.UseTime, successMinUseTime.UseTime, successMaxUseTime.UseTime, count, success, successResult, noAdsCount, (count - success), successRate, "%", successAdRate, "%", int(qps)) }
func main() { // parse cmd-line arguments flag.Parse() log.Info("comet ver: \"%s\" start", ver.Version) // init config if err := InitConfig(); err != nil { panic(err) } // set max routine runtime.GOMAXPROCS(Conf.MaxProc) // init log log.Info("comet log configuration") log.LoadConfiguration(Conf.Log) defer log.Close() // start pprof log.Info("comet init perf") perf.Init(Conf.PprofBind) // create channel // if process exit, close channel UserChannel = NewChannelList() defer UserChannel.Close() // start stats log.Info("comet start stats") StartStats() // start rpc,应该不需要了吧? log.Info("comet start rpc") if err := InitControllerRpcClient(); err != nil { panic(err) } defer thriftPool.Release() // start comet log.Info("comet start ") if err := StartComet(); err != nil { panic(err) } // configuration the kafka topic and kafka consumer to consum the notify messages. log.Info("queue start") if err := StartQueue(); err != nil { panic(err) } // init zookeeper,用来监控instance的启动和服务down。同步instance的ip,queue,信息到配置中心。配置中心监控监控变动,同步信息到调度中心。 zkConn, err := InitZK() if err != nil { if zkConn != nil { zkConn.Close() } panic(err) } // process init // if err = process.Init(Conf.User, Conf.Dir, Conf.PidFile); err != nil { // panic(err) // } // init signals, block wait signals signalCH := InitSignal() HandleSignal(signalCH) // exit log.Info("comet stop") }