Linuxでロードバランサやキャッシュサーバをマルチコアスケールさせるためのカーネルチューニング


20167 Linux / Linux network performance improvement at hatena - Speaker Deck
HAProxy  nginx memcached  KVS  CPU   CPU  Linux  RFS (Receive Flow Steering) 

Redis  Nodejs 11






 CPU 
 




RSSReceive Side Scaling)

RPS (Receive Packet Steering)

RFS (Receive Flow Steering)
 




iperf

(Starlet)
 






:  CPU 


CPU0  softirq(%soft) CPU0  idle(%idle) 
CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest   %idle
all   31.73    0.00    1.47    0.13    0.00    0.96    0.06    0.00   65.64
  0   70.41    0.00    5.10    0.00    0.00   15.31    0.00    0.00    9.18
  1   68.04    0.00    3.09    0.00    0.00    0.00    0.00    0.00   28.87
  2   53.06    0.00    3.06    0.00    0.00    0.00    0.00    0.00   43.88
  3   47.47    0.00    2.02    0.00    0.00    0.00    1.01    0.00   49.49
  4   49.45    0.00    1.10    0.00    0.00    0.00    0.00    0.00   49.45
  5   44.33    0.00    2.06    0.00    0.00    0.00    0.00    0.00   53.61
  6   38.61    0.00    2.97    0.99    0.00    0.00    0.00    0.00   57.43
  7   32.63    0.00    1.05    0.00    0.00    0.00    0.00    0.00   66.32
  8   29.90    0.00    1.03    1.03    0.00    0.00    0.00    0.00   68.04
  9   10.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00   90.00
 10    8.08    0.00    1.01    0.00    0.00    0.00    0.00    0.00   90.91
 11    6.12    0.00    0.00    0.00    0.00    0.00    0.00    0.00   93.88
 12   10.00    0.00    2.00    0.00    0.00    0.00    0.00    0.00   88.00
 13   11.00    0.00    1.00    0.00    0.00    0.00    0.00    0.00   88.00
 14   17.71    0.00    0.00    0.00    0.00    0.00    0.00    0.00   82.29
 15   11.22    0.00    1.02    0.00    0.00    0.00    0.00    0.00   87.76

softirq  CPU0 


Linux http://sourceforge.jp/projects/linux-kernel-docs/wiki/2.2%E3%80%80Linux%E3%82%AB%E3%83%BC%E3%83%8D%E3%83%AB%E3%81%AE%E5%89%B2%E3%82%8A%E8%BE%BC%E3%81%BF%E5%87%A6%E7%90%86%E3%81%AE%E7%89%B9%E5%BE%B4 

Linux Linux 2.6  NAPI NAPI 

f:id:y_uuki:20150330235452p:plain

(一)NICNIC  NIC 

(二)NIC  CPU  CPU (NIC )  NIC  ( DMA  CPU )

(三)

(四)readrecvrecvfrom 


64 1Gbps  1,500,000/sec  CPU 

CPU 10 Gbps  CPU 




TCP Implementation in Linux: A Brief Tutorial
8.3.  Red Hat Enterprise Linux 6 | Red Hat Customer Portal
Linux packet-forwarding
The Performance Analysis of Linux Networking  Packet Receiving

 CPU 


(MSI-X RSS ) NIC NIC  CPU   CPU TCP ()  TCP reordering reordering  CPU 

 Linux  CPU  CPU CPU L1, L2

 CPU 

 CPU (%user)  CPU  accept()  CPU  CPU  L1, L2


NIC()() NIC RSS(Receive Side Scaling)  RPS/RFS  RPS  RFS  RSS  RFS 

RSS/RPS/RFS Scaling in the Linux Networking Stack  RPS/RFS  Linux  2.6.35 RHLE  5.9 

[1][ATransport-FriendlyNICforMulticore/MultiprocessorSystems]  [2][mTCP: a Highly Scalable User-level TCP Stack for Multicore Systems] 

RSSReceive Side Scaling)


 CPU  NIC  CPU  CPU 

TCP reordering "" IP src/dst IP src/dst 4

 128  7 bit 

RPS (Receive Packet Steering)


RSS  NIC NIC 使 RSS (Linux) RPS 

RPS  NIC  CPU (IPI: Inter-processor interrupt) CPU 

 CPU  RSS src/dst IP src/dst 4Consistent-Hashing  CPU 

f:id:y_uuki:20150330235500p:plain
RPS 3


 NIC 





 CPU 1 CPU  CPU  (RSS  MSI-X 使)




