Exemplo n.º 1
0
func init() {
	revel.OnAppStart(func() {
		// 为了避免在多个app 同时运行.
		if isRunning {
			return
		}
		childProcessName := plugins.GetArg("-server")
		if childProcessName != "GoMysqlProxy" {
			return
		}

		// loade the hosts in the config
		host.Groups = getHostConfig()
		host.Hosts = getAllHosts()

		// set mysql connection pooling params.
		pooling.MinPoolingConnection = revel.Config.IntDefault("mysql.ConnectionPooling.min", 10)
		pooling.MaxPoolingConnection = revel.Config.IntDefault("mysql.ConnectionPooling.max", 20)

		// init the main mysql proxy object.
		models.MyProxy = models.NewMysqlProxy()

		wg := &sync.WaitGroup{}
		wg.Add(1)

		cron := cron.New()
		cron.AddFunc("@every 10s", func() { host.GetAndLogHostStatus() })
		cron.Start()
		isRunning = true
	})
}
Exemplo n.º 2
0
func init() {
	revel.OnAppStart(func() {
		// 为了避免在多个app 同时
		if isRunning {
			return
		}
		childProcessName := plugins.GetArg("-server")
		if childProcessName != "HostTracker" {
			return
		}

		wg := &sync.WaitGroup{}
		wg.Add(1)

		cron := cron.New()
		cron.AddFunc("@every 30s", func() { modules.Run() })
		cron.Start()
		isRunning = true
	})
}
Exemplo n.º 3
0
// 创建监听进程
func (s *GoServer) createSocketsAndListen() bool {
	if !plugins.IsInArg("-child") {
		return false
	}
	childProcessName := plugins.GetArg("-server")
	config := s.ServerCfg[childProcessName]

	if config["name"] == "" {
		s.Log.Add("No found out the worker config for:" + childProcessName)
		return false
	}

	port := ""
	if config["port"] == "" {
		return false
	} else {
		port = config["port"]
	}

	protocol := config["protocol"]
	ip := config["ip"]

	// 开启多核并行执行.
	NCPU := runtime.NumCPU()
	runtime.GOMAXPROCS(NCPU)

	switch config["protocol"] {
	case "tcp":
		return s.createTcpSocketsAndListen(protocol, ip, port, &config)
	case "udp":
		return s.createUdpSocketsAndListen(protocol, ip, port, &config)
	default:
		s.Log.Add("sorry can not support this protocol: %s", config["protocol"])
		return false
	}
}