Skip to content

[202412] [cmis] add read only cache decorator#86

Merged
r12f merged 3 commits intoAzure:202412from
jianyuewu:2412_cmis_cache
Jun 18, 2025
Merged

[202412] [cmis] add read only cache decorator#86
r12f merged 3 commits intoAzure:202412from
jianyuewu:2412_cmis_cache

Conversation

@jianyuewu
Copy link

@jianyuewu jianyuewu commented May 21, 2025

202412 Cherry-pick PR for sonic-net/sonic-platform-common#562

Improve CMIS startup performance by adding a read-only cache decorator.

Description

This patch introduces read only cache decorator, which caches the results of static EEPROM-read methods in CmisApi to avoid redundant I2C transactions. By memoizing these methods, we greatly reduce the number of EEPROM reads during startup. Unit tests have been added to verify correct caching behavior and cache invalidation.

Motivation and Context

On systems managing up to 512 CMIS ports, the cumulative cost of repeated EEPROM reads at startup causes noticeable delays. Caching static getter methods eliminates unnecessary I2C calls and speeds up initialization.

How Has This Been Tested?

Test with config reload, speed up around 2 seconds.
Before:

$ time sudo config reload -y
Acquired lock on /etc/sonic/reload.lock
Disabling container and routeCheck monitoring ...
Stopping SONiC target ...
Running command: /usr/local/bin/sonic-cfggen -j /etc/sonic/init_cfg.json -j /etc/sonic/config_db.json --write-to-db
Running command: /usr/local/bin/db_migrator.py -o migrate
Running command: /usr/local/bin/sonic-cfggen -d -y /etc/sonic/sonic_version.yml -t /usr/share/sonic/templates/sonic-environment.j2,/etc/sonic/sonic-environment
Restarting SONiC target ...
Enabling container and routeCheck monitoring ...
Reloading Monit configuration ...
Reinitializing monit daemon
Released lock on /etc/sonic/reload.lock

real    0m22.324s
user    0m1.388s
sys     0m0.361s

After:

$ time sudo config reload -y -f                                                                                                                                                                                                       
Acquired lock on /etc/sonic/reload.lock                                                                                                                                                                                                                   
Disabling container and routeCheck monitoring ...                                                                                                                                                                                                         
Stopping SONiC target ...                                                                                                                                                                                                                                 
Running command: /usr/local/bin/sonic-cfggen -j /etc/sonic/init_cfg.json -j /etc/sonic/config_db.json --write-to-db                                                                                                                                       
Running command: /usr/local/bin/db_migrator.py -o migrate                                                                                                                                                                                                 
Running command: /usr/local/bin/sonic-cfggen -d -y /etc/sonic/sonic_version.yml -t /usr/share/sonic/templates/sonic-environment.j2,/etc/sonic/sonic-environment                                                                                           
Restarting SONiC target ...                                                                                                                                                                                                                               
Enabling container and routeCheck monitoring ...                                                                                                                                                                                                          
Reloading Monit configuration ...                                                                                            
Reinitializing monit daemon                                                                                                  
Released lock on /etc/sonic/reload.lock                                                                                      
                                                                                                                             
real    0m20.811s                                                                                                            
user    0m1.367s                                                                                                             
sys     0m0.361s

Defined read only cache decorator after logger setup.
Cached return values of static get methods to reduce EEPROM reads.
Add unit tests.

Signed-off-by: Jianyue Wu <jianyuew@nvidia.com>
@jianyuewu
Copy link
Author

@microsoft-github-policy-service agree [company="{your company}"]

@microsoft-github-policy-service agree [company="Nvidia"]

@jianyuewu
Copy link
Author

@microsoft-github-policy-service agree company="Nvidia"

jianyuewu added 2 commits May 22, 2025 14:29
Signed-off-by: Jianyue Wu <jianyuew@nvidia.com>
Signed-off-by: Jianyue Wu <jianyuew@nvidia.com>
@r12f r12f merged commit 6d30299 into Azure:202412 Jun 18, 2025
3 checks passed
@r12f
Copy link

r12f commented Jun 18, 2025

Original PR: sonic-net/sonic-platform-common#562

mssonicbld added a commit that referenced this pull request Jun 19, 2025
```<br>* 1ebe56e - (HEAD -> 202503) Merge branch '202412' of https://github.com/Azure/sonic-platform-common.msft into 202503 (2025-06-19) [Sonic Automation]
* 6d30299 - (base/202412) [202412] [cmis] add read only cache decorator (#86) (2025-06-18) [Jianyue Wu]<br>```
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.

2 participants