Jump to content
Cheater

Cum maresti viteza la net'

Recommended Posts

Posted (edited)

Cum n-am mai deschis un topic aici de multi ani, si am terminat serialele, si n-am somn, m-am gandit sa impartasesc cu voi optimizarile ce le folosesc pentru a imbunatati timpul de raspuns si viteza internetului. Este vorba de setari si configurari ce se aplica routerului, si este necesar ca routerul sa va permita conectarea prin ssh ca root pentru a le aplica.

Eu folosesc https://www.synology.com/en-us/products/RT2600ac dar sunt convins ca ca sunt si alti producatori ce au routere cu linux destul de accesibil pentru a implementa optimizarile. Stiu nu e AX, luna viitoare scot cei de la Synology unul AX.

Oricum tutorialul se aplica la fel si la AX si AC. Cand apare wifi 6e in Romania, poate fac o continuare.

 

La routerele Synology parola setata la userul Admin, este parola de root.

Valorile ce le gasiti in continuare au fost optimizate pentru o viteza maxima permisa de isp de 940Mbps, dar pana la 2.5Gbps nu ar trebui sa fie necesare modificari semnificative. De asemenea puteti aplica aceste setari si pe servere linux vor aduca imbunatatiri semnificative fata de default.

 

1. /etc/rc.local

Este posibil sa nu functioneze configurarile exact asa cum le prezint eu aici pe routerul vostru, de aceeea inainte de a le scrie in fisiere pentru a deveni persistente, faceti setarile la run-time, si adaptatiile daca este necesar, sau omitetile daca nu se aplica la voi (nu aveti binarele respective/variabilele de kernel, ajustati caila catre ele)

Quote

# Add this if your router has build-in IDS/IPS

set ips queue_length 8192

 

# Start random number seeder. Increases the entropy pool from ~120 to ~4096

/usr/sbin/rngd -r /dev/urandom -o /dev/random -W 90% > /dev/null 2>&1

 

# Configure custom txqueuelen, based on your actual internet speed, on all interfaces except the virtual ones, 8333 is used for 1Gbps, it's important to calculate the right configuration based on your speed, I used the numbers below, here it is the formula in `Kernel Parameters for Core Networking` section: https://cromwell-intl.com/open-source/performance-tuning/ethernet.html

# Also do NOT change MTU if you won't be able to change it for every device in your entire network.

# I use 2 commands, one for wifi+bridges and one just for ethernet ports, you may adjust this commands.

for i in $(ifconfig | cut -d ' ' -f1| tr ':' '\n' | awk NF | grep -v lo | grep -v tap | grep -v vbr| grep -v eth); do ifconfig $i txqueuelen 7500 > /dev/null 2>&1; done 
for i in $(ifconfig | cut -d ' ' -f1| tr ':' '\n' | awk NF | grep eth); do ifconfig $i txqueuelen 7833 > /dev/null 2>&1; done

 

# nic off-loading, check it in console before yo make it permanent. Use ethtool -k eth0 to check your interface capabilities. I use it only for ethernet interfaces.

for i in $(ifconfig | cut -d ' ' -f1| tr ':' '\n' | awk NF | grep eth); do ethtool -K $i rx on tx on sg on tso on ufo on gso on gro on lro on rxhash on ntuple on txvlan on rxvlan on tx-nocache-copy off tx-checksum-ipv4 on tx-checksum-ip-generic on tx-checksum-ipv6 on tx-checksum-fcoe-crc on tx-checksum-sctp on tx-scatter-gather on tx-scatter-gather-fraglist on tx-tcp-segmentation on tx-tcp-ecn-segmentation on tx-tcp6-segmentation on highdma on tx-gso-robust on tx-fcoe-segmentation on tx-gre-segmentation on tx-ipip-segmentation on tx-sit-segmentation on tx-udp_tnl-segmentation on tx-vlan-stag-hw-insert on > /dev/null 2>&1; done

 

# Tuning the initial congestion window parameter (initcwnd) and advertised receive window (initrwnd), make sure that the interfaces are up and you received DHCP before it runs, or add a sleep before if it is needed.

sleep 600

