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
After switch to tokio 0.2 from 0.2.0-alpha.6, I found a performance decrease #1859
Comments
try wrapping the main fn in a spawn(...).await and let me know how that impacts results? I can try to dig in next week if it doesn't help. The steps to repro are to just run |
Thanks for your reply. After I read through the documentation, I found that I only had the feature 'macros' and 'time' enabled and did not enable the rt-thread feature. After I enable it, the example takes 900ms to run the example. One small suggestion: it might be more helpful to the newcomers if you listed all the features in the documentation. |
What happens when you do the spawn thing from ^^? |
If there are any perf regressions from the alpha, I consider they a bug |
Do you mean wrap like this ? #[tokio::main]
async fn main() {
env_logger::init();
tokio::spawn(async {
let mark = Instant::now();
let (tx, mut rx) = mpsc::channel::<()>(MAX);
do_redis(tx).await.unwrap();
let mut num: usize = 0;
while let Some(_) = rx.next().await {
num += 1;
if num == MAX {
break;
}
}
println!("costs {:?}", mark.elapsed());
})
.await;
} |
Here are some test data tokio 0.2spawn 5000 requests
spawn 1000 requests
tokio 0.2 alpha.6spawn 5000 requests
spawn 1000 requests
|
Ok thanks, this is unexpected. I will try to dig in more soon. |
Can you explain more how you get that data? What is init pool cost vs. total cost? How can I repro? |
I dug into it. I believe the small performance regression you are still seeing is due to the redis crate still being on Tokio 0.1. Because of this, you are running two runtimes simultaneously (0.1 and 0.2) and there is overhead in communicating between them. I would suggest trying to update the redis crate to 0.2 and then seeing what results you get. I expect they will be favorable. |
The test code is almost the same as the previous example. Here are the test data. tokio 0.2 + tokio-postgres 0.5.0-alpha.2(upgraded to tokio 0.2)spawn 5000
spawn 1000
tokio 0.2-alpha + tokio-postgres =0.5.0-alpha.1spawn 5000
spawn 1000
As you can see, they're pretty close. |
Still not what I would expect. Assuming that this is what you are testing, could you wrap main in a #[tokio::main]
async fn main() {
// env_logger::init();
tokio::spawn(async {
let mark = Instant::now();
let (tx, mut rx) = mpsc::channel::<()>(MAX);
do_postgres(tx).await.unwrap();
let mut num: usize = 0;
while let Some(_) = rx.next().await {
num += 1;
if num == MAX {
break;
}
}
println!("cost {:?}", mark.elapsed());
}).await.unwrap();
} If that doesn't improve things measurably, could you help me reproduce your benchmark? It looks like i need postgresql running somehow, are there steps to reproduce the test? |
Sorry for late. When I wrap main in a To run this example, you just need to set up a Postgres server at local and create a user and a database that has the same name, and then you should change the connecting config in the code and run. |
After switch to tokio 0.2 from 0.2.0-alpha.6, I found a performance decrease
Version
Platform
Darwin helloworlddeMBP 18.0.0 Darwin Kernel Version 18.0.0: Wed Aug 22 20:13:40 PDT 2018; root:xnu-4903.201.2~1/RELEASE_X86_64 x86_64
Description
mobc is a database connection pool, it uses tokio 0.2.0-alpha.6. After tokio 0.2 has been released, I want to switch to version 0.2. But when I finished upgraded, mine example has a performance decrease.
There are two versions of the examples.
The old one
https://github.com/importcjj/mobc/blob/master/redis/examples/global_tokio_runtime.rs
The new one
https://github.com/importcjj/mobc/blob/tokio-0.2/redis/examples/global_tokio_runtime.rs
They are almost the same. As for
DefaultExcutor
, in the tokio 0.2.0-alpha.6, it'stokio::executor::DefaultExcutor
, and in tokio 0.2, it's just a wrapper to call the global spawn function.I don't know where the problem is. Someone can help me?
The text was updated successfully, but these errors were encountered: