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

[Namespace]: Reduce time taken during get_all from all namespaces #137

Closed
wants to merge 13 commits into from

Conversation

SuvarnaMeenakshi
Copy link
Contributor

- What I did
To support namespaces, we added a Namespace class with functions to support getting data from all databases.
The Namespace dbs_get_all function , checks if the key exists in the database before executing get_all.
This additional check was causing additional time, which was causing agentx socket to disconnect.

- How I did it

  • Added new Namespace class variables to get the mapping of interface index and namespace(or database instance).
  • Use the new mapping to directly execute get_all from that specific database instance instead of checking if the key exists in the database.

- How to verify it
Make sure unit-test passes.
Make sure single-asic platform test cases are passing and no error message is observed in the syslog.
Check snmp output in multi-asic platform.

- Description for the changelog

interface index and database instance to avoid checking
if a key exists every time for get_all.

Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>

"""
all_ns_db - will have db_conn to all namespace DBs and
global db. First db in the list is global db.
Ignore first global db to get interface tables if there
are multiple namespaces.
"""
for db_conn in Namespace.get_non_host_dbs(dbs):
for inst in range(Namespace.get_start_idx_of_non_host(dbs), len(dbs)):
Copy link
Contributor

@qiluo-msft qiluo-msft Jul 2, 2020

Choose a reason for hiding this comment

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

inst [](start = 12, length = 4)

ns_index or ns ? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ns_index; basically, the index in db array.
index is not same as namespace, index 0 will be host namespace.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then call it db_index ?


In reply to: 449314977 [](ancestors = 449314977)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated as per comment

self.if_range.append((if_oid, ))
self.if_range.sort()
if not self.loc_port_data:
logger.warning("0 - b'PORT_TABLE' is empty. No local port information could be retrieved.")

def _get_if_entry(self, if_name):
def _get_if_entry(self, if_name, db_inst):
Copy link
Contributor

@qiluo-msft qiluo-msft Jul 3, 2020

Choose a reason for hiding this comment

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

db_inst [](start = 37, length = 7)

db_index? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated as per comment

if len(dbs) == 1:
return 0
else:
return 1

@staticmethod
def init_namespace_sync_d_interface_tables(dbs):
Copy link
Contributor

@qiluo-msft qiluo-msft Jul 3, 2020

Choose a reason for hiding this comment

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

init_namespace_sync_d [](start = 8, length = 21)

I see a common pattern in all the functions like init_namespace_sync_d*. They just call the single db function and merge all returned items respectively.

How about abstract this high level function and return a dictionary of list, in this case the type is db -> { if_name_map, if_alias_map, if_id_map, oid_sai_map, oid_name_map, if_oid_namespace }

This comment is also true on dbs_keys_namespace

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the MIB implementations, we generally use a single dict to look up the if_index etc. If we have a dict of lists, then we will have to loop through this dict for each instance of the db and look for the if_index, which will make the code look bulky in the places where these functions are used.



@staticmethod
def get_start_idx_of_non_host(dbs):
Copy link
Contributor

@qiluo-msft qiluo-msft Jul 3, 2020

Choose a reason for hiding this comment

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

get_start_idx_of_non_host [](start = 8, length = 25)

You can return a range since all use cases are in a range. You can further implement get_non_host_dbs by this function.

A better name will be get_non_host_db_indexes #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated as per comment.

Copy link
Contributor

@qiluo-msft qiluo-msft left a comment

Choose a reason for hiding this comment

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

As comments

Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
@lgtm-com
Copy link

lgtm-com bot commented Jul 7, 2020

This pull request introduces 1 alert when merging effc505 into 253f58e - view on LGTM.com

new alerts:

  • 1 for Syntax error

Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
@@ -233,9 +233,9 @@ def update_data(self):
if not self.pubsub[i]:
pattern = self.TRANSCEIVER_KEY_PATTERN
self.pubsub[i] = mibs.get_redis_pubsub(self.statedb[i], self.statedb[i].STATE_DB, pattern)
Copy link
Contributor

@qiluo-msft qiluo-msft Jul 7, 2020

Choose a reason for hiding this comment

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

Move to __init__() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function is currently in sonic_ax_impl/mibs/init.py

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I mean the section is only needed once after each time db connected.

        for i in range(len(self.statedb)):
            if not self.pubsub[i]:
                pattern = self.TRANSCEIVER_KEY_PATTERN
                self.pubsub[i] = mibs.get_redis_pubsub(self.statedb[i], self.statedb[i].STATE_DB, pattern)

In reply to: 451174442 [](ancestors = 451174442)


def _update_per_namespace_data(self, pubsub):
def _update_per_namespace_data(self, pubsub, db_instance):
Copy link
Contributor

@qiluo-msft qiluo-msft Jul 7, 2020

Choose a reason for hiding this comment

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

db_instance [](start = 49, length = 11)

db_index #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated as per comment.

Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
@lgtm-com
Copy link

lgtm-com bot commented Jul 8, 2020

This pull request introduces 1 alert when merging 61c0d91 into 253f58e - view on LGTM.com

new alerts:

  • 1 for Unused local variable

Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
@SuvarnaMeenakshi
Copy link
Contributor Author

Will raise a new PR to fix the comment:
I see a common pattern in all the functions like init_namespace_sync_d*. They just call the single db function and merge all returned items respectively.
How about abstract this high level function and return a dictionary of list, in this case the type is db -> { if_name_map, if_alias_map, if_id_map, oid_sai_map, oid_name_map, if_oid_namespace }
This comment is also true on dbs_keys_namespace

Time reduction and socket connection error is fixed in PR #140

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.

None yet

2 participants