diff --git a/cmd/gobgp/common.go b/cmd/gobgp/common.go index 4d9b311d0..095427e18 100644 --- a/cmd/gobgp/common.go +++ b/cmd/gobgp/common.go @@ -100,6 +100,7 @@ const ( var subOpts struct { AddressFamily string `short:"a" long:"address-family" description:"specifying an address family"` + BatchSize uint64 `short:"b" long:"batch-size" description:"Size of the temporary buffer in the server memory. Zero is unlimited (default)"` } var neighborsOpts struct { diff --git a/cmd/gobgp/global.go b/cmd/gobgp/global.go index 00ff62795..a4abc6997 100644 --- a/cmd/gobgp/global.go +++ b/cmd/gobgp/global.go @@ -2326,6 +2326,7 @@ func newGlobalCmd() *cobra.Command { } ribCmd.PersistentFlags().StringVarP(&subOpts.AddressFamily, "address-family", "a", "", "address family") + ribCmd.PersistentFlags().Uint64VarP(&subOpts.BatchSize, "batch-size", "b", 0, "Size of the temporary buffer in the server memory. Zero is unlimited (default)") for _, v := range []string{cmdAdd, cmdDel} { cmd := &cobra.Command{ diff --git a/cmd/gobgp/neighbor.go b/cmd/gobgp/neighbor.go index bd6c19444..4ee8340da 100644 --- a/cmd/gobgp/neighbor.go +++ b/cmd/gobgp/neighbor.go @@ -974,6 +974,7 @@ func showNeighborRib(r string, name string, args []string) error { Prefixes: filter, SortType: api.ListPathRequest_PREFIX, EnableFiltered: enableFiltered, + BatchSize: subOpts.BatchSize, }) if err != nil { return err diff --git a/pkg/server/grpc_server.go b/pkg/server/grpc_server.go index e5fbf0654..5250139fd 100644 --- a/pkg/server/grpc_server.go +++ b/pkg/server/grpc_server.go @@ -261,8 +261,8 @@ func (s *server) ListPath(r *api.ListPathRequest, stream api.GobgpApi_ListPathSe } var sendErr error err := s.bgpServer.ListPath(ctx, r, func(d *api.Destination) { - if uint64(len(l)) < batchSize { - l = append(l, d) + l = append(l, d) + if uint64(len(l)) <= batchSize { return } if sendErr = send(); sendErr != nil {