Trouble Benchmarking actix_web api with Criterion

I have been trying to add benchmarking using the Criterion crate to my actix_web application. I have been struggling to get it to work because the AsyncExecutor trait is not implemented for tokio 0.2.x. I tried implementing the trait for the actix_rt runtime but ran into issues there as well, code below

impl AsyncExecutor for ActixRuntime {
    fn block_on<T>(&self, future: impl Future<Output=T>) -> T {
        self.rt.block_on(future)
    }
}

pub struct ActixRuntime {
    rt: actix_rt::Runtime,
}

impl ActixRuntime {
    pub fn new() -> Self {
        ActixRuntime {
            rt: actix_rt::Runtime::new().unwrap(),
        }
    }
}

this errors out because the block_on function for actix_rt (and tokio 0.2.x) is has a signature of block_on(&mut self, ...) -> ... { ... } So I cannot implement the trait since the trait has an immutable reference.

Before I dig myself further into trying to make this work I want to ask if what I am attempting is possible. Is there a way to use Criterion with actix? Or is this impossible as of now? If it is not possible are there any other frameworks available or should I look at solutions outside the rust toolchain?

Thanks for any advice or help, links and examples welcome!

Cheers!



Read more here: https://stackoverflow.com/questions/66298167/trouble-benchmarking-actix-web-api-with-criterion

Content Attribution

This content was originally published by Marcus Ruddick at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: