示例#1
0
文件: runner.go 项目: xtracdev/xavi
func setupXAVIEnvironment(pluginRegistrationFn func()) kvstore.KVStore {
	log.Info("GOMAXPROCS: ", runtime.GOMAXPROCS(-1))
	if pluginRegistrationFn != nil {
		log.Info("Registering plugins")
		pluginRegistrationFn()
	}

	log.Info("Obtaining handle to KV store")
	kvs, err := kvstore.NewKVStore(getKVStoreEndpoint())
	if err != nil {
		log.Fatal(err.Error())
	}

	return kvs
}
示例#2
0
func main() {

	//Allow expvar monitoring
	go http.ListenAndServe(":1234", nil)

	//Initialize  the KVStore from the local file store established by running
	//the set up script
	endpoint := os.Getenv(env.KVStoreURL)
	if endpoint == "" {
		log.Fatal(fmt.Sprintf("Required environment variable %s for configuration KV store must be specified", env.KVStoreURL))
	}

	kvs, err := kvstore.NewKVStore(endpoint)
	fatal(err)

	//Since no listener is in context in this sample process, register
	//the configuration so NewBackendLoadBalancer has it in context.
	sc, err := config.ReadServiceConfig("quote-listener", kvs)
	fatal(err)
	config.RecordActiveConfig(sc)

	//Instantiate the load balancer for the quote-backend
	lb, err := loadbalancer.NewBackendLoadBalancer("quote-backend")
	fatal(err)

	for i := 1; i < 10000; i++ {
		req, err := http.NewRequest("GET", "https://hostname:4443", nil)
		fatal(err)

		resp, err := lb.DoWithLoadBalancer(req, true)
		fatal(err)

		_, err = ioutil.ReadAll(resp.Body)
		fatal(err)
		resp.Body.Close()

		if i%100 == 0 {
			fmt.Printf("Done %d calls...\n", i)
		}
	}

	time.Sleep(300 * time.Second)

}