Skip to content

improve performance for show vlan brief in large-scale config#4626

Open
yanjundeng wants to merge 3 commits into
sonic-net:masterfrom
yanjundeng:improve-show-vlan-brief
Open

improve performance for show vlan brief in large-scale config#4626
yanjundeng wants to merge 3 commits into
sonic-net:masterfrom
yanjundeng:improve-show-vlan-brief

Conversation

@yanjundeng

@yanjundeng yanjundeng commented Jun 17, 2026

Copy link
Copy Markdown

What I did

Improve the performance of "show vlan brief" in large-scale testbed

How I did it

Performance issues in "show vlan brief":

  1. get_vlan_ports constructs InterfaceAliasConverter(db) per VLAN — that loads the entire PORT table and calls load_db_config() each time. With 800 VLANs that's 800 PORT-table reads.
  2. natsorted(list(vlan_ports_data.keys())) runs twice per VLAN (in get_vlan_ports and get_vlan_ports_tagging).
  3. get_vlan_ip_address and get_proxy_arp linearly scan all VLAN_INTERFACE keys per VLAN .
  4. get_interface_naming_mode() is queried per VLAN.

Fix :
added _get_brief_cache(ctx) that precomputes ip_by_vlan, proxy_arp_by_vlan, ports_by_vlan (natsorted), tagging_by_vlan, naming mode, and the alias converter exactly once per command.

The cache is stashed on the db object (the same pattern the dhcp-relay plugin uses) — safe because click.make_pass_decorator(Db, ensure=True) creates a fresh Db per CLI invocation. InterfaceAliasConverter is only built when SONIC_CLI_IFACE_MODE=alias.

How to verify it

Verify it on Large scale setup.
It reduces the response time from 35s to 5s.

show-vlan-brief-improvement-ut.log

Previous command output (if the output of a command-line utility has changed)

New command output (if the output of a command-line utility has changed)

Signed-off-by: yanjun deng <yadeng@cisco.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@yanjundeng yanjundeng changed the title improve performance for show vlan brief improve performance for show vlan brief in large-scale config Jun 17, 2026
Signed-off-by: yanjun deng <yadeng@cisco.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown
Collaborator

Hi, there are workflow run(s) waiting for approval, you may be first-time contributor. I will notify maintainers to help approve once PR is approved. Thanks!

---Powered by SONiC BuildBot

@pbrisset pbrisset left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good optimization!

Comment thread show/vlan.py
Comment thread show/vlan.py
Signed-off-by: yanjun deng <yadeng@cisco.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants