summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-06-21 10:57:28 +0900
committerISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-06-21 10:58:00 +0900
commit706ccc9d71b3bd7b0555bf657dc80268b79222df (patch)
tree6629d100f6d7c81acb41fc7e9893ba4f5fb4eae1
parent116ca18c598de459d09e7f64d19f61e53a900f75 (diff)
api: change ModPath() return value to Error from stream Error
cut useless grpc communication and improve performance simple performance test result. rib.20150617.2000 is taken from http://archive.routeviews.org/ [before] $ time gomrt -i rib.20150617.2000 gomrt -i /vagrant/rib.20150617.2000 45.96s user 171.73s system 86% cpu 4:11.87 total [after] $ time gomrt -i rib.20150617.2000 gomrt -i /vagrant/rib.20150617.2000 11.95s user 76.17s system 74% cpu 1:58.38 total Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r--api/gobgp.pb.go12
-rw-r--r--api/gobgp.proto2
-rw-r--r--gobgp/global.go2
-rw-r--r--gomrt/main.go20
-rw-r--r--server/grpc_server.go15
5 files changed, 26 insertions, 25 deletions
diff --git a/api/gobgp.pb.go b/api/gobgp.pb.go
index 060aaa68..7d01de14 100644
--- a/api/gobgp.pb.go
+++ b/api/gobgp.pb.go
@@ -1384,7 +1384,7 @@ func (c *grpcClient) ModPath(ctx context.Context, opts ...grpc.CallOption) (Grpc
type Grpc_ModPathClient interface {
Send(*ModPathArguments) error
- Recv() (*Error, error)
+ CloseAndRecv() (*Error, error)
grpc.ClientStream
}
@@ -1396,7 +1396,10 @@ func (x *grpcModPathClient) Send(m *ModPathArguments) error {
return x.ClientStream.SendMsg(m)
}
-func (x *grpcModPathClient) Recv() (*Error, error) {
+func (x *grpcModPathClient) CloseAndRecv() (*Error, error) {
+ if err := x.ClientStream.CloseSend(); err != nil {
+ return nil, err
+ }
m := new(Error)
if err := x.ClientStream.RecvMsg(m); err != nil {
return nil, err
@@ -1706,7 +1709,7 @@ func _Grpc_ModPath_Handler(srv interface{}, stream grpc.ServerStream) error {
}
type Grpc_ModPathServer interface {
- Send(*Error) error
+ SendAndClose(*Error) error
Recv() (*ModPathArguments, error)
grpc.ServerStream
}
@@ -1715,7 +1718,7 @@ type grpcModPathServer struct {
grpc.ServerStream
}
-func (x *grpcModPathServer) Send(m *Error) error {
+func (x *grpcModPathServer) SendAndClose(m *Error) error {
return x.ServerStream.SendMsg(m)
}
@@ -1888,7 +1891,6 @@ var _Grpc_serviceDesc = grpc.ServiceDesc{
{
StreamName: "ModPath",
Handler: _Grpc_ModPath_Handler,
- ServerStreams: true,
ClientStreams: true,
},
{
diff --git a/api/gobgp.proto b/api/gobgp.proto
index b4beb1c2..e54eacca 100644
--- a/api/gobgp.proto
+++ b/api/gobgp.proto
@@ -31,7 +31,7 @@ service Grpc {
rpc Shutdown(Arguments) returns (Error) {}
rpc Enable(Arguments) returns (Error) {}
rpc Disable(Arguments) returns (Error) {}
- rpc ModPath(stream ModPathArguments) returns (stream Error) {}
+ rpc ModPath(stream ModPathArguments) returns (Error) {}
rpc GetNeighborPolicy(Arguments) returns (ApplyPolicy) {}
rpc ModNeighborPolicy(stream PolicyArguments) returns (stream Error) {}
rpc GetPolicyRoutePolicies(PolicyArguments) returns (stream PolicyDefinition) {}
diff --git a/gobgp/global.go b/gobgp/global.go
index 7883c34a..b5f19ad3 100644
--- a/gobgp/global.go
+++ b/gobgp/global.go
@@ -190,7 +190,7 @@ func modPath(modtype string, eArgs []string) error {
}
stream.CloseSend()
- res, e := stream.Recv()
+ res, e := stream.CloseAndRecv()
if e != nil {
return e
}
diff --git a/gomrt/main.go b/gomrt/main.go
index e587df78..1e44737f 100644
--- a/gomrt/main.go
+++ b/gomrt/main.go
@@ -141,15 +141,6 @@ func main() {
os.Exit(1)
}
- res, err := stream.Recv()
- if err != nil {
- fmt.Println("failed to send:", err)
- os.Exit(1)
- }
- if res.Code != api.Error_SUCCESS {
- fmt.Errorf("error: code: %d, msg: %s", res.Code, res.Msg)
- os.Exit(1)
- }
}
idx += 1
@@ -158,6 +149,17 @@ func main() {
break
}
}
+
+ res, err := stream.CloseAndRecv()
+ if err != nil {
+ fmt.Println("failed to send:", err)
+ os.Exit(1)
+ }
+ if res.Code != api.Error_SUCCESS {
+ fmt.Errorf("error: code: %d, msg: %s", res.Code, res.Msg)
+ os.Exit(1)
+ }
+
},
}
diff --git a/server/grpc_server.go b/server/grpc_server.go
index ef850dbf..b14845b2 100644
--- a/server/grpc_server.go
+++ b/server/grpc_server.go
@@ -256,7 +256,7 @@ func (s *Server) ModPath(stream api.Grpc_ModPathServer) error {
arg, err := stream.Recv()
if err == io.EOF {
- return nil
+ break
} else if err != nil {
return err
}
@@ -282,15 +282,12 @@ func (s *Server) ModPath(stream api.Grpc_ModPathServer) error {
log.Debug(err.Error())
return err
}
-
- err = stream.Send(&api.Error{
- Code: api.Error_SUCCESS,
- })
-
- if err != nil {
- return err
- }
}
+ err := stream.SendAndClose(&api.Error{
+ Code: api.Error_SUCCESS,
+ })
+
+ return err
}
func (s *Server) GetNeighborPolicy(ctx context.Context, arg *api.Arguments) (*api.ApplyPolicy, error) {