diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-01-16 16:40:05 +0900 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-01-16 18:25:35 +0900 |
commit | 6403c806634491b6cd6c3c90f61badf478fed9aa (patch) | |
tree | f557370a5c3ca739d644172140dd42af63cd1b00 /table | |
parent | 0cf8045e994b653030b721c574614d46c1870cf1 (diff) |
server: reduce number of path.Clone() call to reduce memory footprint
the result of memory profile (500 route-server-clients each of them
advertises 100 routes)
before:
(pprof) top5
3913.02MB of 3978.69MB total (98.35%)
Dropped 148 nodes (cum <= 19.89MB)
Showing top 10 nodes out of 11 (cum >= 21MB)
flat flat% sum% cum cum%
2970.30MB 74.66% 74.66% 2975.80MB 74.79% github.com/osrg/gobgp/server.filterpath
810.09MB 20.36% 95.02% 810.59MB 20.37% github.com/osrg/gobgp/table.(*AdjRib).Update
115.60MB 2.91% 97.92% 119.10MB 2.99% github.com/osrg/gobgp/table.createUpdateMsgFromPath
10MB 0.25% 98.17% 1878.02MB 47.20% github.com/osrg/gobgp/server.(*BgpServer).propagateUpdate
4.50MB 0.11% 98.29% 144.60MB 3.63% github.com/osrg/gobgp/table.CreateUpdateMsgFromPaths
after:
(pprof) top5
1259.49MB of 1284.27MB total (98.07%)
Dropped 175 nodes (cum <= 6.42MB)
Showing top 10 nodes out of 26 (cum >= 36.51MB)
flat flat% sum% cum cum%
975.81MB 75.98% 75.98% 976.31MB 76.02% github.com/osrg/gobgp/table.(*AdjRib).Update
198.67MB 15.47% 91.45% 208.17MB 16.21% github.com/osrg/gobgp/table.createUpdateMsgFromPath
22MB 1.71% 93.16% 22MB 1.71% github.com/osrg/gobgp/packet.(*IPAddrPrefix).Serialize
20MB 1.56% 94.72% 707.19MB 55.07% github.com/osrg/gobgp/server.(*BgpServer).propagateUpdate
13.50MB 1.05% 95.77% 13.50MB 1.05% github.com/osrg/gobgp/table.NewPath
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'table')
-rw-r--r-- | table/destination.go | 2 | ||||
-rw-r--r-- | table/path.go | 24 | ||||
-rw-r--r-- | table/policy.go | 14 |
3 files changed, 13 insertions, 27 deletions
diff --git a/table/destination.go b/table/destination.go index d6f1f1de..78c54ba0 100644 --- a/table/destination.go +++ b/table/destination.go @@ -258,7 +258,7 @@ func (dest *Destination) NewFeed(id string) *Path { if old == nil { return nil } - return old.Clone(old.Owner, true) + return old.Clone(true) } return best } diff --git a/table/path.go b/table/path.go index c647a7cc..10b33448 100644 --- a/table/path.go +++ b/table/path.go @@ -17,7 +17,6 @@ package table import ( "bytes" - "encoding/json" "fmt" log "github.com/Sirupsen/logrus" api "github.com/osrg/gobgp/api" @@ -61,7 +60,6 @@ type Path struct { info *originInfo IsWithdraw bool pathAttrs []bgp.PathAttributeInterface - Owner net.IP reason BestPathReason parent *Path dels []bgp.BGPAttrType @@ -78,11 +76,6 @@ func NewPath(source *PeerInfo, nlri bgp.AddrPrefixInterface, isWithdraw bool, pa return nil } - var owner net.IP - if source != nil { - owner = source.Address - } - return &Path{ info: &originInfo{ nlri: nlri, @@ -92,7 +85,6 @@ func NewPath(source *PeerInfo, nlri bgp.AddrPrefixInterface, isWithdraw bool, pa }, IsWithdraw: isWithdraw, pathAttrs: pattrs, - Owner: owner, filtered: make(map[string]PolicyDirection), } } @@ -228,11 +220,10 @@ func (path *Path) ToApiStruct(id string) *api.Path { } // create new PathAttributes -func (path *Path) Clone(owner net.IP, isWithdraw bool) *Path { +func (path *Path) Clone(isWithdraw bool) *Path { return &Path{ parent: path, IsWithdraw: isWithdraw, - Owner: owner, filtered: make(map[string]PolicyDirection), } } @@ -714,16 +705,5 @@ func (path *Path) GetClusterList() []net.IP { } func (lhs *Path) Equal(rhs *Path) bool { - if rhs == nil { - return false - } else if lhs == rhs { - return true - } - f := func(p *Path) []byte { - s := p.ToApiStruct(GLOBAL_RIB_NAME) - s.Age = 0 - buf, _ := json.Marshal(s) - return buf - } - return bytes.Equal(f(lhs), f(rhs)) + return lhs == rhs } diff --git a/table/policy.go b/table/policy.go index a8192a58..81010a9d 100644 --- a/table/policy.go +++ b/table/policy.go @@ -32,6 +32,7 @@ import ( ) type PolicyOptions struct { + Neighbor net.IP } type DefinedType int @@ -1152,19 +1153,24 @@ func (c *NeighborCondition) Option() MatchOption { // compare neighbor ipaddress of this condition and source address of path // and, subsequent comparisons are skipped if that matches the conditions. // If NeighborList's length is zero, return true. -func (c *NeighborCondition) Evaluate(path *Path, _ *PolicyOptions) bool { +func (c *NeighborCondition) Evaluate(path *Path, options *PolicyOptions) bool { if len(c.set.list) == 0 { log.Debug("NeighborList doesn't have elements") return true } - if path.Owner == nil { + neighbor := path.GetSource().Address + if options != nil && options.Neighbor != nil { + neighbor = options.Neighbor + } + + if neighbor == nil { return false } result := false for _, n := range c.set.list { - if path.Owner.Equal(n) { + if neighbor.Equal(n) { result = true break } @@ -2094,7 +2100,7 @@ func (s *Statement) Apply(path *Path, options *PolicyOptions) (RouteType, *Path) if result { if len(s.ModActions) != 0 { // apply all modification actions - path = path.Clone(path.Owner, path.IsWithdraw) + path = path.Clone(path.IsWithdraw) for _, action := range s.ModActions { path = action.Apply(path) } |