Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
docs:guide-user:network:traffic-shaping:sqm [2019/03/11 20:22] – add required update before installing a package gionndocs:guide-user:network:traffic-shaping:sqm [2024/05/10 14:52] – remove a dead link, and small language tweaks palebloodsky
Line 1: Line 1:
-====== Smart Queue Management (SQM- Minimizing Bufferbloat ======+====== SQM (Smart Queue Management) ======
  
-OpenWrt/LEDE has pre-built packages for controlling Bufferbloat - the undesirable latency that arises when the router buffers too much data.  +OpenWrt has a package called SQM for mitigating [[wp>bufferbloat]], the undesirable latency that arises when your router buffers too much data.
-OpenWrt calls this SQM, although it's also called "active queue management" - AQM.+
  
-Bufferbloat is most evident when the link is heavily loaded. It causes bad performance for voice and video conversations, causes gamers to lag out, and generally makes people say, "The Internet is slow today."+Install ''[[:packages:pkgdata:luci-app-sqm|luci-app-sqm]]'' (or ''[[:packages:pkgdata:sqm-scripts|sqm-scripts]]'' if you don't use LuCI) and read below.
  
-The "luci-app-sqm" package of OpenWrt/LEDE solves the problem of Bufferbloat. In a three-minute installation and configuration, you'll have a much more lively network connection. Here's how:+===== Overview =====
  
-**TL;DR** Install OpenWrt 18.06 or newer (or back to LEDE 17.01), and follow the video at: https://www.youtube.com/watch?v=FvYhifdQ92Q+Bufferbloat is most evident when a connection is heavily loaded with downloads or uploadsIt causes increased latency (ping), resulting in poor performance for realtime apps like VoIP, video chat, lag in online games, and generally makes the internet feel unresponsiveThis can be mitigated with SQM.
  
-===== Preparation: Measure Your Current Speed and Latency ===== +SQM is an integrated system that performs per-packet/per-flow network scheduling, active queue management (AQM), traffic shaping, rate limiting, and QoS prioritization. In comparison, “classic” AQM only manages queue length and “classic” QoS only does prioritization.
  
-Before you can optimize your network, you need to know its current stateRun a speed test to find your down/upload link speeds.  +SQM is heavily CPU dependentSlower devices may not be able to [[https://forum.openwrt.org/t/so-you-have-500mbps-1gbps-fiber-and-need-a-router-read-this-first/90305|keep up]] with your connection speed.
-  - When your network is relatively quiet, use DSLReports Speedtest at: http://www.dslreports.com/speedtest You will need this information below. (See [[https://forum.openwrt.org/t/sqm-qos-recommended-settings-for-the-dslreports-speedtest-bufferbloat-testing/2803]] for how to get the most out of the dslreports speedtest) +
-  This is probably a good time to [[docs:guide-user:troubleshooting:backingup|Back up your Configuration]]. (Optional, but always a good idea.) +
-  +
-===== Installing the SQM Bufferbloat Packages =====+
  
-Install the //luci-app-sqm// package. Watch the [[https://youtu.be/FvYhifdQ92Q|Youtube Video]] that shows these steps:+SQM is incompatible with software/hardware [[https://www.redhat.com/en/blog/should-i-offload-my-networking-hardware-look-hardware-offloading|flow offloading]] which bypasses part of the network stack. Be sure to uncheck those features in LuCI -> Firewall to use SQM.
  
-  - Uninstall //qos-scripts// and //luci-app-qos// if they are installed.  +===== Preparation: Measure Your Current Speed and Latency =====
-    - From LuCI web GUI:  +
-      * choose **System -> Software**, then scroll down the list in the Installed Packages tab.  +
-      * click **Remove** if either of these scripts is installed. +
-    - From cmd: <code>opkg remove qos-scripts luci-app-qos</code> +
-  - Install the //luci-app-sqm// package. It will automatically install other required packages. To do this: +
-    - From LuCI web GUI:  +
-      * go to **System -> Software**, then click **Update Lists** +
-      * click the **Available packages** tab, and find //luci-app-sqm//. Click **Install** +
-    - From cmd: <code>opkg update && opkg install luci-app-sqm</code> +
-  - Start and Enable the SQM scripts. To do this, choose **System -> Startup** +
-    - From LuCI web GUI:  +
-      * click Start to start the SQM process +
-      * click Enable to start the SQM process when the route reboots +
-    - From cmd: <code>/etc/init.d/sqm start; /etc/init.d/sqm enable</code> +
-===== Configuring the SQM Bufferbloat Packages =====+
  
-The default values described below work quite well for most situations. They represent conservative estimates that may slightly overestimate the real overheadwhich is generally desirable compared to under-estimatingYou may be able to improve performance by experimenting with settingssee [[#a_little_about_tuning_sqm|A little about tuning SQM]] below.+Before you can optimize your networkyou need to know its current stateWhen your internet is quiet, run a speed test to find your peak download/upload speeds: 
 +  * Run a speed test from [[https://www.waveform.com/tools/bufferbloat|Waveform]] or [[https://speedtest.net|Speedtest]]. Both display the latency during download and upload trafficand grade your existing bufferbloat. 
 +  * If you are using this OpenWrt device as an [[docs:guide-user:network:wifi:relay_configuration|Extender, Repeater, or Bridge]], test your upstream router (OpenWrt or otherwise) and determine if an issue is present there first.
  
-To configure SQM, choose **Network -> SQM QoS** to see the Smart Queue Management (SQM) GUI.+===== Configuration ===== 
 + 
 +In LuCI go to **Network -> SQM QoS**. The default settings will work, however you can improve performance with settings specific to your internet connection as described below:
  
   - In the **Basic Settings** tab:   - In the **Basic Settings** tab:
     * Check the **Enable** box     * Check the **Enable** box
-    * Set the **Interface name:** to your wide area link (usually //eth0// for OpenWrt/LEDEbut check **Network -> Interfaces** to find the name for the WAN port.) +    * Set the **Interface name** to your internet (WAN) link. Interfaces are listed in the dropdownor check **Network -> Interfaces** to find the WAN port. 
-    * Set the **Download** and **Upload** speeds to 80-95% of the speed you measured above in the Preparation. +    * Set the **Download** and **Upload** speeds to 90% of what you measured in Preparation 
-  - In the **Queue Discipline** tab, you can leave the settings at their default. +  - In the **Queue Discipline** tab: 
-    * Choose //cake// as the Queueing Discipline+    * Choose //cake// as the Queueing Discipline (or //fq_codel//, consider [[:docs:guide-user:network:traffic-shaping:sqm#a_little_more_sqm_tuning|note 2]])
     * Choose //piece_of_cake.qos// as the Queue Setup Script     * Choose //piece_of_cake.qos// as the Queue Setup Script
-    * The Advanced Configuration defaults are designed to work well out of the box. +    * Advanced Configuration may be left unchecked 
-  - In the **Link Layer Adaptation** tab, choose the kind of link you have+  - In the **Link Layer Adaptation** tab, select your link type (optional: set mpu see [[:docs:guide-user:network:traffic-shaping:sqm#a_little_more_sqm_tuning|note 3]])
-    * //For VDSL// - Choose **Ethernet**, and set per packet overhead to 34 (or 26 if you know you are not using PPPoE) +    * //For VDSL// - Choose **Ethernet**, and set overhead 34 (or 26 if you're not using PPPoE) (mpu 68). If the link uses 100 Mbps ethernet, set overhead 42 (mpu 84). 
-    * //For DSL of any other type// - Choose **ATM**, and set per packet overhead to 44 +    * //For DSL of any other type// - Choose **ATM**, and set overhead 44 (mpu 96). 
-    * //For Cable// - Choose **Ethernet**, and set per packet overhead to 22 +    * //For DOCSIS Cable// - Choose **Ethernet**, and set overhead 22 (mpu 64). For rates > 760 Mbps, set overhead 42 (mpu 84), because 1 Gbps ethernet between modem and router affects the worst-case per-packet-overhead. 
-    * //For true ethernet or Fiber to the Premises// - Choose **Ethernet**, and set per packet overhead to 44 +    * //For Ethernet or Fiber// - Choose **Ethernet**, and set overhead 44 (mpu 84). 
-    * //When in Doubt, it's better to overestimate// - Choose packet overhead 44 +    * //If unsure, it's better to overestimate// - Choose overhead 44 (mpu 96). 
-  - Click **Save & Apply**. That's it!+  - Click **Save & Apply**. 
 + 
 +That's it! You can confirm mitigation of bufferbloat by re-running the speedtest. Any increased ping during download/uploads will now be minimal. 
 + 
 +===== Results ===== 
 + 
 +As an example, the user below is running OpenWrt 23.05 on a [[toh:linksys:wrt_ac_series|WRT32X]] router. The internet connection is a DOCSIS cable modem with 500/35 Mbit service. Note this ISP includes over-provisioning. Cake was selected with 90% dl/ul limits on baseline speedtest values. Latency increase under load dropped to zero, lower ping with no packet loss is observed during VoIP and online gaming during heavy internet usage. Speedtests results with and without SQM: 
 + 
 +[[https://www.waveform.com/tools/bufferbloat?test-id=e101a8fc-f017-4eef-8f90-b27bcb783d62|User's speedtest results with SQM.]] 
 + 
 +^   Speedtest Results   ^^^^^^^^ 
 +| QoS  | Download  | Upload   | Unloaded Ping | DL Latency | UL Latency | Quality grade | Bufferbloat grade | 
 +| None | 532 Mbits | 37 Mbits |  12 ms        | +18 ms     | +38 ms     | B             | B                 | 
 +| SQM  | 495 Mbits | 28 Mbits |  12 ms        | +0 ms      | +0 ms      | A+            | A +               |
  
-Measure your latency again with the speed test. You should notice that the measured ping times should only be slightly larger during the downloads and uploads. Try using VoIP, Skype, Facetime, gaming, DNS, and general web browsing. They should be much more pleasant, even if someone's uploading or downloading a lot of data. +===== A Little More Tuning  =====
  
-You've reduced your connection' bufferbloat!  +1. The steps above will handle latency well, but you may improve this further via adjusting the dl/ul limits and with these steps:
-===== A Little More SQM Tuning  =====+
  
-The steps above will control latency well without additional effortThe 80-95% figures mentioned above are good first-cut estimatesbut you can often gain more speed while still controlling latency by making couple experiments to adjust the settings.+  * Increase the Download speed limit and retest until latency begins to increase, then go back to a slightly lower value. 
 +  * Repeat the same for the Upload speed. 
 +  * Use [[https://www.waveform.com/tools/bufferbloat|Waveform]] speedtest to achieve A+ quality and A+ bufferbloat grades when optimal settings are found. 
 +  * For DSLthe experiments above may produce download/upload values that are actually //higher// than the original speed test. This is ok, the ATM framing bytes of DSL link add an average of 9% overhead, and these settings tell SQM how to make up for that overhead. 
 +  * For DOCSIS cable, some providers trick speed tests by adding 10-15% over-provisioning for the first 10 seconds (so speed tests look better!).
  
-If you want to spend few more minutes tuningdo these steps.+2. Cake is the [[https://www.bufferbloat.net/projects/codel/wiki/Cake/|preferred algorithm]] as it is excellent at mitigating bufferbloat. However, Fq_codel is often fasteralbeit less comprehensive option. One user found [[https://forum.openwrt.org/t/netgear-r6220-sqm-results-downstream-cut-in-half-and-my-optimal-settings/114301|fq_codel gave about 15% higher throughput when CPU limited]] and this [[https://lists.bufferbloat.net/pipermail/cake/2018-April/003384.html|email thread showed similar results]].
  
-  * Increase the Download speed until the latency begins to increase, then go back to a slightly lower value +3To set your link **mpu*(read [[docs:guide-user:network:traffic-shaping:sqm-details|SQM Details]] and [[https://forum.openwrt.org/t/sqm-setting-question-link-layer-adaptation/2514/9|SQM setting question]]) for efficiency improvements. Setting mpu will ensure rate shaping is correct for small packets.
-  Do the same for the Upload speed entry.  +
-  It may be worth your time to tweak the two a bit up and down to find a sweet spot for your connection and usage. +
-  We recommend you use [[http://dslreports.com/speedtest|DSLReports Speed Test]] for the latency tests because it measures both speed and latency at the same time.  +
-   +
-**Note:** If you have a DSL link, the experiments above may produce Download and Upload values that are actually //higher// than the original speed test results. This is OK: the ATM framing bytes of a DSL link add an average of 9% overhead, and these settings simply tell SQM how to make up for that overhead.+
  
-**Note:** If you use a cable modem, you should use a speed test that runs for a longer timeCable modem makers have gamed speed tests thoroughly by using "Speedboost", which usually gives you an extra 10 mbits or so for the first 10 seconds (so the speed test will look good(!)). Don't be surprised if the "right" setting for your queue rates is significantly lower than the no-SQM speed test resultsYou may need to tune the speeds //down// from your initial settings to get the latency to the point you need for your own usage of your connection.+4Check the [[docs:guide-user:network:traffic-shaping:sqm-details#faq|FAQ]] and [[docs:guide-user:network:traffic-shaping:sqm-details#troubleshooting_sqm|Troubleshooting SQM]] guides for more informationSee also: [[:docs:guide-user:network:traffic-shaping:sqm_configuration|SQM configuration]] for advanced options.
  
-**Note:** You can also experiment with the other settings (read [[docs:guide-user:network:traffic-shaping:sqm-details|SQM - The Details]]  for more information), but they will not make nearly as large a difference as ensuring that the Download and Upload speeds are maximized. +5. Consider Cake tuning parameters: [[https://man7.org/linux/man-pages/man8/tc-cake.8.html]]
  
-**Note:** Also check the [[docs:guide-user:network:traffic-shaping:sqm-details#faq|FAQ]] and [[docs:guide-user:network:traffic-shaping:sqm-details#troubleshooting_sqm|Troubleshooting SQM]] guides +6. To use SQM it is necessary to disable hardware flow offloading as per [[https://forum.openwrt.org/t/sqm-and-non-sqm-queue-issues-lan-vs-wlan/15433/10|this post]].
  • Last modified: 2024/11/07 18:49
  • by palebloodsky