ip route | while read p; do ip route change $p initcwnd 128 initrwnd 128; done > /dev/null 2>&1
ip -6 route | while read p; do ip -6 route change $p initcwnd 128 initrwnd 128; done > /dev/null 2>&1

exit 0

 

2. /etc/sysctl.conf

Ca sa aplicati configurarile fara reboot folositi sysctl -p, sau sysctl -w nume_variabila=valoare. Indepartati variabilele daca primiti eroare, unele pot sa lipseasca din versiunea de kernel pe care o aveti.

Quote

kernel.panic=3
# Required for Synology Routers, comment it if you don't have a default like this before edit this file.
net.ipv6.conf.default.accept_ra_defrtr=0

# Force gc to clean-up quickly
net.ipv4.neigh.default.gc_interval = 3600

# Set ARP cache entry timeout
net.ipv4.neigh.default.gc_stale_time = 3600

# Setup DNS threshold for arp
net.ipv4.neigh.default.gc_thresh3 = 4096
net.ipv4.neigh.default.gc_thresh2 = 2048
net.ipv4.neigh.default.gc_thresh1 = 1024


# congestion control (default cubic)
# /sbin/modprobe tcp_htcp
# sysctl net.ipv4.tcp_available_congestion_control
# some routers uses highspeed instead of htcp, but it is the same thing.
net.ipv4.tcp_congestion_control=highspeed 
# use bbr if you have kernel >4.9
#net.ipv4.tcp_congestion_control=bbr 
#net.core.default_qdisc=fq

### Set the max OS send buffer size (wmem) and receive buffer
# size (rmem) for queues on all protocols. In other
# words set the amount of memory that is allocated for each
# TCP socket when it is opened or created while transferring files

# Default Socket Receive Buffer
net.core.rmem_default = 14155776
net.core.rmem_max = 28311552
net.core.wmem_default = 14155776
net.core.wmem_max = 28311552


# Set minimum, default, and maximum TCP buffer limits
# decrease it if you have packet loose after you configure it
net.ipv4.tcp_rmem = 4096 14155776 28311552
net.ipv4.tcp_wmem = 4096 14155776 28311552
net.ipv4.udp_rmem_min = 16384
net.ipv4.udp_wmem_min = 16384

# Increase the maximum total buffer-space allocatable
# This is measured in units of pages (4096 bytes)
net.ipv4.tcp_mem = 65536 131072 262144
net.ipv4.udp_mem = 65536 131072 262144

net.ipv4.tcp_max_tw_buckets = 1440000

# Set maximum network input buffer queue length
net.core.netdev_max_backlog = 250000
net.core.netdev_budget = 50000
net.core.dev_weight = 50000
net.core.flow_limit_table_len=8192

# Disable caching of TCP congestion state (2.6 only)
net.ipv4.tcp_no_metrics_save = 1

# increase port range
net.ipv4.ip_local_port_range = 1024 65535

# Protect Against TCP Time-Wait
net.ipv4.tcp_rfc1337 = 1
net.ipv4.tcp_fack = 1

# This will enusre that immediatly subsequent connections use the new values
net.ipv4.route.flush = 1
net.ipv6.route.flush = 1

# Increase TCP queue length
net.ipv4.neigh.default.proxy_qlen = 96
net.ipv4.neigh.default.unres_qlen = 6

# Increase size of RPC datagram queue length
net.unix.max_dgram_qlen = 256

net.ipv4.tcp_notsent_lowat = 16384

# Limit the maximum memory used to reassemble IP fragments (CVE-2018-5391)
net.ipv4.ipfrag_low_thresh = 196608
net.ipv6.ip6frag_low_thresh = 196608
net.ipv4.ipfrag_high_thresh = 262144
net.ipv6.ip6frag_high_thresh = 262144

# Performance
net.ipv4.tcp_reordering = 3

