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

lib: Fix to optimize the time taken while batching huge configs #17672

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/northbound_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ static int nb_cli_classic_commit(struct vty *vty)
static void nb_cli_pending_commit_clear(struct vty *vty)
{
vty->pending_commit = 0;
vty->buffer_cmd_count = 0;
XFREE(MTYPE_TMP, vty->pending_cmds_buf);
vty->pending_cmds_buflen = 0;
vty->pending_cmds_bufpos = 0;
Expand All @@ -102,12 +103,19 @@ int nb_cli_pending_commit_check(struct vty *vty)

static int nb_cli_schedule_command(struct vty *vty)
{
/* Append command to dynamically sized buffer of scheduled commands. */
/* Append command to dynamically sized buffer of scheduled commands.
* vty->buf -Incoming config
* vty->pending_cmds_buf - Pending buffer where incoming configs are
* accumulated for later processing
* vty->pending_cmds_bufpos - length of the pending buffer
*
*/
if (!vty->pending_cmds_buf) {
vty->pending_cmds_buflen = 4096;
vty->pending_cmds_buf =
XCALLOC(MTYPE_TMP, vty->pending_cmds_buflen);
}

if ((strlen(vty->buf) + 3)
> (vty->pending_cmds_buflen - vty->pending_cmds_bufpos)) {
vty->pending_cmds_buflen *= 2;
Expand All @@ -121,6 +129,9 @@ static int nb_cli_schedule_command(struct vty *vty)

/* Schedule the commit operation. */
vty->pending_commit = 1;
vty->buffer_cmd_count++;
if (vty->buffer_cmd_count == NB_CMD_BATCH_SIZE)
nb_cli_pending_commit_check(vty);

return CMD_SUCCESS;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/northbound_cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ enum nb_cfg_format {
NB_CFG_FMT_XML,
};

/* Maximum config commands in a batch*/
#define NB_CMD_BATCH_SIZE 5000

extern struct nb_config *vty_shared_candidate_config;

/*
Expand Down
1 change: 1 addition & 0 deletions lib/vty.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ struct vty {
struct nb_config *candidate_config_base;

/* Dynamic transaction information. */
size_t buffer_cmd_count;
bool pending_allowed;
bool pending_commit;
char *pending_cmds_buf;
Expand Down
Loading