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

Added new method get_back_end_interface_set() to speed up back-end in… #5731

Merged
merged 4 commits into from
Nov 1, 2020
Merged
Changes from 2 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
25 changes: 25 additions & 0 deletions src/sonic-py-common/sonic_py_common/multi_asic.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,31 @@ def is_port_channel_internal(port_channel, namespace=None):

return False

# Allow user to get a set() of back-end interface and back-end LAG per namespace
# default is getting it for all name spaces if no namespace is specified
def get_back_end_interface_set(namespace=None):
bk_end_intf_list =[]
if not is_multi_asic():
return None

port_table = get_port_table(namespace)
for port, info in port_table.items():
if PORT_ROLE in info and info[PORT_ROLE] == INTERNAL_PORT:
bk_end_intf_list.append(port)

ns_list = get_namespace_list(namespace)
for ns in ns_list:
config_db = connect_config_db_for_ns(ns)
port_channels = config_db.get_table(PORT_CHANNEL_CFG_DB_TABLE)
for port_channel, lag_info in port_channels.items():
if 'members' in lag_info:
members = lag_info['members']
if members[0] in bk_end_intf_list:
bk_end_intf_list.append(port_channel)

a = set()
a.update(bk_end_intf_list)
Copy link
Contributor

@smaheshm smaheshm Oct 28, 2020

Choose a reason for hiding this comment

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

return set(bk_end_intf_list)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@smaheshm according to some research using .update(xx_list) has better performance when compared to set(xx_list).

Copy link
Contributor

Choose a reason for hiding this comment

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

samaddik@samaddik-vm-01:/data/sonic$ python -m timeit 'x = [x for x in range(0, 1000000)]; y = set(); y.update(x)'
10 loops, best of 3: 104 msec per loop
samaddik@samaddik-vm-01:/data/sonic$ python -m timeit 'x = [x for x in range(0, 1000000)]; y = set(); y.update(x)'
10 loops, best of 3: 104 msec per loop
samaddik@samaddik-vm-01:/data/sonic$ python -m timeit 'x = [x for x in range(0, 1000000)]; y = set(); y.update(x)'
10 loops, best of 3: 105 msec per loop
samaddik@samaddik-vm-01:/data/sonic$ python -m timeit 'x = [x for x in range(0, 1000000)]; set(x)'
10 loops, best of 3: 104 msec per loop
samaddik@samaddik-vm-01:/data/sonic$ python -m timeit 'x = [x for x in range(0, 1000000)]; set(x)'
10 loops, best of 3: 105 msec per loop

No noticeable diff for million elements. Either is fine.

return a

def is_bgp_session_internal(bgp_neigh_ip, namespace=None):

Expand Down