Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ISUCONにRustで挑戦した話 / Participating in ISUCON wi...

ISUCONにRustで挑戦した話 / Participating in ISUCON with Rust

https://forcia.connpass.com/event/187287/ に向けた発表資料です。

すてにゃん

October 20, 2020
Tweet

More Decks by すてにゃん

Other Decks in Programming

Transcript

  1. actix-web use actix_web::{web, App, HttpResponse, HttpServer}; // ϢʔβҰཡΛදࣔ͢Δ async fn

    show_users() -> HttpResponse { HttpResponse::Ok().body(“Show users…”) } // ΤϯυϙΠϯτ͝ͱʹͲͷؔ਺ΛݺͿ͔ͳͲ͜͜Ͱهड़͢Δ #[actix_rt::main] async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new().service( web::scope(“/users”) .route(“/show”, web::get().to(show_users)), ) }) .bind(“127.0.0.1:8088”)? .run() .await } RustͷWeb framework https://github.com/actix/ actix-web
  2. Tera <h2>My Programming Languages</h2> <ul> {% for language in programming_languages

    %} {% if language.name == “rust” %} <li>Rust Rules!!!!</li> {% else %} <li>{{ language.name }}</li> {% endif %} {% endfor %} </ul> … Template engine inspired by Jinja2 https://github.com/Keats/ tera
  3. reqwest let client = reqwest::Client::new(); // form()ͷଞʹbody()ͱ͔json()ͱ͔΋࢖͑Δ let res =

    client.post(“https://…”) .form(&params) .send() .await?; RustͷHTTPΫϥΠΞϯτ https://github.com/ seanmonstar/reqwest
  4. serde use actix_web::{HttpResponse, Responder}; use serve::{Serialize, Deserialize}; #[derive(Serialize, Deserialize)] struct

    User { id: i32, username: String, name: String } async fn user_detail_json() -> imp Responder { let user = User { id: 12345, username: “stefafafan”.to_string(), name: “ͯ͢ʹΌΜ”.to_string(), } // ͜Ε͸actix_webͷؔ਺͚ͩͲJSONͱͯ͠ฦͤͯΔ HttpResponse::Ok().json(user) } Rust޲͚ʹσʔλΛSerialize/ Deserialize͢ΔϑϨʔϜϫʔΫ https://github.com/serde-rs/ serde
  5. SQLx use sqlx::{MySqlPool}; async fn main() -> std::io::Result<()> { let

    pool = MySqlPool::connect(&DATABASE_URL).await; let row = sqlx::query!(“SELECT …”) .fetch_all(&pool) .await .unwrap(); … } Rust޲͚SQLϥΠϒϥϦ https://github.com/ launchbadge/sqlx
  6. ISUCON10 ༧બ֓ཁ • Πεʹ߹͏෺݅Λݕࡧ͢ΔαΠτ(ISUUMO) ҎԼͷΑ͏ͳը໘͕͋Δ • Πεͷݕࡧ • ෺݅ͷݕࡧ •

    Πεɾ෺݅ͷৄࡉը໘ • ϚοϓΛϚ΢εͰͳͧͬͯൣғ಺ʹؚ·ΕΔ෺݅Λදࣔ