-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'show bgp detail' memory improvement #16771
'show bgp detail' memory improvement #16771
Conversation
I'm a bit confused, is this an issue of the JSON library or our implementation? |
Json structs are locally allocated at show time in BGP as paths. This makes increase of memory used, whereas we already struggle with memory with BGP handling million of routes. I had the possibility to allocate json at startup. In this way, even before show time, we would have reached a memory size that would not move, event after. So I decided to not store json. I took the choice of using b). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the "before" and "after" examples in the description: where on master were those taken? did both include the "incremental vtysh" change that we merged recently? I'm wondering whether there's something we might do to extend that concept for large json output, if necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just at the top level, I'm not keen to try to manually do json encoding inside bgpd. I'd prefer to see something incremental, for example, that still used the common library in some more efficient way.
Measures have been done on the top of master (with spike commit + json incremental fixes partial for BGP). |
I think that on a long term basis, all this code will be replaced by a real state model defined in YANG. But today, we do not have this in BGP. |
a057c2e
to
605766d
Compare
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Have you looked at the json-c library? it looks like it would be possible to do our own string output walk through a tree of json objects, keep track of any container objects that have been partially printed, and free inner objects once they've been printed. I'll bet that would a) take fewer lines of change, and b) be reusable generally. |
The main problem is we store json objects in BGP aspath/communities/large communities structure, and it is too expensive. |
I made a branch with using extended API. With a custom release using serialized code for aspath only (community and large community code has been removed) we demonstrate that the memory taken is similar to before the 'show bgp ipv4 json detail' command. before the show
during the show
after the show
|
When using the 'show bgp ipv4 json detail' against a full route, the BGP memory consumed increases a lot, and is never restored. Before the show: > root@dut-orwell-nianticvf:~# ps -aux | grep bgpd > root 12263 10.8 10.1 1213920 1033452 ? Ssl 10:43 1:42 /usr/bin/bgpd -A 127.0.0.1 -M snmp -M rpki -M bmp After the show: > root@dut-orwell-nianticvf:~# ps -aux | grep bgpd > root 11772 4.9 19.3 2150668 1970548 ? Ssl 08:59 2:09 /usr/bin/bgpd -A 127.0.0.1 -M snmp -M rpki -M bmp This is not a memory leak, since applying multiple times the command does not increase the memory. What happens is that some internal structures of BGP store a json structure: AsPath, Communities, Large Communities. This series of commits intends to do the following for the following objects: ASPaths, communities and large communities: - replace the usage of the internal json structure by a dynamically built json object. - remove the no more used json object referenced in the BGP internals. That first commit addresses the case with ASpaths: instead of relying on the internal json structure, the json aspath objects are allocated and freed at usage. Signed-off-by: Philippe Guibert <[email protected]>
The aspath library stores a json pointer that is no more used. Remove the 'make_json' argument of the associated functions. Remove the 'json' attribute from the bgp_aspath structure. Signed-off-by: Philippe Guibert <[email protected]>
Create the community_json_list() function, that stores the community list output in a passed buffer, and optionally in the json community list passed array. This commit does not have any functional impact. Signed-off-by: Philippe Guibert <[email protected]>
605766d
to
2ef66bd
Compare
The community_get_json() API is used to return a json object. At display time, this object will use the community_list_json_to_string() function to handle the output. Signed-off-by: Philippe Guibert <[email protected]>
The bgp community list library stores a json pointer that is no more used. Remove the 'make_json' argument of the associated functions. Remove the 'json' attribute from the bgp community structure. Signed-off-by: Philippe Guibert <[email protected]>
Create the lcommunity_json_list() function, that returns the large community list output in a returned buffer, and optionally in the json large community list passed array. This commit does not have any functional impact. Signed-off-by: Philippe Guibert <[email protected]>
2ef66bd
to
f0c97fa
Compare
The lcommunity_get_json() API is used to return a json object. At display time, this object will use the lcommunity_json_to_string() function to handle the output. Signed-off-by: Philippe Guibert <[email protected]>
The bgp large community library stores a json pointer that is no more used. Remove the 'make_json' argument of the associated functions. Remove the 'json' attribute from the bgp large community structure. Signed-off-by: Philippe Guibert <[email protected]>
f0c97fa
to
eb6b0a1
Compare
The global memory used before the show
after the show
|
This API proposes to use the sprintbuf() method to facilitate the forge of buffers in json. Note that this buffer is limited to 128 bytes, so it can not be used everywhere as it without any checks. Signed-off-by: Philippe Guibert <[email protected]>
@mjstapp , please review
|
closing this pull request for clarity. please go to: |
After having loaded a full route, the memory consumption still increases after executing the 'show bgp ipv4 json detail' command. The memory consumed is related to json objects stored for BGP as paths, standard and large communities.
The below pull request proposes to incrementally display each path detailed information, without relying on the json storage.
Memory consumed after BGP routes have been loaded:
Memory consumed after the 'show bgp ipv4 json detail' command is executed, without fix:
after fix: