Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

性能恶劣? #80

Open
PikuZheng opened this issue Mar 22, 2023 · 13 comments
Open

性能恶劣? #80

PikuZheng opened this issue Mar 22, 2023 · 13 comments

Comments

@PikuZheng
Copy link
Contributor

使用dnspref测试,脚本参考 pymumu/smartdns#1337 (comment)

受cpu性能限制,c++查询效率大约每秒2万次(目标5万次),cpu使用率90%以上 pymumu/smartdns#1337 (comment)

rust版采用相同配置,查询效率大约每秒2百次,cpu使用率约20%。

localhost:~/test# sh ./runquerypref.sh
DNS Performance Testing Tool
Version 2.11.1

[Status] Command line: dnsperf -p 53 -s 172.19.0.4 -d ./data/querytest_400W.txt
[Status] Sending queries (to 172.19.0.4:53)
[Status] Started at: Wed Mar 22 14:51:15 2023
[Status] Stopping after 1 run through file
^C[Status] Testing complete (interruption)

Statistics:

  Queries sent:         677060
  Queries completed:    676960 (99.99%)
  Queries lost:         0 (0.00%)
  Queries interrupted:  100 (0.01%)

  Response codes:       NOERROR 676960 (100.00%)
  Average packet size:  request 31, response 63
  Run time (s):         2886.670816
  Queries per second:   234.512365

  Average Latency (s):  0.426340 (min 0.058085, max 3.345481)
  Latency StdDev (s):   0.368039

image

·测试结果符合预期吗?
·如何提高运行效率(比如更换编译器、静态链接、增加内存)?

@mokeyish
Copy link
Owner

mokeyish commented Mar 22, 2023

还有很大上升空间啊😂。

  • 这个版本锁死了线程数,只有 4 个线程
    .worker_threads(4)
  • 域名匹配,没有用 mph ,这块查找规则也慢
    https://crates.io/crates/boomphf
  • 还有缓存那块,存在锁,应该还有优化空间。
  • 最后是查询那,目前直接用了上游类库的,例如 Http2 是可以多路复用的,这个还没深入研究。

@mokeyish
Copy link
Owner

mokeyish commented Apr 1, 2023

@PikuZheng

我在 linux x86_64 测了下,把线程数放开后,Rust 版性能比 C 版,好差不多 30 %(但会丢失一小部分的查询)

你重新再测一下?


Rust 版
图片


C 版

图片


Rust 版,工作线程数,可用下面的方式配置,使用的线程数量,默认是 CPU 的核数

num-workers 4

"num-workers" => self.num_workers = options.parse().ok(),

Sets the number of worker threads the Runtime will use.

This can be any number above 0 though it is advised to keep this value on the smaller side.

This will override the value read from environment variable TOKIO_WORKER_THREADS.
Default

The default value is the number of cores available to the system.

When using the current_thread runtime this method has no effect.

@PikuZheng
Copy link
Contributor Author

新版编译不过去。。。坑

@mokeyish
Copy link
Owner

mokeyish commented Apr 1, 2023

新版编译不过去。。。坑

什么问题?

@PikuZheng
Copy link
Contributor Author

error[E0425]: cannot find value `DCCP_SOCKOPT_SERVICE` in crate `libc`
    --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.5.1/src/sys/unix.rs:2452:23
     |
2452 |                 libc::DCCP_SOCKOPT_SERVICE,
     |                       ^^^^^^^^^^^^^^^^^^^^ not found in `libc`

error[E0425]: cannot find value `DCCP_SOCKOPT_SERVICE` in crate `libc`
    --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.5.1/src/sys/unix.rs:2466:66
     |
2466 |         unsafe { getsockopt(self.as_raw(), libc::SOL_DCCP, libc::DCCP_SOCKOPT_SERVICE) }
     |                                                                  ^^^^^^^^^^^^^^^^^^^^ not found in `libc`

error[E0425]: cannot find value `DCCP_SOCKOPT_CCID` in crate `libc`
    --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.5.1/src/sys/unix.rs:2475:66
     |
2475 |         unsafe { setsockopt(self.as_raw(), libc::SOL_DCCP, libc::DCCP_SOCKOPT_CCID, ccid) }
     |                                                                  ^^^^^^^^^^^^^^^^^ not found in `libc`

error[E0425]: cannot find value `DCCP_SOCKOPT_TX_CCID` in crate `libc`
    --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.5.1/src/sys/unix.rs:2486:66
     |
