Exemplo n.º 1
0
// StartServer starts an RPC server.
func StartServer(address string) error {
	gorpc.SetErrorLogger(dvid.Errorf) // Send gorpc errors to appropriate error log.

	s := gorpc.NewTCPServer(address, dispatcher.NewHandlerFunc())
	if servers == nil {
		servers = make(map[string]*gorpc.Server)
	}
	servers[address] = s
	return s.Serve()
}
Exemplo n.º 2
0
// Benchmark valyala/gorpc TCP connection for 2MB payload.
func BenchmarkPingPong_2MB_valyala(b *testing.B) {
	gorpc.RegisterType(&PostingList{})

	s := gorpc.NewTCPServer(":12345", PingPong)
	if err := s.Start(); err != nil {
		b.Fatal("While starting server on port 12345")
		return
	}
	defer s.Stop()

	req := NewRequest(mb2)
	c := gorpc.NewTCPClient(":12345")
	c.Start()
	defer c.Stop()

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		_, err := c.Call(req)
		if err != nil {
			b.Fatalf("While running request: %v", err)
			return
		}
	}
}