diff options
author | FUJITA Tomonori <fujita.tomonori@gmail.com> | 2019-09-16 22:31:42 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@gmail.com> | 2019-09-17 06:31:23 +0900 |
commit | 21093fbc8739d0a8e4f84ec6e52c98dad0894612 (patch) | |
tree | 3364be5e29afedc6f47a2923847b0953f787bb3b /pkg/server | |
parent | 682e42c98d2abc9da97f1fb925533483fcf1a834 (diff) |
server: improve ListPath's performance
send large data rather than sending small repeatedly.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Diffstat (limited to 'pkg/server')
-rw-r--r-- | pkg/server/grpc_server.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/pkg/server/grpc_server.go b/pkg/server/grpc_server.go index 725ab77a..3c7527b2 100644 --- a/pkg/server/grpc_server.go +++ b/pkg/server/grpc_server.go @@ -171,12 +171,19 @@ func getValidation(v []*table.Validation, i int) *table.Validation { func (s *server) ListPath(r *api.ListPathRequest, stream api.GobgpApi_ListPathServer) error { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - fn := func(d *api.Destination) { + l := make([]*api.Destination, 0) + err := s.bgpServer.ListPath(ctx, r, func(d *api.Destination) { + l = append(l, d) + }) + if err != nil { + return err + } + for _, d := range l { if err := stream.Send(&api.ListPathResponse{Destination: d}); err != nil { - cancel() + break } } - return s.bgpServer.ListPath(ctx, r, fn) + return err } func (s *server) MonitorTable(arg *api.MonitorTableRequest, stream api.GobgpApi_MonitorTableServer) error { |