RPS 使NIC  NIC  rx-0  NIC  rx-N 
# echo "f" > /sys/class/net/eth0/queues/rx-0/rps_cpus

rps_cpus  CPU  "f" 2 1111  CPU0 ~ CPU3 1 CPU  "f"  CPU0,1,2,3  RPS  CPU  CPU  0 16  https://www.kernel.org/doc/Documentation/IRQ-affinity.txt 

RFS (Receive Flow Steering)


RPS  L1, L2 RPS CPU accept(2)  read(2)  CPU  CPU 

RFS  RPS   Consistent-Hashing CPU  CPU   CPU  CPU recv_message  CPU 

RFS RPS  rps_cpus rps_flow_cnt  rps_sock_flow_entries 
# echo "f" > /sys/class/net/eth0/queues/rx-0/rps_cpus
# echo 4096 > /sys/class/net/eth0/queues/rx-0/rps_flow_cnt
# echo 32768 > /proc/sys/net/core/rps_sock_flow_entries

rps_sock_flow_entries  ()65536  32768 

rps_flow_cnt  NIC 16 NIC rps_sock_flow_entries  32768 rps_flow_cnt  2048   NIC rps_flow_cnt  rps_sock_flow_entries 

CentOS6/sys/ 


( iperf )  10GBps NIC 使

iperf





CPU: Intel Core i5 3470 3.2GHz 2 (Hyper Threading)

NIC: Mellanox ConnectX-3 EN 10GbE PCI Express 3.0

OS: CentOS 5.9


CPU  BIOS  1.6 GHz CPU iperf()464iperf CPU0  softirq 使 100% 
CPU   %user   %nice    %sys %iowait    %irq   %soft  %steal   %idle
all    0.74    0.00   16.75    0.00    0.00   27.83    0.00   54.68
  0    0.00    0.00    0.00    0.00    0.00  100.00    0.00    0.00
  1    2.00    0.00   52.00    0.00    0.00    9.00    0.00   37.00
  2    0.00    0.00   14.95    0.00    0.00    3.74    0.00   81.31
  3    0.00    0.00    1.00    0.00    0.00    0.00    0.00   99.00

 RFS CPU1,CPU2,CPU3 system  softirq 
# echo "f" > /sys/class/net/eth0/queues/rx-0/rps_cpus
# echo 4096 > /sys/class/net/eth0/queues/rx-0/rps_flow_cnt
# echo 32768 > /proc/sys/net/core/rps_sock_flow_entries
CPU   %user   %nice    %sys %iowait    %irq   %soft  %steal   %idle
all    0.24    0.00   11.86    0.00    0.00   23.00    0.00   64.89
  0    0.00    0.00   11.11    0.00    0.00   38.38    0.00   50.51
  1    0.95    0.00   12.38    0.00    0.00   19.05    0.00   67.62
  2    0.00    0.00   13.21    0.00    0.00   18.87    0.00   67.92
  3    0.00    0.00   12.50    0.00    0.00   16.35    0.00   71.15

(Starlet)


Perl  Starlet  RFS 


EC2 c3.4xlarge SR-IOV

CPU: Intel Xeon E5-2680 v2 @ 2.80GHz 16

NIC: Intel 82599 10 Gigabit Ethernet Controller

NIC driver: ixgbevf 2.7.12

OS: 3.10.23 Debian Wheezy


RFS 
# echo "ffff" > /sys/class/net/eth0/queues/rx-0/rps_cpus
# echo 32768 > /sys/class/net/eth0/queues/rx-0/rps_flow_cnt
# echo 32768 > /proc/sys/net/core/rps_sock_flow_entries