# max connections, usefull if your router is also a download station or it has a database like postgress/mysql
net.core.somaxconn=1024000
net.ipv4.tcp_tw_reuse=1
net.ipv4.tcp_fastopen = 3
net.ipv4.tcp_low_latency=1
net.ipv4.tcp_fin_timeout=7
net.ipv4.tcp_max_syn_backlog=1024
net.ipv4.tcp_moderate_rcvbuf = 1
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_keepalive_intvl = 15
net.ipv4.tcp_keepalive_probes = 5
net.ipv4.tcp_sack=1
net.core.optmem_max = 25165824
# disable timestamps and syncookies to decrease tcp header size
net.ipv4.tcp_timestamps=0
net.ipv4.tcp_syncookies=0
# use ecn in case of congestion instead of dropping packets 
net.ipv4.tcp_ecn=1
net.ipv4.tcp_slow_start_after_idle=0
net.ipv4.tcp_syn_retries = 2
# make sure that we identify the right mtu, make sure that ping is allowed on ipv4/ipv6 in your fw
net.ipv4.ip_no_pmtu_disc=0
net.ipv4.tcp_base_mss=1460
net.ipv4.tcp_mtu_probing=1
net.ipv4.route.mtu_expires=86400
net.ipv6.route.mtu_expires=86400

# Turn on window scaling which can enlarge the transfer window:
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_adv_win_scale = 14


# Number of times SYNACKs for passive TCP connection.
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_retries2 = 5
net.ipv4.tcp_retries1 = 3

kernel.domainname = SynologyRouter

# Increase size of file handles and inode cache, usefull if your router is also a download station or it has a database like postgress/mysql
fs.file-max = 50000
fs.inotify.max_user_watches=6000

# tells the kernel how many TCP sockets that are not attached to any
# user file handle to maintain. In case this number is exceeded,
# orphaned connections are immediately reset and a warning is printed.
net.ipv4.tcp_max_orphans = 600


# Security
net.ipv4.tcp_challenge_ack_limit=1073741823
net.ipv4.conf.default.rp_filter=2
net.ipv4.conf.all.rp_filter=2

# For low-latency 
net.core.busy_poll=100
net.core.busy_read=100
net.ipv4.route.gc_timeout = 100

 

3. Wifi

 

Alegem canalul:

 

Primul pas este scanarea de spectru, sunt multe aplicatii pentru asta, scopul este sa identificati canalul cel mai putin folosit pe 2.4/5Ghz sau daca este folosit retelele ce emit pe acel canal sa aiba o putere cat mai mica.

 

TvBIR97VF7hs.png?o=1

 

- pe 2.4Ghz sunt 3 canale ce nu se suprapun (non overlapping channels), 1, 6 si 11, ideal este sa alegem unul dintre acestea. Daca toate sunt libere, alegeti 11.

- pe 5Ghz, cautam sa ne ferim de canalele cu DFS obligatoriu, astfel ne orientam catre benziile U-NII-1 si U-NII-3, daca avem noroc sa locuim in US/Canada (sau routerul crede asta), as recomanda canalul 161. Dar cum locuim in Romania si e 5000 lei amenda daca setezi alta tara si mergi pe un canal aiurea (in ideea in care avem vreo UM in apropiere, bruiem ceva, ei fac sesizare la ANCOM si ne bate ANCOM la usa, putin probabil), iar routerul nu ne lasa sa folosim 161 pe Romania, m-as uita la 40-44, daca este liber.

Daca ai un router capabil, si intamplator locuiesti in Australia, routerul iti va permite 4W puterea in U-NII-3, cea mai mare din lume acceptata pe wifi, dar majoritatea routerelor suporta ±1W maxim.

 

Channel width:

 

Marimea canalului este importanta, cu cat este mai mare, cu atat incap mai multe date, deci avem viteza mai mare. 

- pe 2.4Ghz, eu merg pe width de 40Mhz

- pe 5Ghz, routerul meu stie sa mearga pe un width de 80+80 Mhz, practic foloseste 2 canale, am ales un canal din U-NII-1 si unul U-NII-3 (cand locuiam in US), ambele cu un width de 80Mhz, bine si deviceurile din caza trebuie sa stie 80+80 Mhz, sau 160Mhz, cel mai probabil suporta doar 80Mhz, ceea ce e good enough oricum.

 

Alte setari:

 

DTIM 4 - mai mic scade viteza si timpul de raspuns, si se consuma mai multa baterie, mai mare e opusul, optimul este 4. Dar puteti face A/B testing si vedeti ce vi se potriveste mai bine.

Multicast translation - on

