示例#1
0
func Benchmark_TChannel_YARPCToYARPC(b *testing.B) {
	serverCh, err := tchannel.NewChannel("server", nil)
	require.NoError(b, err, "failed to build server TChannel")

	serverCfg := yarpc.Config{
		Name:     "server",
		Inbounds: []transport.Inbound{ytchannel.NewInbound(serverCh)},
	}

	clientCh, err := tchannel.NewChannel("client", nil)
	require.NoError(b, err, "failed to build client TChannel")

	// no defer close on channels because YARPC will take care of that

	withDispatcher(b, serverCfg, func(server yarpc.Dispatcher) {
		server.Register(raw.Procedure("echo", yarpcEcho))

		// Need server already started to build client config
		clientCfg := yarpc.Config{
			Name: "client",
			Outbounds: yarpc.Outbounds{
				"server": {
					Unary: ytchannel.NewOutbound(clientCh, ytchannel.HostPort(serverCh.PeerInfo().HostPort)),
				},
			},
		}
		withDispatcher(b, clientCfg, func(client yarpc.Dispatcher) {
			b.ResetTimer()
			runYARPCClient(b, raw.New(client.Channel("server")))
		})
	})
}
示例#2
0
文件: server.go 项目: yarpc/yarpc-go
func register(reg transport.Registrar) {
	reg.Register(raw.Procedure("echo/raw", EchoRaw))
	reg.Register(json.Procedure("echo", EchoJSON))

	reg.Register(echoserver.New(EchoThrift{}))
	reg.Register(thrifttestserver.New(thriftTest{}))
	reg.Register(secondserviceserver.New(secondService{}))

	reg.Register(json.Procedure("unexpected-error", UnexpectedError))
	reg.Register(json.Procedure("bad-response", BadResponse))
	reg.Register(json.Procedure("phone", Phone))
	reg.Register(json.Procedure("sleep", Sleep))

	reg.Register(raw.Procedure("sleep/raw", SleepRaw))
	reg.Register(raw.Procedure("waitfortimeout/raw", WaitForTimeoutRaw))
}
示例#3
0
func withConnectedClient(t *testing.T, recorder *Recorder, f func(raw.Client)) {
	serverHTTP := http.NewInbound(":0")

	serverDisp := yarpc.NewDispatcher(yarpc.Config{
		Name:     "server",
		Inbounds: []transport.Inbound{serverHTTP},
	})

	serverDisp.Register(raw.Procedure("hello",
		func(ctx context.Context, reqMeta yarpc.ReqMeta, body []byte) ([]byte, yarpc.ResMeta, error) {
			return append(body, []byte(", World")...), nil, nil
		}))

	require.NoError(t, serverDisp.Start())
	defer serverDisp.Stop()

	clientDisp := yarpc.NewDispatcher(yarpc.Config{
		Name: "client",
		Outbounds: yarpc.Outbounds{
			"server": {
				Unary: http.NewOutbound(fmt.Sprintf("http://%s", serverHTTP.Addr().String())),
			},
		},
		Filter: recorder,
	})
	require.NoError(t, clientDisp.Start())
	defer clientDisp.Stop()

	client := raw.New(clientDisp.Channel("server"))
	f(client)
}
示例#4
0
func Benchmark_HTTP_NetHTTPToYARPC(b *testing.B) {
	serverCfg := yarpc.Config{
		Name:     "server",
		Inbounds: []transport.Inbound{yhttp.NewInbound(":8996")},
	}

	withDispatcher(b, serverCfg, func(server yarpc.Dispatcher) {
		server.Register(raw.Procedure("echo", yarpcEcho))

		b.ResetTimer()
		runHTTPClient(b, http.DefaultClient, "http://localhost:8996")
	})
}
示例#5
0
func Benchmark_TChannel_TChannelToYARPC(b *testing.B) {
	serverCh, err := tchannel.NewChannel("server", nil)
	require.NoError(b, err, "failed to build server TChannel")

	serverCfg := yarpc.Config{
		Name:     "server",
		Inbounds: []transport.Inbound{ytchannel.NewInbound(serverCh)},
	}

	withDispatcher(b, serverCfg, func(server yarpc.Dispatcher) {
		server.Register(raw.Procedure("echo", yarpcEcho))

		clientCh, err := tchannel.NewChannel("client", nil)
		require.NoError(b, err, "failed to build client TChannel")
		defer clientCh.Close()

		b.ResetTimer()
		runTChannelClient(b, clientCh, serverCh.PeerInfo().HostPort)
	})
}
示例#6
0
func Benchmark_HTTP_YARPCToYARPC(b *testing.B) {
	serverCfg := yarpc.Config{
		Name:     "server",
		Inbounds: []transport.Inbound{yhttp.NewInbound(":8999")},
	}

	clientCfg := yarpc.Config{
		Name: "client",
		Outbounds: yarpc.Outbounds{
			"server": {
				Unary: yhttp.NewOutbound("http://localhost:8999"),
			},
		},
	}

	withDispatcher(b, serverCfg, func(server yarpc.Dispatcher) {
		server.Register(raw.Procedure("echo", yarpcEcho))
		withDispatcher(b, clientCfg, func(client yarpc.Dispatcher) {
			b.ResetTimer()
			runYARPCClient(b, raw.New(client.Channel("server")))
		})
	})
}