diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-05-10 14:42:38 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-05-10 23:13:21 +0900 |
commit | 2b0f16dcc6a47bd8d6518746038b3d65ff55e8c4 (patch) | |
tree | 7678378a940b6be7c8ad150362ded0464637c0e3 /server/bmp.go | |
parent | 691d80e5d160b82c8b4dd1d83c959ecdffad318f (diff) |
bmp: avoid huge memory allocation for sending paths initially
We had to serialize all the paths once because the paths could be
modified later. Now they are immutable so we don't need.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/bmp.go')
-rw-r--r-- | server/bmp.go | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/server/bmp.go b/server/bmp.go index dd5d102e..2e9db698 100644 --- a/server/bmp.go +++ b/server/bmp.go @@ -17,14 +17,15 @@ package server import ( "fmt" + "net" + "strconv" + "time" + "github.com/osrg/gobgp/config" "github.com/osrg/gobgp/packet/bgp" "github.com/osrg/gobgp/packet/bmp" "github.com/osrg/gobgp/table" log "github.com/sirupsen/logrus" - "net" - "strconv" - "time" ) type ribout map[string][]*table.Path @@ -166,16 +167,22 @@ func (b *bmpClient) loop() { ID: msg.PeerID, } if msg.Payload == nil { - pathList := make([]*table.Path, 0, len(msg.PathList)) - for _, p := range msg.PathList { - if b.ribout.update(p) { - pathList = append(pathList, p) + var pathList []*table.Path + if msg.Init { + pathList = msg.PathList + } else { + for _, p := range msg.PathList { + if b.ribout.update(p) { + pathList = append(pathList, p) + } } } - for _, u := range table.CreateUpdateMsgFromPaths(pathList) { - payload, _ := u.Serialize() - if err := write(bmpPeerRoute(bmp.BMP_PEER_TYPE_GLOBAL, msg.PostPolicy, 0, true, info, msg.Timestamp.Unix(), payload)); err != nil { - return false + for _, path := range pathList { + for _, u := range table.CreateUpdateMsgFromPaths([]*table.Path{path}) { + payload, _ := u.Serialize() + if err := write(bmpPeerRoute(bmp.BMP_PEER_TYPE_GLOBAL, msg.PostPolicy, 0, true, info, msg.Timestamp.Unix(), payload)); err != nil { + return false + } } } } else { |