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

考虑支持 tokio 和 async-std ? #8

Open
kuyoonjo opened this issue Dec 7, 2021 · 5 comments
Open

考虑支持 tokio 和 async-std ? #8

kuyoonjo opened this issue Dec 7, 2021 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@kuyoonjo
Copy link

kuyoonjo commented Dec 7, 2021

看到这里使用的是 may 这个运行库。有没有考虑支持 tokio 和 async-std 呢?

@zhuxiujia
Copy link
Member

zhuxiujia commented Dec 7, 2021

看到这里使用的是 may 这个运行库。有没有考虑支持 tokio 和 async-std 呢?

由于fast_log 使用异步库只处理 通道接受日志,并处理后续Appender的IO事件(打印日志,发送日志到网络IO....)等等,
实际测试在协程量较少情况下,may 相比tokio协程切换更积极,同时开销小于传统线程。因此目前选择它做为支持的异步库。

更换tokio(而且是建立在使用tokio的单线程Runtime 模拟Actor运行时)诚然能提高稍多的并发,但是代价是单协程的延迟增高。但是我们打印日志基本都是不超过5条协程在工作。

保持简单,高性能即可

@kuyoonjo
Copy link
Author

kuyoonjo commented Dec 7, 2021

因为这边使用很多东西包括 Web 服务 rweb 都是基于 tokio 的。换 runtime 不实际。这个库也是可以正常用的。只是担心同时跑两个 runtimes 会不会有问题呢?

@zhuxiujia
Copy link
Member

因为这边使用很多东西包括 Web 服务 rweb 都是基于 tokio 的。换 runtime 不实际。这个库也是可以正常用的。只是担心同时跑两个 runtimes 会不会有问题呢?

不影响你的。

@kuyoonjo kuyoonjo closed this as completed Dec 7, 2021
@kuyoonjo kuyoonjo reopened this Dec 7, 2021
@kuyoonjo
Copy link
Author

kuyoonjo commented Dec 7, 2021

实际上还是有影响的呢。我的机子是 8 核 8 线程的。运行只有 tokio 的程序有 9 全线程。加上这个库后变成 20 个线程了呢。

clee-test $ ps -ax|grep hello-tokio
45652 ttys005    0:00.04 target/debug/hello-tokio
45760 ttys007    0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox hello-tokio
clee-test $ ps -M 45652
USER   PID   TT   %CPU STAT PRI     STIME     UTIME COMMAND
yu   45652 s005    0.0 S    31T   0:00.01   0:00.01 target/debug/hello-tokio
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00

下面是没有启用 Log 的。

clee-test $ ps -ax|grep hello-tokio
46095 ttys005    0:00.02 target/debug/hello-tokio
46122 ttys007    0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox hello-tokio
clee-test $ ps -M 46095
USER   PID   TT   %CPU STAT PRI     STIME     UTIME COMMAND
yu   46095 s005    0.0 S    31T   0:00.01   0:00.00 target/debug/hello-tokio
     46095         0.0 S    31T   0:00.00   0:00.00
     46095         0.0 S    31T   0:00.00   0:00.00
     46095         0.0 S    31T   0:00.00   0:00.00
     46095         0.0 S    31T   0:00.00   0:00.00
     46095         0.0 S    31T   0:00.00   0:00.00
     46095         0.0 S    31T   0:00.00   0:00.00
     46095         0.0 S    31T   0:00.00   0:00.00
     46095         0.0 S    31T   0:00.00   0:00.00

@zhuxiujia
Copy link
Member

zhuxiujia commented Dec 7, 2021

实际上还是有影响的呢。我的机子是 8 核 8 线程的。运行只有 tokio 的程序有 9 全线程。加上这个库后变成 20 个线程了呢。

clee-test $ ps -ax|grep hello-tokio
45652 ttys005    0:00.04 target/debug/hello-tokio
45760 ttys007    0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox hello-tokio
clee-test $ ps -M 45652
USER   PID   TT   %CPU STAT PRI     STIME     UTIME COMMAND
yu   45652 s005    0.0 S    31T   0:00.01   0:00.01 target/debug/hello-tokio
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00
     45652         0.0 S    31T   0:00.00   0:00.00

下面是没有启用 Log 的。

clee-test $ ps -ax|grep hello-tokio
46095 ttys005    0:00.02 target/debug/hello-tokio
46122 ttys007    0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox hello-tokio
clee-test $ ps -M 46095
USER   PID   TT   %CPU STAT PRI     STIME     UTIME COMMAND
yu   46095 s005    0.0 S    31T   0:00.01   0:00.00 target/debug/hello-tokio
     46095         0.0 S    31T   0:00.00   0:00.00
     46095         0.0 S    31T   0:00.00   0:00.00
     46095         0.0 S    31T   0:00.00   0:00.00
     46095         0.0 S    31T   0:00.00   0:00.00
     46095         0.0 S    31T   0:00.00   0:00.00
     46095         0.0 S    31T   0:00.00   0:00.00
     46095         0.0 S    31T   0:00.00   0:00.00
     46095         0.0 S    31T   0:00.00   0:00.00

may默认是cpu*2线程,你可以设置它为2线程(至少)。
may::config().set_workers(2);

@zhuxiujia zhuxiujia added the help wanted Extra attention is needed label Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants