Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Speed up MBUF Usage command in system information widget #4703

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GChuf
Copy link
Contributor

@GChuf GChuf commented Oct 12, 2024

$mbuf = "{$mbufs_total}/{$mbufs_max}";
$mbufpercent = ($mbufs_max > 0) ? round(($mbufs_total / $mbufs_max) * 100, 0) : "NA";
function get_mbuf() {
$mbufs_output=trim(`/usr/bin/vmstat -z | /usr/bin/grep mbuf_cluster | /usr/bin/grep -v debugnet | /usr/bin/awk '{print $3,$4,$5}'`);
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not work properly in several cases. The output is not guaranteed to have spaces between columns.

For example:

: /usr/bin/vmstat -z | /usr/bin/grep mbuf_cluster | /usr/bin/grep -v debugnet 
mbuf_cluster:          2048,1000000,   12028,    1434,  144434,   0,   0,   0

: /usr/bin/vmstat -z | /usr/bin/grep mbuf_cluster | /usr/bin/grep -v debugnet | /usr/bin/awk '{print $3,$4,$5}'
12027, 1435, 144434,

If you want to try going that route, call vmstat -z --libxo=json and process that output to find the exact values you want accurately. Or to narrow that a bit:

: /usr/bin/vmstat -z --libxo=json | /usr/local/bin/jq '."memory-zone-statistics".zone.[] | select(.name=="mbuf_cluster")'
{
  "name": "mbuf_cluster",
  "size": 2048,
  "limit": 1000000,
  "used": 12028,
  "free": 1434,
  "requests": 144620,
  "fail": 0,
  "sleep": 0,
  "xdomain": 0
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, you're right - I noticed this one when testing but the fix slipped away somewhere in between the testing and commiting.
One idea was to use comma delimiter with awk, but then whitespaces become potentially problematic (output needs to be trimmed). I'll take a look at json output and try to find the cleanest/fastest solution.

@GChuf GChuf force-pushed the mbufFunctionOptimize branch from 3517da1 to a070c8d Compare October 22, 2024 20:32
@GChuf
Copy link
Contributor Author

GChuf commented Oct 22, 2024

Updated the code.
It might not look as clean. I'm using sub(/^ +/, "", $2) to cleanup leading whitespaces, and I'm using comma as delimiter for awk.

The other option was:
/usr/bin/vmstat -z --libxo=json | /usr/local/bin/jq -r '."memory-zone-statistics".zone.[] | select(.name=="mbuf_cluster") | "\(.total) \(.used) \(.free)"'
After testing on my system, using json and jq was approximately twice slower (but both options are fast).

@jim-p
Copy link
Contributor

jim-p commented Apr 4, 2025

The libxo method is necessary to ensure accuracy, and is the only method that will be accepted. Anything else is just guessing and making assumptions about the format which could be wrong. It would require a lot more testing on a lot more hardware/networks when all such concerns are eliminated by using libxo which is designed for this purpose.

@GChuf GChuf force-pushed the mbufFunctionOptimize branch from a070c8d to 9838dd5 Compare April 6, 2025 12:46
@GChuf
Copy link
Contributor Author

GChuf commented Apr 6, 2025

Understood - changed the code.
Using this now:
/usr/bin/vmstat -z --libxo=json | /usr/local/bin/jq -r '."memory-zone-statistics".zone.[] | select(.name=="mbuf_cluster") | "\(.limit) \(.used) \(.free)"'

@GChuf GChuf requested a review from jim-p April 6, 2025 12:50
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