Ho ntlafatsa Linux ho sebetsana le likopo tsa JSON tse limilione tse 1.2 motsotsoana

Tataiso e qaqileng e phatlalalitsoe mabapi le ho lokisa tikoloho ea Linux ho fihlela ts'ebetso e phahameng ea ho sebetsana le likopo tsa HTTP. Mekhoa e reriloeng e entse hore ho khonehe ho eketsa ts'ebetso ea processor ea JSON e ipapisitseng le laeborari ea libreactor tikolohong ea Amazon EC2 (4 vCPU) ho tsoa ho likopo tse likete tse 224 tsa API motsotsoana ka litlhophiso tse tloaelehileng tsa Amazon Linux 2 e nang le likopo tse limilione tse 4.14 ho isa ho tse 1.2 ka motsotsoana. ea bobeli ka mor'a ho ntlafatsa (keketseho ea 436%), hape e lebisitse ho fokotseha ha tieho ea ho sebetsa likopo ka 79%. Mekhoa e reriloeng ha e tsejoe ka ho toba ho libreactor le ho sebetsa ha u sebelisa lisebelisoa tse ling tsa http, ho akarelletsa le nginx, Actix, Netty le Node.js (libreactor e ne e sebelisoa litekong hobane tharollo e thehiloeng ho eona e bontšitse tshebetso e ntlafetseng).

Ho ntlafatsa Linux ho sebetsana le likopo tsa JSON tse limilione tse 1.2 motsotsoana

Lintlafatso tsa mantlha:

  • Ho ntlafatsa khoutu ea libreactor. Khetho ea R18 e tsoang ho Techempower kit e ile ea sebelisoa e le motheo, e ileng ea ntlafatsoa ka ho tlosa khoutu ho fokotsa palo ea li-CPU cores tse sebelisoang (ho ntlafatsa ho lumella ho potlakisa mosebetsi ka 25-27%), ho bokana GCC ka likhetho tsa "-O3". (keketseho ea 5-10%) le "-march-native" (5-10%), ho nkela mehala ea ho bala / ho ngola ka recv/send (5-10%) le ho fokotsa holimo ha u sebelisa li-pthreads (2-3%). . Keketseho ea ts'ebetso ka kakaretso ka mor'a ho ntlafatsa khoutu e bile 55%, 'me tlhahiso e ile ea eketseha ho tloha 224k req/s ho ea ho 347k req/s.
  • Thibela tshireletso kgahlanong le bofokodi bo inahaneloang ba phethahatso. Ho sebelisa li-parameters "nospectre_v1 nospectre_v2 pti=off mds=off tsx_async_abort=off" ha u kenya kernel e lumelloa ho eketsa ts'ebetso ka 28%,' me tlhahiso e eketsehile ho tloha 347k req / s ho ea ho 446k req / s. Ka thoko, keketseho e tsoang ho parameter "nospectre_v1" (ts'ireletso ho Specter v1 + SWAPGS) e ne e le 1-2%, "nospectre_v2" (ts'ireletso ho Specter v2) - 15-20%, "pti=off" (Specter v3 / Meltdown) - 6 %, "mds=off tsx_async_abort=off" (MDS/Zombieload le TSX Asynchronous Abort) - 6%. Litlhophiso tsa ts'ireletso khahlanong le L1TF/Foreshadow (l1tf=flush), iTLB multihit, Speculative Store Bypass le litlhaselo tsa SRBDS li ile tsa siuoa li sa fetoha, tse sa kang tsa ama ts'ebetso kaha li ne li sa kopane le tlhophiso e lekiloeng (mohlala, e khethehileng ho KVM, virtualization le mefuta e meng ea CPU).
  • Ho thibela mokhoa oa ho hlahloba le oa ho thibela mehala ka ho sebelisa taelo ea "auditctl -a never,task" le ho hlakisa khetho ea "-security-opt seccomp=unconfined" ha u qala setshelo sa docker. Keketseho ea ts'ebetso ka kakaretso e bile 11%, 'me tlhahiso e eketsehile ho tloha ho 446k req/s ho ea ho 495k req/s.
  • Ho thibela iptables/netfilter ka ho laolla li-module tsa kernel tse amanang. Khopolo ea ho tima firewall, e neng e sa sebelisoe tharollong e itseng ea seva, e susumelitsoe ke liphetho tsa profiling, ho ahlola hore na mosebetsi oa nf_hook_slow o nkile 18% ea nako ea ho e etsa. Hoa hlokomeleha hore nftables e sebetsa ka mokhoa o atlehileng ho feta li-iptables, empa Amazon Linux e ntse e tsoela pele ho sebelisa li-iptables. Ka mor'a ho thibela li-iptables, keketseho ea ts'ebetso e ne e le 22%, 'me tlhahiso e ile ea eketseha ho tloha 495k req / s ho ea ho 603k req / s.
  • Phokotso ea ho falla ha li-processor lipakeng tsa li-cores tse fapaneng tsa CPU ho ntlafatsa ts'ebeliso ea cache ea processor. Ntlafatso e entsoe ka bobeli boemong ba lits'ebetso tse tlamang libreactor ho li-CPU cores (CPU Pinning) le ka ho ts'oara marang-rang a kernel (Amohela Side Scaling). Ka mohlala, irqbalance e ne e holofetse mme kamano ea queue ho CPU e ne e behiloe ka ho hlaka ho /proc/irq/$IRQ/smp_affinity_list. Ho sebelisa motsoako o tšoanang oa CPU ho sebetsana le ts'ebetso ea libreactor le letoto la marang-rang la lipakete tse kenang, ho sebelisoa mochine o tloaelehileng oa BPF, o kopantsoe ka ho beha folakha ea SO_ATTACH_REUSEPORT_CBPF ha ho etsoa sokete. Ho kopanya mela ea lipakete tse tsoang ho CPU, litlhophiso /sys/class/net/eth0/queues/tx- li fetotsoe. /xps_cpus. Keketseho ea ts'ebetso ka kakaretso e bile 38%, 'me tlhahiso e eketsehile ho tloha ho 603k req/s ho ea ho 834k req/s.
  • Ntlafatso ea ts'ebetso ea tšitiso le ts'ebeliso ea likhetho. Ho nolofalletsa mokhoa oa adaptive-rx ho mokhanni oa ENA le ho laola sysctl net.core.busy_read e eketsehile ts'ebetso ka 28% (sephetho se eketsehile ho tloha ho 834k req/s ho ea ho 1.06M req/s, 'me latency e fokotsehile ho tloha ho 361μs ho ea ho 292μs).
  • Ho thibela lits'ebeletso tsa tsamaiso tse lebisang ho thibela ho sa hlokahaleng ka har'a stack ea marang-rang. Ho thibela dhclient le ho beha aterese ea IP ka letsoho ho entse hore ho be le keketseho ea 6% ea ts'ebetso 'me tlhahiso e eketsehile ho tloha 1.06M req/s ho ea ho 1.12M req/s. Lebaka leo ka lona dhclient e amang ts'ebetso ke tlhahlobong ea sephethephethe ho sebelisa sokete e tala.
  • Ntoa ea Spin Lock. Ho fetola stack ea marang-rang ho "noqueue" mode ka sysctl "net.core.default_qdisc=noqueue" le "tc qdisc replace dev eth0 root mq" e lebisitse ho keketseho ea ts'ebetso ea 2%, 'me tlhahiso e ile ea eketseha ho tloha 1.12M req/s ho ea ho 1.15M req/s.
  • Lintlafatso tse nyane tsa ho qetela, joalo ka ho tima GRO (Generic Receive Offload) ka taelo ea "ethtool -K eth0 gro off" le ho nkela algorithm ea taolo ea tšubuhlellano sebaka ka reno o sebelisa sysctl “net.ipv4.tcp_congestion_control=reno”. Keketseho ea tlhahiso ka kakaretso e bile 4%. Sephetho se eketsehile ho tloha ho 1.15M req/s ho ea ho 1.2M req/s.

