Пример #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
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())
}