UNIX DOMAIN SOCKET效率
关于UNIX DOMAIN SOCKET和普通udp socket的对比
在TX1(4核A57 1.7GHz)的板卡上进行测试,每个包大小设置为1024,全速收发,UDS的速度在90Mbps左右,UDP在120Mbps左右(略有丢包)
CPU占用率,UDS比UDP低10%,但是实际上,如果码率相近时,CPU占用率是差不多的
下面是UDP的CPU占用:
top - 08:44:46 up 3:04, 5 users, load average: 1.78, 1.70, 1.66 Threads: 195 total, 3 running, 192 sleeping, 0 stopped, 0 zombie %Cpu(s): 15.4 us, 31.3 sy, 0.0 ni, 51.3 id, 0.0 wa, 0.0 hi, 2.1 si, 0.0 st KiB Mem : 4078676 total, 3061964 free, 399460 used, 617252 buff/cache KiB Swap: 0 total, 0 free, 0 used. 3180808 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1397 root -88 0 487920 156364 2100 R 65.9 3.8 2:04.03 udp_send 1396 root -91 0 487920 156364 2100 R 56.3 3.8 1:48.16 udp_recv 1395 root rt 0 487920 156364 2100 S 38.7 3.8 1:15.88 data_out 1398 root -81 0 487920 156364 2100 S 29.8 3.8 0:58.27 data_in 915 nvidia 20 0 9020 3280 2568 S 0.7 0.1 1:25.59 top 7 root 20 0 0 0 0 S 0.3 0.0 0:43.18 rcu_preempt 146 root rt 0 0 0 0 S 0.3 0.0 0:26.44 cfinteractive 327 systemd+ 20 0 77312 1952 1740 S 0.3 0.0 0:06.22 sd-resolve 1393 root 20 0 487920 156364 2100 S 0.3 3.8 0:01.00 test_udp.out 1400 admin 20 0 8932 3304 2632 R 0.3 0.1 0:00.07 top 1 root 20 0 7044 5452 3524 S 0.0 0.1 0:02.68 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 2:52.41 ksoftirqd/0 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_sched 9 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh 10 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0 11 root rt 0 0 0 0 S 0.0 0.0 0:00.22 watchdog/0
这个是UDS的CPU占用率:
top - 08:45:22 up 3:05, 5 users, load average: 1.64, 1.68, 1.65 Threads: 195 total, 1 running, 194 sleeping, 0 stopped, 0 zombie %Cpu(s): 12.9 us, 28.2 sy, 0.0 ni, 58.9 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 4078676 total, 3061868 free, 399532 used, 617276 buff/cache KiB Swap: 0 total, 0 free, 0 used. 3180712 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1406 root -88 0 487916 156400 2136 S 53.5 3.8 0:05.85 udp_send 1405 root -91 0 487916 156400 2136 S 41.6 3.8 0:04.57 udp_recv 1407 root -81 0 487916 156400 2136 S 34.0 3.8 0:03.77 data_in 1404 root rt 0 487916 156400 2136 S 29.7 3.8 0:03.24 data_out 915 nvidia 20 0 9020 3280 2568 S 0.7 0.1 1:25.79 top 1402 root 20 0 487916 156400 2136 S 0.7 3.8 0:00.41 test.out 146 root rt 0 0 0 0 S 0.3 0.0 0:26.49 cfinteractive 1400 admin 20 0 8932 3304 2632 R 0.3 0.1 0:00.27 top 1403 root rt 0 487916 156400 2136 S 0.3 3.8 0:00.01 trace_tsk 1 root 20 0 7044 5452 3524 S 0.0 0.1 0:02.68 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 2:52.41 ksoftirqd/0 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H 7 root 20 0 0 0 0 S 0.0 0.0 0:43.20 rcu_preempt 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_sched 9 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh 10 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0 11 root rt 0 0 0 0 S 0.0 0.0 0:00.22 watchdog/0 12 root rt 0 0 0 0 S 0.0 0.0 0:00.20 watchdog/1 13 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/1 14 root 20 0 0 0 0 S 0.0 0.0 0:00.29 ksoftirqd/1 15 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/1:0 16 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/1:0H 17 root rt 0 0 0 0 S 0.0 0.0 0:00.21 watchdog/2 18 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/2 19 root 20 0 0 0 0 S 0.0 0.0 0:00.20 ksoftirqd/2 21 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/2:0H 22 root rt 0 0 0 0 S 0.0 0.0 0:00.22 watchdog/3 23 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/3 24 root 20 0 0 0 0 S 0.0 0.0 0:00.31 ksoftirqd/3 26 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/3:0H
理论上UDS不经过协议栈,不用计算校验和,但是为什么实际UDP速度还要快一些,那么UDS存在的价值在哪?