ss 在 centos 6.6/7.1 上比 netstat 慢

ss is slow than netstat on centos 6.6/7.1

这是我的测试脚本

echo "=====ss===="
time ss -o state established | wc -l

echo "====netstat===="
time netstat -ant | grep EST | wc -l

输出为:

[root@lab8106 ~]# ./test_network.sh 
=====ss====
268

real    0m0.212s
user    0m0.183s
sys     0m0.033s
====netstat====
169

real    0m0.026s
user    0m0.009s
sys     0m0.025s

因为我看过很多博客,他们说 "ss" 比 "netstat" 快得多, 但是我上面的测试结果让我很困惑。我应该怎么做才能更深入地研究它?

您为 ss 忘记了 -n,因此您实际上是在为每个 IP 执行反向 DNS 查找,这肯定会延长执行时间。