[PYTHON] Actix-web performance

I was interested in web apps and Rust, so I compared the performance of web frameworks to see how fast they work.

environment


windows 10 pro
Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz 2.71GHz
RAM: 8.00 GB
system 64bit

Web server creation

Web framework to use Rust: Actix-web Python: Flask Julia: Genie

Hello World app creation First of all, Actix

command


cargo new hello-world
cd hello-world

Edit main.rs in \ hello-world \ src.

main.rs


use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder};

#[get("/")]
async fn hello() -> impl Responder {
    HttpResponse::Ok().body("Hello world!")
}

#[post("/echo")]
async fn echo(req_body: String) -> impl Responder {
    HttpResponse::Ok().body(req_body)
}

async fn manual_hello() -> impl Responder {
    HttpResponse::Ok().body("Hey there!")
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        App::new()
            .service(hello)
            .service(echo)
            .route("/hey", web::get().to(manual_hello))
    })
    .bind("0.0.0.0:8080")?
    .run()
    .await
}

Flask

Create server.py in an appropriate folder.

server.py


from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    return 'Hello World'


if __name__ == '__main__':
    app.debug = True
    app.run(host='0.0.0.0', port=8001)

Genie created in Julia

command


julia
using Genie
Genie.newapp("hello_world")

Since the file set is created automatically, exit julia and edit the routes.jl file.

routes.jl


using Genie.Router

route("/") do
  "Hello - Welcome to Genie!"
end

Genie.AppServer.startup(8000, "0.0.0.0")

Now that I think about it, I might have just done the following in julia without creating a fileset. .. .. ..

"Hello - Welcome to Genie!"
end
Genie.AppServer.startup(8000, "0.0.0.0")```

 Leave the three web apps running and use another PC (ubuntu20.04) to measure performance.

# Performance measurement

 Use wrk2.
https://github.com/giltene/wrk2


#### **`command`**
```ubuntu

sudo apt-get install -y build-essential libssl-dev git zlib1g-dev
git clone https://github.com/giltene/wrk2.git
cd wrk2
make
sudo cp wrk /usr/local/bin
wrk -v
wrk 4.0.0 [epoll] Copyright (C) 2012 Will Glozer
Usage: wrk <options> <url>                            
  Options:                                            
    -c, --connections <N>  Connections to keep open   
    -d, --duration    <T>  Duration of test           
    -t, --threads     <N>  Number of threads to use   
                                                      
    -s, --script      <S>  Load Lua script file       
    -H, --header      <H>  Add header to request      
    -L  --latency          Print latency statistics   
    -U  --u_latency        Print uncorrected latency statistics
        --timeout     <T>  Socket/request timeout     
    -B, --batch_latency    Measure latency of whole   
                           batches of pipelined ops   
                           (as opposed to each op)    
    -v, --version          Print version details      
    -R, --rate        <T>  work rate (throughput)     
                           in requests/sec (total)    
                           [Required Parameter]       
                                                      
                                                      
  Numeric arguments may include a SI unit (1k, 1M, 1G)
  Time arguments may include a time unit (2s, 2m, 2h)

Use wrk2img to display the graph. https://github.com/PPACI/wrk2img

command


pip3 install wrk2img
#It didn't work so I put on sudo

I will measure it. See below for how to use and view. https://qiita.com/RyujiKawazoe/items/1da4342d8854543ca4cc

command


wrk -U -d 30 -c 100 -R 1000 --latency http://192.168.1.95:8080/ | wrk2img actix_100.png
wrk -U -d 30 -c 100 -R 1000 --latency http://192.168.1.95:8001/ | wrk2img flask_100.png
wrk -U -d 30 -c 100 -R 1000 --latency http://192.168.1.95:8000/ | wrk2img genie_100.png

result of actix

actix_100.png

Flask results

flask_100.png

Genie results

genie_100.png

Flask <Genie <actix, so actix seems to perform better.

Graph when the number of actix connections is increased at the end (10,100,1000,10000) actix.png

There is no load up to 100, but it seems to be affected when it reaches 1000.

that's all

Recommended Posts

Actix-web performance
Performance evaluation index
Redis performance measurement
Batting performance calculator
Performance improvement efforts