Esempio n. 1
0
func main() {
	cf := config.NewDefaultProxy()
	cf.PoolCapacity = 2
	peer := proxy.New(cf)

	for {
		time.Sleep(time.Duration(interval) * time.Second)
		fmt.Println()

		client, err := peer.ServantByAddr(host + ":" + port)
		if err != nil {
			fmt.Println(err)
			continue
		}

		ctx := rpc.NewContext()
		ctx.Reason = "broken.test"
		ctx.Rid = time.Now().UnixNano()
		pong, err := client.Ping(ctx)
		if err != nil {
			fmt.Println("err:", err)

			if proxy.IsIoError(err) {
				client.Close()
			}
		} else {
			fmt.Println(pong)
		}

		client.Recycle()
	}

}
Esempio n. 2
0
func main() {
	cf := config.NewDefaultProxy()
	cf.IoTimeout = time.Hour
	cf.TcpNoDelay = tcpNoDelay
	prx := proxy.New(cf)

	etclib.Dial([]string{zk})
	go prx.StartMonitorCluster()
	prx.AwaitClusterTopologyReady()

	// test pool
	if testPool {
		testServantPool(prx)
		pause("pool tested")
	}

	go report.run()

	wg := new(sync.WaitGroup)
	t1 := time.Now()
	for k := c1; k <= c2; k += 10 {
		Concurrency = k

		cf.PoolCapacity = Concurrency
		prx = proxy.New(cf)

		for i := 0; i < Rounds; i++ {
			for j := 0; j < k; j++ {
				wg.Add(1)
				go runSession(prx, wg, i+1, j)
			}

			wg.Wait()
		}
	}

	elapsed := time.Since(t1)
	log.Printf("Elapsed: %s, calls: {%s, %.1f/s}, sessions: {%s, %.1f/s}, errors: {conn:%d, io:%d call:%d}",
		elapsed,
		gofmt.Comma(report.callOk),
		float64(report.callOk)/elapsed.Seconds(),
		gofmt.Comma(int64(report.sessionN)),
		float64(report.sessionN)/elapsed.Seconds(),
		report.connErrs,
		report.ioErrs,
		report.callErrs)
}
Esempio n. 3
0
func NewWithPoolCapacity(capacity int) *Proxy {
	cf := config.NewDefaultProxy()
	cf.PoolCapacity = capacity
	return New(cf)
}
Esempio n. 4
0
func NewWithDefaultConfig() *Proxy {
	return New(config.NewDefaultProxy())
}