{"id":2065,"date":"2025-07-24T07:56:20","date_gmt":"2025-07-24T07:56:20","guid":{"rendered":"https:\/\/www.nicktailor.com\/?p=2065"},"modified":"2025-07-24T09:24:41","modified_gmt":"2025-07-24T09:24:41","slug":"complete-latency-troubleshooting-command-reference","status":"publish","type":"post","link":"https:\/\/nicktailor.com\/tech-blog\/complete-latency-troubleshooting-command-reference\/","title":{"rendered":"Complete Latency Troubleshooting Command Reference"},"content":{"rendered":"<div style=\"background-color: #f8f9fa; border-left: 4px solid #3498db; padding: 20px; margin: 20px 0; border-radius: 0 6px 6px 0;\">\n<p><strong>How to Read This Guide:<\/strong> Each command shows the actual output you&#8217;ll see on your system. The green\/red examples below each command show real outputs &#8211; green means your system is optimized for low latency, red means there are problems that will cause latency spikes. Compare your actual output to these examples to quickly identify issues.<\/p>\n<p>SECRET SAUCE: I did write a bash script that does all this analysing for you awhile back. Been meaning to push to my repos.<\/p>\n<p>Its sitting in one my 1000&#8217;s of text files of how to do&#8217;s. \ud83d\ude01. Im sure you all have those&#8230;..more to come&#8230;<\/p>\n<\/div>\n<h2 style=\"color: #2c3e50; margin-top: 40px; margin-bottom: 20px; font-size: 1.5em;\">System Information Commands<\/h2>\n<h3 style=\"color: #34495e; margin-top: 30px; margin-bottom: 15px; font-size: 1.2em;\">uname -a<\/h3>\n<pre style=\"background-color: #f5f5f5; border: 1px solid #ddd; border-radius: 6px; padding: 16px; margin: 20px 0; overflow-x: auto; font-family: 'Courier New', Consolas, monospace; font-size: 14px; line-height: 1.4;\"><code>uname -a<\/code><\/pre>\n<p><strong>Flags:<\/strong><\/p>\n<ul>\n<li><code style=\"background-color: #f5f5f5; padding: 2px 6px; border-radius: 3px; font-family: 'Courier New', Consolas, monospace; font-size: 14px;\">-a<\/code>: Print all system information<\/li>\n<\/ul>\n<p><strong>Example Output:<\/strong><\/p>\n<pre style=\"background-color: #f5f5f5; border: 1px solid #ddd; border-radius: 6px; padding: 16px; margin: 20px 0; overflow-x: auto; font-family: 'Courier New', Consolas, monospace; font-size: 14px; line-height: 1.4;\"><code>Linux trading-server 5.15.0-rt64 #1 SMP PREEMPT_RT Thu Mar 21 13:30:15 UTC 2024 x86_64 x86_64 x86_64 GNU\/Linux<\/code><\/pre>\n<p><strong>What to look for:<\/strong> <code style=\"background-color: #f5f5f5; padding: 2px 6px; border-radius: 3px; font-family: 'Courier New', Consolas, monospace; font-size: 14px;\">PREEMPT_RT<\/code> indicates real-time kernel is active<\/p>\n<div style=\"background-color: #f8f9fa; border-left: 4px solid #6c757d; padding: 10px; margin: 10px 0; font-family: monospace;\"><span style=\"color: #27ae60; font-weight: bold;\">\u2713 GOOD OUTPUT (real-time kernel):<\/span><br \/>\n<code style=\"background-color: transparent; font-family: 'Courier New', Consolas, monospace;\">Linux server 5.15.0-rt64 #1 SMP PREEMPT_RT Thu Mar 21 13:30:15 UTC 2024<\/code><br \/>\n<small>Shows &#8220;PREEMPT_RT&#8221; = real-time kernel for predictable latency<br \/>\n<\/small><span style=\"color: #e74c3c; font-weight: bold;\">\u2717 BAD OUTPUT (standard kernel):<\/span><br \/>\n<code style=\"background-color: transparent; font-family: 'Courier New', Consolas, monospace;\">Linux server 5.15.0-generic #1 SMP Thu Mar 21 13:30:15 UTC 2024<\/code><br \/>\n<small>Shows &#8220;generic&#8221; with no &#8220;PREEMPT_RT&#8221; = standard kernel with unpredictable latency<\/small><\/div>\n<hr \/>\n<h2 style=\"color: #2c3e50; margin-top: 40px; margin-bottom: 20px; font-size: 1.5em;\">Performance Profiling Commands<\/h2>\n<h3 style=\"color: #34495e; margin-top: 30px; margin-bottom: 15px; font-size: 1.2em;\">perf stat<\/h3>\n<pre style=\"background-color: #f5f5f5; border: 1px solid #ddd; border-radius: 6px; padding: 16px; margin: 20px 0; overflow-x: auto; font-family: 'Courier New', Consolas, monospace; font-size: 14px; line-height: 1.4;\"><code>perf stat [options] [command]<\/code><\/pre>\n<p><strong>Key flags:<\/strong><\/p>\n<ul>\n<li><code style=\"background-color: #f5f5f5; padding: 2px 6px; border-radius: 3px; font-family: 'Courier New', Consolas, monospace; font-size: 14px;\">-e &lt;events&gt;<\/code>: Specific events to count<\/li>\n<li><code style=\"background-color: #f5f5f5; padding: 2px 6px; border-radius: 3px; font-family: 'Courier New', Consolas, monospace; font-size: 14px;\">-a<\/code>: Monitor all CPUs<\/li>\n<li><code style=\"background-color: #f5f5f5; padding: 2px 6px; border-radius: 3px; font-family: 'Courier New', Consolas, monospace; font-size: 14px;\">-p &lt;pid&gt;<\/code>: Monitor specific process<\/li>\n<\/ul>\n<p><strong>Example Usage &amp; Output:<\/strong><\/p>\n<pre style=\"background-color: #f5f5f5; border: 1px solid #ddd; border-radius: 6px; padding: 16px; margin: 20px 0; overflow-x: auto; font-family: 'Courier New', Consolas, monospace; font-size: 14px; line-height: 1.4;\"><code>perf stat -e cycles,instructions,cache-misses,branch-misses .\/trading_app\n\n Performance counter stats for '.\/trading_app':\n\n     4,234,567,890      cycles                    #    3.456 GHz\n     2,987,654,321      instructions              #    0.71  insn per cycle\n        45,678,901      cache-misses              #   10.789 % of all cache refs\n         5,432,109      branch-misses             #    0.234 % of all branches<\/code><\/pre>\n<p><strong>What to look for:<\/strong> Instructions per cycle (should be &gt;1), cache miss rate (&lt;5% is good), branch miss rate (&lt;1% is good)<\/p>\n<div style=\"background-color: #f8f9fa; border-left: 4px solid #6c757d; padding: 10px; margin: 10px 0; font-family: monospace;\"><span style=\"color: #27ae60; font-weight: bold;\">\u2713 GOOD OUTPUT:<\/span><br \/>\n<code style=\"background-color: transparent; font-family: 'Courier New', Consolas, monospace;\">2,987,654,321      instructions              #    2.15  insn per cycle<br \/>\n45,678,901      cache-misses              #    3.2 % of all cache refs<br \/>\n5,432,109      branch-misses             #    0.8 % of all branches<br \/>\n<small><strong>Why:<\/strong> <span style=\"color: #27ae60; font-weight: bold;\">Good<\/span> = &gt;2.0 IPC (CPU efficient), &lt;5% cache misses, &lt;1% branch misses.<\/p>\n<p><\/small><\/code><span style=\"color: #e74c3c; font-weight: bold;\">\u2717 BAD OUTPUT:<\/span><br \/>\n<code style=\"background-color: transparent; font-family: 'Courier New', Consolas, monospace;\">1,234,567,890      instructions              #    0.65  insn per cycle<br \/>\n156,789,012      cache-misses              #   15.7 % of all cache refs<br \/>\n89,432,109      branch-misses             #    4.2 % of all branches<\/code><br \/>\n<small><code style=\"background-color: transparent; font-family: 'Courier New', Consolas, monospace;\"><small><strong>Why:<\/strong><\/small><\/code>\u00a0<span style=\"color: #e74c3c; font-weight: bold;\">Bad<\/span> = &lt;1.0 IPC (CPU starved), &gt;10% cache misses, &gt;4% branch misses.<\/small><\/div>\n<hr \/>\n<h2 style=\"color: #2c3e50; margin-top: 40px; margin-bottom: 20px; font-size: 1.5em;\">eBPF Tools<\/h2>\n<div style=\"background-color: #fff3cd; border: 1px solid #ffeaa7; border-radius: 6px; padding: 15px; margin: 20px 0;\">\n<p><strong style=\"color: #856404;\">Note:<\/strong> eBPF tools are part of the BCC toolkit. Install once with: <code style=\"background-color: #f5f5f5; padding: 2px 6px; border-radius: 3px; font-family: 'Courier New', Consolas, monospace; font-size: 14px;\">sudo apt-get install bpfcc-tools linux-headers-$(uname -r)<\/code> (Ubuntu) or <code style=\"background-color: #f5f5f5; padding: 2px 6px; border-radius: 3px; font-family: 'Courier New', Consolas, monospace; font-size: 14px;\">sudo yum install bcc-tools<\/code> (RHEL\/CentOS). After installation, these become system-wide commands.<\/p>\n<\/div>\n<h3 style=\"color: #34495e; margin-top: 30px; margin-bottom: 15px; font-size: 1.2em;\">funclatency<\/h3>\n<pre style=\"background-color: #f5f5f5; border: 1px solid #ddd; border-radius: 6px; padding: 16px; margin: 20px 0; overflow-x: auto; font-family: 'Courier New', Consolas, monospace; font-size: 14px; line-height: 1.4;\"><code>sudo funclatency [options] 'function_pattern'<\/code><\/pre>\n<p><strong>Key flags:<\/strong><\/p>\n<ul>\n<li><code style=\"background-color: #f5f5f5; padding: 2px 6px; border-radius: 3px; font-family: 'Courier New', Consolas, monospace; font-size: 14px;\">-p &lt;pid&gt;<\/code>: Trace specific process<\/li>\n<li><code style=\"background-color: #f5f5f5; padding: 2px 6px; border-radius: 3px; font-family: 'Courier New', Consolas, monospace; font-size: 14px;\">-u<\/code>: Show in microseconds instead of nanoseconds<\/li>\n<\/ul>\n<p><strong>Example Output:<\/strong><\/p>\n<pre style=\"background-color: #f5f5f5; border: 1px solid #ddd; border-radius: 6px; padding: 16px; margin: 20px 0; overflow-x: auto; font-family: 'Courier New', Consolas, monospace; font-size: 14px; line-height: 1.4;\"><code>sudo funclatency 'c:malloc' -p 1234 -u\n\n     usecs               : count     distribution\n         0 -&gt; 1          : 1234     |****************************************|\n         2 -&gt; 3          : 567      |******************                      |\n         4 -&gt; 7          : 234      |*******                                 |\n         8 -&gt; 15         : 89       |**                                      |\n        16 -&gt; 31         : 23       |                                        |\n        32 -&gt; 63         : 5        |                                        |<\/code><\/pre>\n<p><strong>What to look for:<\/strong> Long tail distributions indicate inconsistent performance<\/p>\n<div style=\"background-color: #f8f9fa; border-left: 4px solid #6c757d; padding: 10px; margin: 10px 0; font-family: monospace;\"><span style=\"color: #27ae60; font-weight: bold;\">\u2713 GOOD OUTPUT (consistent performance):<\/span><br \/>\n<code style=\"background-color: transparent; font-family: 'Courier New', Consolas, monospace;\"><br \/>\nusecs               : count     distribution<br \/>\n0 -&gt; 1          : 4567     |****************************************|<br \/>\n2 -&gt; 3          : 234      |**                                      |<br \/>\n4 -&gt; 7          : 12       |                                        |<br \/>\n<\/code><small><strong>Why:<\/strong> <span style=\"color: #27ae60; font-weight: bold;\">Good<\/span> shows 95%+ calls in 0-3\u03bcs (predictable).<\/p>\n<p><\/small><span style=\"color: #e74c3c; font-weight: bold;\">\u2717 BAD OUTPUT (inconsistent performance):<\/span><br \/>\n<code style=\"background-color: transparent; font-family: 'Courier New', Consolas, monospace;\">usecs               : count     distribution<br \/>\n0 -&gt; 1          : 1234     |******************                      |<br \/>\n2 -&gt; 3          : 567      |********                                |<br \/>\n4 -&gt; 7          : 234      |***                                     |<br \/>\n8 -&gt; 15         : 189      |**                                      |<br \/>\n16 -&gt; 31         : 89       |*                                       |<br \/>\n32 -&gt; 63         : 45       |                                        |<br \/>\n<\/code><br \/>\n<small><\/small><small><strong>Why:<\/strong><\/small>\u00a0<span style=\"color: #e74c3c; font-weight: bold;\">Bad<\/span> shows calls scattered across many latency ranges (unpredictable).<\/div>\n<hr \/>\n<h2 style=\"color: #2c3e50; margin-top: 40px; margin-bottom: 20px; font-size: 1.5em;\">Network Monitoring Commands<\/h2>\n<h3 style=\"color: #34495e; margin-top: 30px; margin-bottom: 15px; font-size: 1.2em;\">netstat -i<\/h3>\n<pre style=\"background-color: #f5f5f5; border: 1px solid #ddd; border-radius: 6px; padding: 16px; margin: 20px 0; overflow-x: auto; font-family: 'Courier New', Consolas, monospace; font-size: 14px; line-height: 1.4;\"><code>netstat -i<\/code><\/pre>\n<p><strong>Example Output:<\/strong><\/p>\n<pre style=\"background-color: #f5f5f5; border: 1px solid #ddd; border-radius: 6px; padding: 16px; margin: 20px 0; overflow-x: auto; font-family: 'Courier New', Consolas, monospace; font-size: 14px; line-height: 1.4;\"><code>Kernel Interface table\nIface      MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg\neth0      1500  1234567      0      0 0       987654      0      0      0 BMRU\nlo       65536    45678      0      0 0        45678      0      0      0 LRU<\/code><\/pre>\n<p><strong>What to look for:<\/strong><\/p>\n<ul>\n<li><strong>RX-ERR, TX-ERR<\/strong>: Hardware errors<\/li>\n<li><strong>RX-DRP, TX-DRP<\/strong>: Dropped packets (buffer overruns)<\/li>\n<li><strong>RX-OVR, TX-OVR<\/strong>: FIFO overruns<\/li>\n<\/ul>\n<div style=\"background-color: #f8f9fa; border-left: 4px solid #6c757d; padding: 10px; margin: 10px 0; font-family: monospace;\"><span style=\"color: #27ae60; font-weight: bold;\">\u2713 GOOD OUTPUT:<\/span><br \/>\n<code style=\"background-color: transparent; font-family: 'Courier New', Consolas, monospace;\">eth0    1500  1234567      0      0 0     987654      0      0      0 BMRU<br \/>\n<small><strong>Why:<\/strong> <span style=\"color: #27ae60; font-weight: bold;\">Good<\/span> = all error\/drop counters are 0.<\/small><\/code><\/p>\n<p><span style=\"color: #e74c3c; font-weight: bold;\">\u2717 BAD OUTPUT:<\/span><br \/>\n<code style=\"background-color: transparent; font-family: 'Courier New', Consolas, monospace;\">eth0    1500  1234567      5   1247 23    987654     12     89      7 BMRU<\/code><br \/>\n<small><span style=\"color: #e74c3c; font-weight: bold;\"><br \/>\n<code style=\"background-color: transparent; font-family: 'Courier New', Consolas, monospace;\"><small><strong>Why:<\/strong><\/small><\/code>Bad<\/span> = RX-ERR=5, RX-DRP=1247, TX-ERR=12, TX-DRP=89 means network problems causing packet loss and latency spikes.<\/small><\/div>\n<hr \/>\n<h2 style=\"color: #2c3e50; margin-top: 40px; margin-bottom: 20px; font-size: 1.5em;\">CPU and Memory Analysis<\/h2>\n<h3 style=\"color: #34495e; margin-top: 30px; margin-bottom: 15px; font-size: 1.2em;\">vmstat 1<\/h3>\n<pre style=\"background-color: #f5f5f5; border: 1px solid #ddd; border-radius: 6px; padding: 16px; margin: 20px 0; overflow-x: auto; font-family: 'Courier New', Consolas, monospace; font-size: 14px; line-height: 1.4;\"><code>vmstat [delay] [count]<\/code><\/pre>\n<p><strong>Example Output:<\/strong><\/p>\n<pre style=\"background-color: #f5f5f5; border: 1px solid #ddd; border-radius: 6px; padding: 16px; margin: 20px 0; overflow-x: auto; font-family: 'Courier New', Consolas, monospace; font-size: 14px; line-height: 1.4;\"><code>procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----\n r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st\n 1  0      0 789456  12345 234567    0    0     0     5 1234 2345  5  2 93  0  0\n 0  0      0 789234  12345 234678    0    0     0     0 1456 2567  3  1 96  0  0<\/code><\/pre>\n<p><strong>What to look for:<\/strong><\/p>\n<ul>\n<li><strong>r<\/strong>: Running processes (should be \u2264 CPU count)<\/li>\n<li><strong>si\/so<\/strong>: Swap in\/out (should be 0)<\/li>\n<li><strong>cs<\/strong>: Context switches per second (lower is better for latency)<\/li>\n<li><strong>wa<\/strong>: I\/O wait percentage (should be low)<\/li>\n<\/ul>\n<div style=\"background-color: #f8f9fa; border-left: 4px solid #6c757d; padding: 10px; margin: 10px 0; font-family: monospace;\"><span style=\"color: #27ae60; font-weight: bold;\">\u2713 GOOD OUTPUT (8-CPU system):<\/span><br \/>\n<code style=\"background-color: transparent; font-family: 'Courier New', Consolas, monospace;\">procs -----memory------ ---swap-- --system-- ------cpu-----<br \/>\nr  b   si   so    in   cs us sy id wa st<br \/>\n2  0    0    0  1234 2345  5  2 93  0  0<br \/>\n<small><strong>Why:<\/strong> <span style=\"color: #27ae60; font-weight: bold;\">Good<\/span>: r=2 (\u22648 CPUs), si\/so=0 (no swap), cs=2345 (low context switches), wa=0 (no I\/O wait).<\/p>\n<p><\/small><\/code><span style=\"color: #e74c3c; font-weight: bold;\">\u2717 BAD OUTPUT (8-CPU system):<\/span><br \/>\n<code style=\"background-color: transparent; font-family: 'Courier New', Consolas, monospace;\">procs -----memory------ ---swap-- --system-- ------cpu-----<br \/>\nr  b   si   so    in   cs us sy id wa st<br \/>\n12  1   45   67 8234 15678 85  8  2 15  0<\/code><br \/>\n<small><code style=\"background-color: transparent; font-family: 'Courier New', Consolas, monospace;\"><small><strong>Why<\/strong><\/small><\/code>\u00a0<span style=\"color: #e74c3c; font-weight: bold;\">Bad<\/span>: r=12 (&gt;8 CPUs = overloaded), si\/so&gt;0 (swapping = latency spikes), cs=15678 (high context switches), wa=15 (I\/O blocked).<\/small><\/div>\n<hr \/>\n<h2 style=\"color: #2c3e50; margin-top: 40px; margin-bottom: 20px; font-size: 1.5em;\">Interpreting the Results<\/h2>\n<div style=\"background-color: #d4edda; border: 1px solid #c3e6cb; border-radius: 6px; padding: 15px; margin: 20px 0;\">\n<h3>Good Latency Indicators:<\/h3>\n<ul>\n<li>perf stat: &gt;2.0 instructions per cycle<\/li>\n<li>Cache misses: &lt;5% of references<\/li>\n<li>Branch misses: &lt;1% of branches<\/li>\n<li>Context switches: &lt;1000\/sec per core<\/li>\n<li>IRQ latency: &lt;10 microseconds<\/li>\n<li>Run queue length: Mostly 0<\/li>\n<li>No swap activity (si\/so = 0)<\/li>\n<li>CPUs at max frequency<\/li>\n<li>Temperature &lt;80\u00b0C<\/li>\n<\/ul>\n<\/div>\n<div style=\"background-color: #f8d7da; border: 1px solid #f5c6cb; border-radius: 6px; padding: 15px; margin: 20px 0;\">\n<h3>Red Flags:<\/h3>\n<ul>\n<li>Instructions per cycle &lt;1.0<\/li>\n<li>Cache miss rate &gt;10%<\/li>\n<li>High context switch rate (&gt;10k\/sec)<\/li>\n<li>IRQ processing &gt;50us<\/li>\n<li>Consistent run queue length &gt;1<\/li>\n<li>Any swap activity<\/li>\n<li>CPU frequency scaling active<\/li>\n<li>Memory fragmentation (no high-order pages)<\/li>\n<li>Thermal throttling events<\/li>\n<\/ul>\n<\/div>\n<p>This reference guide provides the foundation for systematic latency troubleshooting &#8211; use the baseline measurements to identify problematic areas, then dive deeper with the appropriate tools!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to Read This Guide: Each command shows the actual output you&#8217;ll see on your system. The green\/red examples below each command show real outputs &#8211; green means your system is optimized for low latency, red means there are problems that will cause latency spikes. Compare your actual output to these examples to quickly identify issues. SECRET SAUCE: I did<a href=\"https:\/\/nicktailor.com\/tech-blog\/complete-latency-troubleshooting-command-reference\/\" class=\"read-more\">Read More &#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[52,138],"tags":[],"class_list":["post-2065","post","type-post","status-publish","format-standard","hentry","category-kernel-stuff","category-linux"],"_links":{"self":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts\/2065","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/comments?post=2065"}],"version-history":[{"count":18,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts\/2065\/revisions"}],"predecessor-version":[{"id":2095,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts\/2065\/revisions\/2095"}],"wp:attachment":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/media?parent=2065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/categories?post=2065"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/tags?post=2065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}