Skip to content

Counter optimization all in one#22

Closed
stephenxs wants to merge 4 commits intomasterfrom
counter-optimization-all-in-one
Closed

Counter optimization all in one#22
stephenxs wants to merge 4 commits intomasterfrom
counter-optimization-all-in-one

Conversation

@stephenxs
Copy link
Owner

@stephenxs stephenxs commented Oct 29, 2024

What I did

Optimize the counter-polling performance in terms of polling interval accuracy

  1. Enable bulk counter-polling to run at a smaller chunk size
    There is one counter-polling thread for each counter group. All such threads can compete for the critical sections at the vendor SAI level, which means a counter-polling thread can wait for a critical section if another thread has been in it, which introduces latency for the waiting counter group.
    An example is the competition between the PFC watchdog and the port counter groups.
    The port counter group contains many counters and is polled in a bulk mode which takes a relatively longer time. The PFC watchdog counter group contains only a few counters but is polled at a short interval. Sometimes, PFC watchdog counters need to wait before polling, which makes the polling interval inaccurate and prevents the PFC storm from being detected in time.
    To resolve this issue, we can reduce the chunk size of the port counter group. The port counter group polls the counters of all ports in a single bulk operation by default. By using a smaller chunk size, it polls the counters in several bulk operations with each polling counter of a subset (whose size <= chunk size) of all ports.
    By doing so, the port counter group stays in the critical section for a shorter time and the PFC watchdog is more likely to be scheduled to poll counters and detect the PFC storm in time.

  2. Collect the time stamp immediately after vendor SAI API returns.
    Currently, many counter groups require a Lua plugin to execute based on polling interval, to calculate rates, detect certain events, etc.
    Eg. For PFC watchdog counter group to PFC storm. In this case, the polling interval is calculated based on the difference of time stamps between the current and last poll to avoid deviation due to scheduling latency. However, the timestamp is collected in the Lua plugin which is several steps after the SAI API returns and is executed in a different context (redis-server). Both introduce even larger deviations. To overcome this, we collect the timestamp immediately after the SAI API returns.

Why I did it

How I verified it

Run regression test and observe counter-polling performance.

A comparison test shows very good results if we put any/or all of the above optimizations.

Details if related

For 2, each counter group contains more than one counter context based on the type of objects. counter context is mapped from (group, object type). But the counters fetched from different counter groups will be pushed into the same entry for the same objects.
eg. PFC_WD group contains counters of ports and queues. PORT group contains counters of ports. QUEUE_STAT group contains counters of queues.
Both PFC_WD and PORT groups will push counter data into an item representing a port. but each counter has its own polling interval, which means counter IDs polled from different counter groups can be polled with different time stamps.
We use the name of a counter group to identify the time stamp of the counter group.
Eg. In port counter entry, PORT_timestamp represents last time when the port counter group polls the counters. PFC_WD_timestamp represents the last time when the PFC watchdog counter group polls the counters

@stephenxs
Copy link
Owner Author

ci 4546 passed

@stephenxs stephenxs force-pushed the counter-optimization-all-in-one branch from 2d6796b to c14fd22 Compare November 8, 2024 14:35
@stephenxs stephenxs force-pushed the counter-optimization-all-in-one branch from c14fd22 to 6b362f6 Compare November 18, 2024 02:15
Signed-off-by: Stephen Sun <stephens@nvidia.com>
Signed-off-by: Stephen Sun <stephens@nvidia.com>
Signed-off-by: Stephen Sun <stephens@nvidia.com>
Signed-off-by: Stephen Sun <stephens@nvidia.com>
@stephenxs stephenxs force-pushed the counter-optimization-all-in-one branch from 6b362f6 to b82e233 Compare November 25, 2024 12:06
@stephenxs stephenxs closed this Nov 25, 2024
stephenxs pushed a commit that referenced this pull request Feb 27, 2025
…#22)

```<br>* aa1add1f - (HEAD -> 202412) Merge branch '202411' of https://github.com/sonic-net/sonic-sairedis into 202412 (2025-02-25) [Sonic Automation]
* d884ff9 - (origin/202411) [syncd] Move logSet logGet under mutex to prevent race condition (sonic-net#1520) (sonic-net#1538) (2025-02-20) [Kamil Cudnik]
* ec8b3c3 - Fix pipeline errors related to rsyslogd and libswsscommon installation (sonic-net#1535) (2025-02-19) [mssonicbld]
* 6b263b8 - [FC] Support Policer Counter (sonic-net#1533) (2025-02-19) [mssonicbld]
* e53489e - [syncd] Update log level for bulk api (sonic-net#1532) (2025-02-18) [Jianyue Wu]
* 7ae00e5 - Define bulk chunk size and bulk chunk size per counter ID (sonic-net#1528) (2025-02-11) [mssonicbld]
* f35e743 - [nvidia] Skip SAI discovery on ports (sonic-net#1524) (2025-02-07) [mssonicbld]
* bf049ed - Use sonictest pool instead of sonic-common and fix arm64 issue. (sonic-net#1516) (2025-02-05) [mssonicbld]
* ffe371d - [syncd] Support bulk set in INIT_VIEW mode (sonic-net#1517) (2025-02-05) [mssonicbld]<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