Ntle le lintlafatso tse ileng tsa sebetsa, sengoloa se boetse se bua ka mekhoa e sa kang ea lebisa keketsehong e lebelletsoeng ea ts'ebetso. Ka mohlala, tse latelang li ile tsa bonahala li sa sebetse:

  • Libreactor e mathang ka thoko e ne e sa fapane ka ts'ebetso le ho e tsamaisa ka setshelo. Ho nkela writev sebaka ka send, ho eketsa maxevents ho epoll_wait, le ho leka mefuta le lifolakha tsa GCC ha hoa ka ha e-ba le phello (phello e ile ea bonahala feela bakeng sa lifolakha tsa "-O3" le "-march-native").
  • Ho ntlafatsa Linux kernel ho ea ho liphetolelo tsa 4.19 le 5.4, ho sebelisoa SCHED_FIFO le SCHED_RR tlhophiso, ho fetola sysctl kernel.sched_min_granularity_ns, kernel.sched_wakeup_granularity_ns, transparent_hugepages=never, skew did_tick.
  • Ho mokhanni oa ENA, ho nolofalletsa mekhoa ea Offload (karohano, ho bokella, rx/tx checksum), ho haha ​​ka folakha ea "-O3", le ho sebelisa ena.rx_queue_size le ena.force_large_llq_header parameters ho ne ho se na phello.
  • Liphetoho ho stack ea marang-rang ha lia ka tsa ntlafatsa ts'ebetso:
    • Thibela IPv6: ipv6.disable=1
    • Tlosa VLAN: modprobe -rv 8021q
    • Tlosa tlhahlobo ea mohloli oa thepa
      • net.ipv4.conf.all.rp_filter=0
      • net.ipv4.conf.eth0.rp_filter=0
      • net.ipv4.conf.all.accept_local=1 (phello e mpe)
    • net.ipv4.tcp_sack = 0
    • net.ipv4.tcp_dsack=0
    • net.ipv4.tcp_mem/tcp_wmem/tcp_rmem
    • net.core.netdev_budget
    • net.core.dev_weight
    • net.core.netdev_max_backlog
    • net.ipv4.tcp_slow_start_after_idle=0
    • net.ipv4.tcp_moderate_rcvbuf=0
    • net.ipv4.tcp_timestamps=0
    • net.ipv4.tcp_low_latency = 1
    • SO_PRIORITY
    • TCP_NODELAY

    Source: opennet.ru

Eketsa ka tlhaloso