Skip to content
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 ipv4 detail json" consumes too much memory #16880

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

pguibert6WIND
Copy link
Member

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:

dut-orwell-nianticvf# show ip route summary
Route Source         Routes               FIB  (vrf default)
kernel               1                    1
connected            2                    2
ebgp                 993276               992665
ibgp                 0                    0
------
Totals               993279               992668

root@dut-orwell-nianticvf:~# ps -aux | grep bgpd
root      106598 84.0 10.2 1224244 1044028 ?     Ssl  15:54   1:46 /usr/bin/bgpd -A 127.0.0.1 -M snmp -M rpki -M bmp

Memory consumed after the 'show bgp ipv4 json detail' command is executed, without fix:

root@dut-orwell-nianticvf:~# time vtysh -c "show bgp ipv4 detail json" > /tmp/aa.txt

real    0m25.336s
user    0m2.438s
sys     0m4.745s
root@dut-orwell-nianticvf:~# ps -aux | grep bgpd
root       16770 59.0 18.6 2080984 1900816 ?     Ssl  09:13   2:03 /usr/bin/bgpd -A 127.0.0.1 -M snmp -M rpki -M bmp

after fix:

root@dut-orwell-nianticvf:~# time vtysh -c "show bgp ipv4 detail json" > /tmp/aa.txt

real    0m33.106s
user    0m2.594s
sys     0m4.533s
root@dut-sureau-nianticvf:~# ps -aux | grep bgpd
root       45983 45.4 13.6 1567712 1387988 ?     Ssl  11:24   2:10 /usr/bin/bgpd -A 127.0.0.1 -M snmp -M rpki -M bmp

I get a memory gain (roughly 500 MB spared, -35% memory).
I get a timing status (8 seconds, +32% speed)

@pguibert6WIND pguibert6WIND changed the title Bgp detail no json alloc 2 "show bgp ipv4 detail json" consumes too much memory Sep 20, 2024
@frrbot frrbot bot added the bugfix label Sep 23, 2024
@pguibert6WIND pguibert6WIND force-pushed the bgp_detail_no_json_alloc_2 branch 6 times, most recently from 69093ca to 6209576 Compare September 26, 2024 08:13
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.

The implementation relies on the json_object_set_serializer() utility.
The function overrides the json buffer build at display time. Do
fallback to the original code when this utility is not present in
json-c library (aka < 0.13).

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]>
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]>
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]>
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]>
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant