1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
Dismiss Notice

Welcome To SNBForums

SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.

If you'd like to post a question, simply register and have at it!

While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!

AC86U SMB Tweaking

Discussion in 'Asuswrt-Merlin' started by Adamm, Feb 17, 2018.

  1. Adamm

    Adamm Very Senior Member

    Joined:
    Mar 26, 2013
    Messages:
    1,541
    So I recently purchased a 2TB WD Elements HDD for the purpose network storage, I formatted this drive ext4. I noticed pretty fast that SMB default values give terrible wireless performance (LAN tests though are great at 100MB/s+ transfer rates).

    I decided to-do some tweaking and found some interesting results.

    1) Default socket values | Write = 18MB/s - Read = 25MB/s
    Code:
    socket options = IPTOS_LOWDELAY TCP_NODELAY SO_KEEPALIVE SO_RCVBUF=65536 SO_SNDBUF=65536
    2) Doubled Send/Receive buffers | Write = 30MB/s - Read = 40MB/s
    Code:
    socket options = IPTOS_LOWDELAY TCP_NODELAY SO_KEEPALIVE SO_RCVBUF=131072 SO_SNDBUF=131072
    3) No buffers specified | Write = 50MB/s - Read = 80MB/s
    Code:
    socket options = IPTOS_LOWDELAY TCP_NODELAY SO_KEEPALIVE

    Admittedly I can't say I've looked into this area too much, a quick search of the forum showed previous threads with similar recommendations about increasing the buffer size, but nothing mentioning removing the specified buffer all together which so far has given me the best performance. I'm also unsure of what SMB defaults this to when its not specified which is giving the above results or any potential downsides.

    If anyone would like to chip in their findings in further improvements I'm all ears, and potentially we can have some of these tweaks added by default as stock performance is quite terrible.


    For anyone wishing to replicate this, create the file "/jffs/scripts/smb.postconf" with the following content (and change the second part of the sed command to your desired config).

    Code:
    #!/bin/sh
    CONFIG="$1"
    sed -i "s~socket options.*~socket options = IPTOS_LOWDELAY TCP_NODELAY SO_KEEPALIVE~g" "$CONFIG"
    After creating the file, chmod it and restart the nasapps service;

    Code:
    chmod +x /jffs/scripts/smb.postconf
    
    service restart_nasapps
     
    Last edited: Feb 19, 2018
  2. Please support SNBForums! Just click on this link before you buy something from Amazon and we'll get a small commission on anything you buy. Thanks!
  3. skeal

    skeal Very Senior Member

    Joined:
    Apr 30, 2016
    Messages:
    1,575
    I did this on my arm7 router and it seems to speed things up considerably.
     
  4. bigeyes0x0

    bigeyes0x0 Senior Member

    Joined:
    Sep 9, 2015
    Messages:
    216
    I can confirm this improves my AC56U SMB speed by 10 to 20% as well.
     
  5. RussellInCincinnati

    RussellInCincinnati Senior Member

    Joined:
    Feb 20, 2013
    Messages:
    301

    Not sure what this sentence intends for us to do to the "sed" command, exactly:
    (and change the second part of the sed command to your desired config).
     
  6. Adamm

    Adamm Very Senior Member

    Joined:
    Mar 26, 2013
    Messages:
    1,541

    The bolded part you would change to the socket config you wish to enable (I posted 3 examples above).

     
  7. quaz

    quaz Occasional Visitor

    Joined:
    Feb 29, 2016
    Messages:
    12
    Works great on my AC68U running 382.2beta3 (because of my VPN I need to overclock my router, so I'm stuck with this firmware), a 20% speed increase with double buffer.
     
  8. Lotta Cox

    Lotta Cox Regular Contributor

    Joined:
    Jun 19, 2013
    Messages:
    142
    Location:
    Google HQ
    Am I doing something wrong?
    [email protected]:/tmp/home/root# sed -i "s~socket options.*~socket options = IPTOS_LOWDELAY TCP_NODELAY SO_KEEPALIVE~
    g" "$CONFIG"
    sed: : No such file or directory
    [email protected]:/tmp/home/root#
     
  9. ColinTaylor

    ColinTaylor Part of the Furniture

    Joined:
    Mar 31, 2014
    Messages:
    6,049
    Location:
    UK
    Yes. Re-read post #1.
     
  10. Lotta Cox

    Lotta Cox Regular Contributor

    Joined:
    Jun 19, 2013
    Messages:
    142
    Location:
    Google HQ
    Doesn't the second part already have the third option? I have read it sooo many times o_O

    socket options = IPTOS_LOWDELAY TCP_NODELAY SO_KEEPALIVE

    sed -i "s~socket options.*~socket options = IPTOS_LOWDELAY TCP_NODELAY SO_KEEPALIVE~
    g" "$CONFIG"

    What is it supposed to be with the third option?
     
  11. sfx2000

    sfx2000 Part of the Furniture

    Joined:
    Aug 11, 2011
    Messages:
    12,895
    Location:
    San Diego, CA
    Be careful - the SAMBA defaults are conservative to protect data...

    That being said... if one wants to walk on the wild-side... this gets the best bang in our testing with Win7/8/10 and MacOS...

    socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=65536 SO_SNDBUF=65536
     
  12. ColinTaylor

    ColinTaylor Part of the Furniture

    Joined:
    Mar 31, 2014
    Messages:
    6,049
    Location:
    UK
    I think you're missing the most important part:
     
    Lotta Cox likes this.
  13. Lotta Cox

    Lotta Cox Regular Contributor

    Joined:
    Jun 19, 2013
    Messages:
    142
    Location:
    Google HQ
    Gotcha thanks!
     
  14. Lotta Cox

    Lotta Cox Regular Contributor

    Joined:
    Jun 19, 2013
    Messages:
    142
    Location:
    Google HQ
    I used WinSCP to make the file, edit, and chmod it.
    With option 3, I transferred a movie file. Speed went from 235mb/s to 500mb/s. Nice!
     
    Last edited: Feb 18, 2018
  15. RMerlin

    RMerlin Super Moderator

    Joined:
    Apr 14, 2012
    Messages:
    27,407
    Location:
    Canada
    Also note that I noticed very different test results with Samba when testing with Ethernet vs Wifi. Some optimizations were great for one but seriously reduced performance for the other.
     
  16. Lotta Cox

    Lotta Cox Regular Contributor

    Joined:
    Jun 19, 2013
    Messages:
    142
    Location:
    Google HQ
    My ethernet speeds are good with option 3 too. I will keep an eye on it.
     
  17. LostFreq

    LostFreq Regular Contributor

    Joined:
    Nov 27, 2017
    Messages:
    59
    Location:
    Belgium
    Not setting the SO_RCVBUF and SO_SNDBUF socket options may be a good idea because on Linux there is TCP buffer auto-tuning which only works if you don't set socket buffer sizes, so it is more effective not to set SO_RCVBUF and SO_SNDBUF with TCP connections. This should allow Linux to find the optimal buffer size for the actual latency on the socket.

    OpenVPN also used to set the buffer sizes to 64 KB by default in the past, but from version 2.3.9 it relies on the operating system defaults instead. You can read some of the discussion here: https://community.openvpn.net/openvpn/ticket/461

    On my RT-AC86U I see these auto-tuning TCP buffer limits (min, default, and maximum number of bytes to use):

    Code:
    # grep . /proc/sys/net/ipv4/tcp_?mem
    /proc/sys/net/ipv4/tcp_rmem:4096    87380   3521536
    /proc/sys/net/ipv4/tcp_wmem:4096    16384   3521536
    and these are limited by the maximum buffer sizes (384.3):
    Code:
    # grep . /proc/sys/net/core/?mem_max
    /proc/sys/net/core/rmem_max:278528
    /proc/sys/net/core/wmem_max:278528
    Asus increased these values for HND in release/src/router/rc/sysdeps/init-broadcom.c with 384_20379 (384.4 alpha):
    Code:
    # grep . /proc/sys/net/core/?mem_max
    /proc/sys/net/core/rmem_max:524288
    /proc/sys/net/core/wmem_max:524288
    If you agree that the optimal TCP buffer size for a given network link is buffer size = RTT * bandwidth then a fixed 64KB buffer size would limit your throughput on a wireless link with some latency, for instance if the RTT would be 2 ms then:
    64KB = 0.002 * 31.25 MB/s

    If you remove the SO_RCVBUF and SO_SNDBUF socket options from the Samba config, you could instead increase the default initial size of the send buffer used by TCP sockets to the value currently used for SO_SNDBUF in the Samba config, that would give you the best of both worlds (maybe do this in the same place in init-broadcom.c):
    Code:
    echo 4096 65636 3521536 > /proc/sys/net/ipv4/tcp_wmem
     
    Last edited: Feb 19, 2018
  18. TheBestPessimist

    TheBestPessimist Occasional Visitor

    Joined:
    Oct 15, 2017
    Messages:
    14
    RT-AC87U 380.68_4

    Speeds better both on wireless and on wired with "socket options = IPTOS_LOWDELAY TCP_NODELAY SO_KEEPALIVE" (basically w/o "SO_RCVBUF=65536 SO_SNDBUF=65536").

    As a delta between the speeds (as reported by windows 10 copy window): i seem to get about 10MBPS more than before, but i have not actually timed the copy.
     
  19. LostFreq

    LostFreq Regular Contributor

    Joined:
    Nov 27, 2017
    Messages:
    59
    Location:
    Belgium
    On the AC86U I assume that would default to:
    an initial receive buffer size of 87380, auto-tuned by the kernel up to 278528 (or 524288 for 384.4)
    an initial send buffer size of 16384, auto-tuned by the kernel up to 278528 (or 524288 for 384.4)
    To get the 384.4 tweaked maximum values that I mentioned above on 384.3 you could enter these commands:
    Code:
    echo 524288 > /proc/sys/net/core/rmem_max
    echo 524288 > /proc/sys/net/core/wmem_max
    And you could increase the default initial size of the send buffer used by TCP sockets with this command:
    Code:
    echo 4096 65636 3521536 > /proc/sys/net/ipv4/tcp_wmem
    Note that you have to restart Samba after these commands and that the changed values will be reset by a reboot.

    As RMerlin pointed out, testers should compare results for both a wired and a wireless connection (as these have different bandwidth and latency). And it would also be interesting to test both read speeds and write speeds.
     
    Last edited: Feb 19, 2018
  20. Adamm

    Adamm Very Senior Member

    Joined:
    Mar 26, 2013
    Messages:
    1,541
    These values are already present at-least when no buffers are specified.

    Unfortunately I can't easily test wired speeds due to my setup (I could but its a hassle). Not only that but I assume my mechanical HDD would be the bottleneck, someone with an external SSD would be preferable. I did update the OP with read speeds though for reference.
     
  21. LostFreq

    LostFreq Regular Contributor

    Joined:
    Nov 27, 2017
    Messages:
    59
    Location:
    Belgium
    Which firmware version are you using? Can you give the output of
    Code:
    cat /proc/sys/net/ipv4/tcp_wmem
     
Please support SNBForums! Just click on this link before you buy something from Amazon and we'll get a small commission on anything you buy. Thanks!