示例#1
0
// TestRelayStress makes many concurrent calls and ensures that
// we don't try to reuse any frames once they've been released.
func TestRelayConcurrentCalls(t *testing.T) {
	pool := NewProtectMemFramePool()
	opts := testutils.NewOpts().SetRelayOnly().SetFramePool(pool)
	testutils.WithTestServer(t, opts, func(ts *testutils.TestServer) {
		server := benchmark.NewServer(
			benchmark.WithNoLibrary(),
			benchmark.WithServiceName("s1"),
		)
		defer server.Close()
		ts.RelayHosts().Add("s1", server.HostPort())

		client := benchmark.NewClient([]string{ts.HostPort()},
			benchmark.WithNoDurations(),
			benchmark.WithNoLibrary(),
			benchmark.WithNumClients(20),
			benchmark.WithServiceName("s1"),
			benchmark.WithTimeout(time.Minute),
		)
		defer client.Close()
		require.NoError(t, client.Warmup(), "Client warmup failed")

		_, err := client.RawCall(1000)
		assert.NoError(t, err, "RawCalls failed")
	})
}
示例#2
0
文件: main.go 项目: uber/tchannel-go
func main() {
	flag.Parse()

	opts := []benchmark.Option{
		benchmark.WithServiceName(*serviceName),
		benchmark.WithTimeout(*timeout),
		benchmark.WithRequestSize(*requestSize),
		benchmark.WithNumClients(*numClients),
	}
	if *noLibrary {
		opts = append(opts, benchmark.WithNoLibrary())
	}

	client := benchmark.NewClient(flag.Args(), opts...)
	fmt.Println("bench-client started")

	rdr := bufio.NewScanner(os.Stdin)
	for rdr.Scan() {
		line := rdr.Text()
		parts := strings.Split(line, " ")
		var n int
		var err error
		if len(parts) >= 2 {
			n, err = strconv.Atoi(parts[1])
			if err != nil {
				log.Fatalf("unrecognized number %q: %v", parts[1], err)
			}
		}

		switch cmd := parts[0]; cmd {
		case "warmup":
			if err := client.Warmup(); err != nil {
				log.Fatalf("warmup failed: %v", err)
			}
			fmt.Println("success")
			continue
		case "rcall":
			makeCalls(n, client.RawCall)
		case "tcall":
			makeCalls(n, client.ThriftCall)
		case "quit":
			return
		default:
			log.Fatalf("unrecognized command: %v", line)
		}
	}

	if err := rdr.Err(); err != nil {
		log.Fatalf("Reader failed: %v", err)
	}
}
示例#3
0
func BenchmarkRelayNoLatencies(b *testing.B) {
	server := benchmark.NewServer(
		benchmark.WithServiceName("svc"),
		benchmark.WithExternalProcess(),
		benchmark.WithNoLibrary(),
	)
	defer server.Close()

	hostMapping := map[string][]string{"svc": {server.HostPort()}}
	relay, err := benchmark.NewRealRelay(hostMapping)
	require.NoError(b, err, "NewRealRelay failed")
	defer relay.Close()

	client := benchmark.NewClient([]string{relay.HostPort()},
		benchmark.WithServiceName("svc"),
		benchmark.WithExternalProcess(),
		benchmark.WithNoLibrary(),
		benchmark.WithNumClients(10),
		benchmark.WithNoChecking(),
		benchmark.WithNoDurations(),
		benchmark.WithTimeout(10*time.Second),
	)
	defer client.Close()
	require.NoError(b, client.Warmup(), "client.Warmup failed")

	b.ResetTimer()
	started := time.Now()
	for _, calls := range testutils.Batch(b.N, 10000) {
		if _, err := client.RawCall(calls); err != nil {
			b.Fatalf("Calls failed: %v", err)
		}
	}

	duration := time.Since(started)
	fmt.Printf("\nb.N: %v Duration: %v RPS = %0.0f\n", b.N, duration, float64(b.N)/duration.Seconds())
}
示例#4
0
func benchmarkRelay(b *testing.B, p benchmarkParams) {
	b.SetBytes(int64(p.requestSize))
	b.ReportAllocs()

	services := make(map[string][]string)

	servers := make([]benchmark.Server, p.servers)
	for i := range servers {
		servers[i] = benchmark.NewServer(
			benchmark.WithServiceName("svc"),
			benchmark.WithRequestSize(p.requestSize),
			benchmark.WithExternalProcess(),
		)
		defer servers[i].Close()
		services["svc"] = append(services["svc]"], servers[i].HostPort())
	}

	relay, err := benchmark.NewRealRelay(services)
	require.NoError(b, err, "Failed to create relay")
	defer relay.Close()

	clients := make([]benchmark.Client, p.clients)
	for i := range clients {
		clients[i] = benchmark.NewClient([]string{relay.HostPort()},
			benchmark.WithServiceName("svc"),
			benchmark.WithRequestSize(p.requestSize),
			benchmark.WithExternalProcess(),
			benchmark.WithTimeout(10*time.Second),
		)
		defer clients[i].Close()
		require.NoError(b, clients[i].Warmup(), "Warmup failed")
	}

	quantileVals := []float64{0.50, 0.95, 0.99, 1.0}
	quantiles := make([]*quantile.Stream, p.clients)
	for i := range quantiles {
		quantiles[i] = quantile.NewTargeted(quantileVals...)
	}

	wc := newWorkerControl(p.clients)
	dec := testutils.Decrementor(b.N)

	for i, c := range clients {
		go func(i int, c benchmark.Client) {
			// Do a warm up call.
			c.RawCall(1)

			wc.WorkerStart()
			defer wc.WorkerDone()

			for {
				tokens := dec.Multiple(200)
				if tokens == 0 {
					break
				}

				durations, err := c.RawCall(tokens)
				if err != nil {
					b.Fatalf("Call failed: %v", err)
				}

				for _, d := range durations {
					quantiles[i].Insert(float64(d))
				}
			}
		}(i, c)
	}

	var started time.Time
	wc.WaitForStart(func() {
		b.ResetTimer()
		started = time.Now()
	})
	wc.WaitForEnd()
	duration := time.Since(started)

	fmt.Printf("\nb.N: %v Duration: %v RPS = %0.0f\n", b.N, duration, float64(b.N)/duration.Seconds())

	// Merge all the quantiles into 1
	for _, q := range quantiles[1:] {
		quantiles[0].Merge(q.Samples())
	}

	for _, q := range quantileVals {
		fmt.Printf("  %0.4f = %v\n", q, time.Duration(quantiles[0].Query(q)))
	}
	fmt.Println()
}