2486 |         unsafe { getsockopt(self.as_raw(), libc::SOL_DCCP, libc::DCCP_SOCKOPT_TX_CCID) }
     |                                                                  ^^^^^^^^^^^^^^^^^^^^ not found in `libc`

error[E0425]: cannot find value `DCCP_SOCKOPT_RX_CCID` in crate `libc`
    --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.5.1/src/sys/unix.rs:2497:66
     |
2497 |         unsafe { getsockopt(self.as_raw(), libc::SOL_DCCP, libc::DCCP_SOCKOPT_RX_CCID) }
     |                                                                  ^^^^^^^^^^^^^^^^^^^^ not found in `libc`

error[E0425]: cannot find value `DCCP_SOCKOPT_SERVER_TIMEWAIT` in crate `libc`
    --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.5.1/src/sys/unix.rs:2511:23
     |
2511 |                 libc::DCCP_SOCKOPT_SERVER_TIMEWAIT,
     |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in `libc`

error[E0425]: cannot find value `DCCP_SOCKOPT_SERVER_TIMEWAIT` in crate `libc`
    --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.5.1/src/sys/unix.rs:2529:23
     |
2529 |                 libc::DCCP_SOCKOPT_SERVER_TIMEWAIT,
     |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in `libc`

error[E0425]: cannot find value `DCCP_SOCKOPT_SEND_CSCOV` in crate `libc`
    --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.5.1/src/sys/unix.rs:2548:23
     |
2548 |                 libc::DCCP_SOCKOPT_SEND_CSCOV,
     |                       ^^^^^^^^^^^^^^^^^^^^^^^ not found in `libc`

error[E0425]: cannot find value `DCCP_SOCKOPT_SEND_CSCOV` in crate `libc`
    --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.5.1/src/sys/unix.rs:2562:66
     |
2562 |         unsafe { getsockopt(self.as_raw(), libc::SOL_DCCP, libc::DCCP_SOCKOPT_SEND_CSCOV) }
     |                                                                  ^^^^^^^^^^^^^^^^^^^^^^^ not found in `libc`

error[E0425]: cannot find value `DCCP_SOCKOPT_RECV_CSCOV` in crate `libc`
    --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.5.1/src/sys/unix.rs:2577:23
     |
2577 |                 libc::DCCP_SOCKOPT_RECV_CSCOV,
     |                       ^^^^^^^^^^^^^^^^^^^^^^^ not found in `libc`

error[E0425]: cannot find value `DCCP_SOCKOPT_RECV_CSCOV` in crate `libc`
    --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.5.1/src/sys/unix.rs:2591:66
     |
2591 |         unsafe { getsockopt(self.as_raw(), libc::SOL_DCCP, libc::DCCP_SOCKOPT_RECV_CSCOV) }
     |                                                                  ^^^^^^^^^^^^^^^^^^^^^^^ not found in `libc`

error[E0425]: cannot find value `DCCP_SOCKOPT_QPOLICY_TXQLEN` in crate `libc`
    --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.5.1/src/sys/unix.rs:2605:23
     |
2605 |                 libc::DCCP_SOCKOPT_QPOLICY_TXQLEN,
     |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in `libc`

error[E0425]: cannot find value `DCCP_SOCKOPT_QPOLICY_TXQLEN` in crate `libc`
    --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.5.1/src/sys/unix.rs:2623:23
     |
2623 |                 libc::DCCP_SOCKOPT_QPOLICY_TXQLEN,
     |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in `libc`

error[E0425]: cannot find value `DCCP_SOCKOPT_AVAILABLE_CCIDS` in crate `libc`
    --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.5.1/src/sys/unix.rs:2645:19
     |
2645 |             libc::DCCP_SOCKOPT_AVAILABLE_CCIDS,
     |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in `libc`

error[E0425]: cannot find value `DCCP_SOCKOPT_GET_CUR_MPS` in crate `libc`
    --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.5.1/src/sys/unix.rs:2663:23
     |
2663 |                 libc::DCCP_SOCKOPT_GET_CUR_MPS,
     |                       ^^^^^^^^^^^^^^^^^^^^^^^^ not found in `libc`

For more information about this error, try `rustc --explain E0425`.
error: could not compile `socket2` due to 15 previous errors

@mokeyish
Copy link
Owner

mokeyish commented Apr 1, 2023

