• # Rustlang

    Posté par (site web personnel) . En réponse au journal Java : presque 9 000 requêtes par seconde avec 8 Mo de RAM. Évalué à 7. Dernière modification le 13 juin 2022 à 20:54.

    En rust;

    $ cargo init renard

    Dans le fichier Cargo.toml sous [dependencies] ajouter :
    actix-web = "4"
    rand= "0.8.5"

    Dans le src/main.rs :

    use actix_web::{get, App, HttpResponse, HttpServer, Responder};
    use rand::Rng;
    #[get("/")]
    async fn hello() -> impl Responder {
     let mut rng = rand::thread_rng();
     HttpResponse::TemporaryRedirect()
     .append_header(("Location", format!("https://avatar.spacefox.fr/Renard-{}.png",rng.gen_range(1..21))))
     .finish()
    }
    #[actix_web::main]
    async fn main() -> std::io::Result<()> {
     HttpServer::new(|| {
     App::new()
     .service(hello) 
     })
     .bind(("127.0.0.1", 8080))?
     .run()
     .await
    }
    

    avec le test :
    $ cargo build
    $ cargo run
    $ ab -n 100000 -c 10 http://localhost:8080/
    ...
    Requests per second: 12180.63 #/sec
    ...

    Et en version release :
    $ cargo build --release
    $ cargo run --release
    $ ab -n 100000 -c 10 http://localhost:8080/
    ...
    Requests per second: 23764.99 #/sec
    ...
    Percentage of the requests served within a certain time (ms)
    50% 0
    66% 0
    75% 0
    80% 0
    90% 0
    95% 1
    98% 1
    99% 1
    100% 3 (longest request)

    ps aux :
    VSZ : 338Ko RSS: 4.2Ko
    cpu : i7-8565U CPU @ 1.80GHz

    "La première sécurité est la liberté"