RFS CPU0  CPU CPU0  softirq(%soft)  15% idle  9% 
CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest   %idle
all   31.73    0.00    1.47    0.13    0.00    0.96    0.06    0.00   65.64
  0   70.41    0.00    5.10    0.00    0.00   15.31    0.00    0.00    9.18
  1   68.04    0.00    3.09    0.00    0.00    0.00    0.00    0.00   28.87
  2   53.06    0.00    3.06    0.00    0.00    0.00    0.00    0.00   43.88
  3   47.47    0.00    2.02    0.00    0.00    0.00    1.01    0.00   49.49
  4   49.45    0.00    1.10    0.00    0.00    0.00    0.00    0.00   49.45
  5   44.33    0.00    2.06    0.00    0.00    0.00    0.00    0.00   53.61
  6   38.61    0.00    2.97    0.99    0.00    0.00    0.00    0.00   57.43
  7   32.63    0.00    1.05    0.00    0.00    0.00    0.00    0.00   66.32
  8   29.90    0.00    1.03    1.03    0.00    0.00    0.00    0.00   68.04
  9   10.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00   90.00
 10    8.08    0.00    1.01    0.00    0.00    0.00    0.00    0.00   90.91
 11    6.12    0.00    0.00    0.00    0.00    0.00    0.00    0.00   93.88
 12   10.00    0.00    2.00    0.00    0.00    0.00    0.00    0.00   88.00
 13   11.00    0.00    1.00    0.00    0.00    0.00    0.00    0.00   88.00
 14   17.71    0.00    0.00    0.00    0.00    0.00    0.00    0.00   82.29
 15   11.22    0.00    1.02    0.00    0.00    0.00    0.00    0.00   87.76

RFS softirq(si) user(%usr)  system(%sys) 
CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest   %idle
all   27.41    0.00    3.07    0.00    0.00    0.70    0.13    0.00   68.69
  0   36.08    0.00    8.25    0.00    0.00    6.19    0.00    0.00   49.48
  1   30.43    0.00    3.26    0.00    0.00    0.00    0.00    0.00   66.30
  2   31.96    0.00    4.12    0.00    0.00    2.06    0.00    0.00   61.86
  3   35.64    0.00    3.96    0.00    0.00    0.00    0.99    0.00   59.41
  4   44.12    0.00    1.96    0.00    0.00    0.98    0.00    0.00   52.94
  5   37.00    0.00    9.00    0.00    0.00    0.00    0.00    0.00   54.00
  6   38.78    0.00    1.02    0.00    0.00    1.02    0.00    0.00   59.18
  7   39.00    0.00    6.00    0.00    0.00    1.00    1.00    0.00   53.00
  8   19.59    0.00    3.09    0.00    0.00    0.00    0.00    0.00   77.32
  9   23.16    0.00    3.16    0.00    0.00    0.00    0.00    0.00   73.68
 10   17.17    0.00    4.04    0.00    0.00    0.00    0.00    0.00   78.79
 11   18.00    0.00    3.00    0.00    0.00    0.00    0.00    0.00   79.00
 12   16.49    0.00    0.00    0.00    0.00    0.00    0.00    0.00   83.51
 13   16.33    0.00    0.00    0.00    0.00    1.02    0.00    0.00   82.65
 14   16.00    0.00    1.00    0.00    0.00    0.00    0.00    0.00   83.00
 15   16.67    0.00    0.00    0.00    0.00    0.00    0.00    0.00   83.33

softirq user  system  CPU 

 Starlet  HAProxypgpoolVarnish  RFS 

 memcached  LVSLinux 


CentOS 6.2  RPS/RFS 使 - blog.nomadscafe.jp
CentOS5RPS/RFSNIC | Nekoya press
Re: CentOS5RPS/RFSNIC - 



Scaling in the Linux Networking Stack





rfs: Receive Flow Steering [LWN.net]

RFS 



10GbEI/O

RSS/RFS 



Linux packet-forwarding
Linux / x86_64 1 |  |  | VA Linux Systems Japan

RFS  @ten_forward 

@y_uuk1 この辺りも関連資料かな :)https://t.co/P762uGwFOwhttps://t.co/gpm9wssjNM

 🅣enForward🖖 (@ten_forward) 2015331
 


Linux  RFS  RFS 使



使CPULinux  softirq (http://www.slideshare.net/syuu1228/10-gbeio  softirq )

2C

ryot_a_raiが、y_uuk1くんのブログのカーネルチューニング、とりあえず本番APPにいれてみますねーと言ってやってみたら応答速度が10%ぐらい速くなってびっくりした http://t.co/5q5iweUrnD

  (@mikeda) 201542
 

:  CPU 


10GbEI/O 

CPUCPU()

CPU()NICASIC NICNIC ethtool -k eth0 rx-checksumming TCPNIC TCP Offload Engine (TOE) 

NIC1NICCPU1Interrupt Coalescing NIC Interrupt Coalescing  Interrupt Coalescing 使EC2 EC2SR-IOV使NIC -  

NIC 

Linux 2.6 使 NAPI  NIC  NAPI  Interrupt Coalescing 1NICCPUCPU  NIC  CPU  NIC  NIC1 e1000  igb NIC NAPI  Linux NAPI 

詳解 Linuxカーネル 第3版

詳解 Linuxカーネル 第3版