#105 这个 PR 先修复,禁用设备绑定了。这个库 https://github.com/rust-lang/socket2 居然有问题

不会再出现此类编译问题了,已经加了 #107 CI 检查,代码合并前,得通过这些检查。

@PikuZheng
Copy link
Contributor Author

localhost:~/test# sh ./runquerypref.sh
DNS Performance Testing Tool
Version 2.11.1

[Status] Command line: dnsperf -p 53 -s 172.19.0.4 -d ./data/querytest_400W.txt
[Status] Sending queries (to 172.19.0.4:53)
[Status] Started at: Tue Apr  4 19:31:06 2023
[Status] Stopping after 1 run through file
^C[Status] Testing complete (interruption)

Statistics:

  Queries sent:         1683132
  Queries completed:    1683032 (99.99%)
  Queries lost:         0 (0.00%)
  Queries interrupted:  100 (0.01%)

  Response codes:       NOERROR 1683032 (100.00%)
  Average packet size:  request 31, response 62
  Run time (s):         6804.565230
  Queries per second:   247.338653

  Average Latency (s):  0.404254 (min 0.055399, max 3.820666)
  Latency StdDev (s):   0.339117

似乎无改善

Mem: 3855964K used, 174348K free, 48724K shrd, 109932K buff, 1062416K cached
CPU:   0% usr   0% sys   0% nic  99% idle   0% io   0% irq   0% sirq
Load average: 0.38 1.16 1.31 2/1000 247
  PID  PPID USER     STAT   VSZ %VSZ CPU %CPU COMMAND
   11     0 root     S     382m  10%   1   0% {smartdns-runtim} /usr/sbin/smartdns run -c /etc/smartdns/smartdns.conf -d -p -
   10     0 root     S     382m  10%   0   0% {smartdns-runtim} /usr/sbin/smartdns run -c /etc/smartdns/smartdns.conf -d -p -
    9     0 root     S     382m  10%   1   0% {smartdns-runtim} /usr/sbin/smartdns run -c /etc/smartdns/smartdns.conf -d -p -
    8     0 root     S     382m  10%   0   0% {smartdns-runtim} /usr/sbin/smartdns run -c /etc/smartdns/smartdns.conf -d -p -
    1     0 root     S     382m  10%   1   0% /usr/sbin/smartdns run -c /etc/smartdns/smartdns.conf -d -p -
  236     0 root     S     1692   0%   0   0% /bin/sh
  237   236 root     R     1620   0%   1   0% top -H

不过确实是四个线程了

@PikuZheng
Copy link
Contributor Author

image
而且cpu使用增加了。。。就挺迷惑

@mokeyish
Copy link
Owner

mokeyish commented Apr 4, 2023

无改善? 看你上面的意思你限制了4个线程?之前就是锁死了四个线程。

上面说 num-workers 4 ,只是示例可以这样控制线程数。不配置它才会使用所有 cpu。

@PikuZheng
Copy link
Contributor Author

PikuZheng commented Apr 4, 2023

无改善? 看你上面的意思你限制了4个线程?之前就是锁死了四个线程。

上面说 num-workers 4 ,只是示例可以这样控制线程数。不配置它才会使用所有 cpu。

我2核,,,不配置就是2线程。那么配置4线程cpu使用量是30%,我改成16试了cpu使用量仍是30%,但确实是16个线程了。
但是无改善。每秒查询只有200左右。应该不是线程的问题。

他那个测试脚本是重复测www.baidu.com,原则上应该完全命中缓存。但是脚本运行时看到有5Mbps的入站流量,感觉似乎完全没有命中缓存。

@mokeyish
Copy link
Owner

mokeyish commented Apr 4, 2023

那就奇怪了,为啥你电脑30%,cpu 利用率上不去难道卡在入站流量上了?

@PikuZheng
Copy link
Contributor Author

#105 这个 PR 先修复,禁用设备绑定了。这个库 https://github.com/rust-lang/socket2 居然有问题

不会再出现此类编译问题了,已经加了 #107 CI 检查,代码合并前,得通过这些检查。

rust-lang/libc 昨天发布0.2.141 release了说修复了编译问题

@PikuZheng
Copy link
Contributor Author

看了一下上端路由器的状态。性能测试时连接数满(6万多),大概一半是icmp连接。可见是缓存完全没有命中,时间都耗费在查询和测速上了。带宽占用大概5Mbps。
另外开了debug日志也有影响。关掉后每秒查询量由200上升到300。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants