Skip to content

Conversation

@mjstapp
Copy link
Contributor

@mjstapp mjstapp commented Dec 1, 2025

There are a number of scaling issues with the current FRR json output approach. In general, we have to produce the entire json hierarchy of objects and then emit a single string to the vty. At scale, this means a large memory footprint. This PR proposes some new lib apis that allow us to incrementally output a json object hierarchy. Many leaf objects can be freed as soon as they've been output. Parent container objects can be kept "open" during long-running iterations, and then "closed" once their children have been processed. This incremental approach reduces the number of json objects in memory; only "open" parents/containers and a limited number of leaf objects need to be in memory.

The library changes required are a little ... invasive, because we have to have our own wrapper that replaces the generic json-c lib code. Maybe that's a bridge too far, so I've made this a draft PR initially.

I've used a fairly simple zebra show command, "show nexthop-group rib", as an example to illustrate the use of the new apis.

@ton31337
Copy link
Member

ton31337 commented Dec 2, 2025

Nice proposal 👍

@mjstapp
Copy link
Contributor Author

mjstapp commented Dec 2, 2025

looks like the versions of the json-c lib have some meaningful differences - I'll see about walling off the older versions...

@mjstapp
Copy link
Contributor Author

mjstapp commented Dec 2, 2025

I've pushed some changes that should help with libjson-c compatibility

Mark Stapp added 2 commits December 2, 2025 15:28
Add some new lib apis that allow us to incrementally output
a json object hierarchy. Many leaf objects can be freed
as soon as they've been output. Parent container objects
can be kept "open" during long-running iterations, and then
"closed" once their children have been processed. This
incremental approach reduces the number of json objects
in memory; only "open" containers and a limited number of
leaf objects need to be in memory.

Signed-off-by: Mark Stapp <mjs@cisco.com>
Demonstrate incremental json output with the zebra
"show nexthop-group rib" command.

Signed-off-by: Mark Stapp <mjs@cisco.com>
@donaldsharp
Copy link
Member

Could you add some documentation to the doc/developer directory on how this should be used. That way I can point people at this when we say use this functionality.

Add some doc about the new json lib apis for incremental
output.

Signed-off-by: Mark Stapp <mjs@cisco.com>
@frrbot frrbot bot added the documentation label Dec 5, 2025
@github-actions github-actions bot added the rebase PR needs rebase label Dec 5, 2025
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.

3 participants