obsidian-rs / obsidian

Ergonomic async http framework for reliable and efficient web
MIT License
26 stars 4 forks source link

Async/Await Migration #31

Closed plwai closed 4 years ago

plwai commented 4 years ago

Implement Async/Await to bring better developer experience.

Currently, Async/Await drastically lower down the performance within hyper. In Obsidian there is one part consumes a lot of resource too.

let service = make_service_fn(|_| {
    let server_clone = app_server.clone();
    async {
        Ok::<_, hyper::Error>(service_fn(move |req| {
            // This clone takes time to complete as it will be call every endpoint request invoked
            let server_clone = server_clone.clone(); 
            async move { Ok::<_, hyper::Error>(server_clone.resolve_endpoint(req).await) }
        }))
    }
});
plwai commented 4 years ago

Benchmark

using ./ab.exe -n 1000000 -k -c 8 http://localhost:3000/ with one core. The hyper with async/await is slower than the one before. For the issue stated above, it has been resolved and the result is shown below. It has a significant boost after eliminating clone process.

Hyper and Obsidian (Hello world)

Obsidian Hello World

ab_ob_hello

Hyper Hello World

ab_hyper_hello

Obsidian before and after optimization

Obsidian Example before removing clone

ab_ob_example_before

Obsidian Example after removing clone

ab_ob_example

Hyper and Obsidian (Before Async/Await)

Hyper before async/await

ab_hyper_old

Obsidian before async/await

ab_ob_example_old

jk-gan commented 4 years ago

Closing this issue as #32 is merged.