AMPDU - on 

EXTENDED NSS - on

U-APSD - off

MU-MIMO - on, ideal 4x4, dar si 2x2 ar trebui sa fie suficient.

PMF support - off, apare un overhead ciudat si pare buggy, daca la voi se comporta la fel si on si off, e o idee buna sa ii dati on. La fel si WPA 3.

IGMP Snooping - on

Orice setare de power saving, off!

Downgrade usb 3.0 device to reduce interference to 2.4 Ghz signal - on

Allow auto-switch to DFS channels - off

WPS - off (security)

Daca routerul suporta guest, si nu folositi reteaua in mod curent, opriti guest.

La criptarea retelei alegeti AES, pentru ca e hw accelerated.

Alegeti pe 2.4Ghz N only, si 5Ghz AC/AX only, ca sa va asigurati ca fortati device-urile sa folosesca cele mai rapide protocoale de wifi, daca sunt device ce nu functioneza corect reveniti la o setare mai permisiva.

Daca routerul suporta 802.11v aka Smart Connect, puteti, si recomand, sa folositi acelasi nume si la 2.4Ghz si la 5Ghz si routerul va negocia protocolul cel mai bun suportat de device, tinand cont si de calitatea semnalului pentru a avea cea mai buna acoperire si un plus de simplitate.

 

+ Folositi un doh dns, daca suporta routerul, sau macar un cloudflare dns, are datacenter si la otopeni si peers locale - https://1.1.1.1/dns/ .

 

Firewall:

 

Mtu probing se foloseste de icmp (ping), pentru a identifica valoarea optima, astfel este important sa acceptati icmp pe ipv4 si ipv6. 

Blocati orice port ce nu are ce cauta in afara, eu de exemplu, prefer sa folosesc un port non-default pentru vpn server, din care mai apoi sa am access la interfata routerului si alte chestii.

 

Locatia fizica:

 

Recomand sa identificati locul de unde, din pozitia routerului puteti vedea usile la toate camerele (sau cat mai multe), un hol, sa va asigurati ca nu sunt obstacole (pereti mai ales de beton, frigider, etc..) in jurul routerului, este ideal sa fie situat la o inaltime de 2m, prins pe perete (preferabil), daca folositi wifi cu precadere dintr-o anumita camera cautati o pozitie cat mai aproape de camera care sa respecte cele de mai sus. Daca pui routerul sub pat, de sub pat o sa ai putere maxima :))). 

Este adevarat ca semnalul ocoleste/trece prin obstacole doar ca fiecare obstacol scade semnificativ puterea, daca punem routerul pe jos, in mod automat va intalni semnificativ mai multe obstacole, si daca prin dreptul lui trec persoane, o sa apara spike-uri, nu ne dorim asta, de aceea inaltimea de 2m este optima.

 

Performante obtinute:

 

Inainte de a face aceste optimizari aveam 300-400 mbps, cu spike-uri mari.

Dupa, am 650-666 pe orice device Apple mai nou de 2019 (testat cu: iPhone X, 12, MacBook Pro 16'' M1 pro/M1 max), si 800-900 Mbps pe deviceuri Apple 2017-2019 (chiar 2014) (testat cu: MacBook Pro 16'' 2014, 2019, Intel-based), au pus placi de retea mai slabe pe 5Ghz cu 2/mimo in loc de 3 cum era pana in 2019 pe device recente, probabil ca sa faca o economie de baterie/de cost de productie, naiba stie. https://support.apple.com/ro-ro/guide/deployment/dep2ac3e3b51/web

Cert este ca routerul duce mai mult decat deviceurile ce le folosesc.

Daca routerul este capabil AX la 2 mimo atat pe partea de router cat si de client estimez o viteza de 750-800Mbps, ceea ce e destul de bine.

 

Update, screenshoot facut din qbittorrent, de pe un MBP M1 Pro, pe WIFI:

46pU6ntInOT1.png

 

Sper sa va fie de folos!

 

Have fun! :)

 

PS: daca am facut vreo greseala, o sa o corectez zilele urmatoare, am inceput sa scriu la 23 si e 03 :))

Edited by Cheater
typo si fine tunning
  • Upvote 8

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...