Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
RustのWebフレームワーク周りの概観
Search
hayao
July 20, 2022
Programming
0
620
RustのWebフレームワーク周りの概観
FutureCon2022での登壇資料です。
RustのWebフレームワーク周りの代表的なソフトウェアスタックであるaxum、hyper、tokio、mio、towerについて簡単に説明しました。
hayao
July 20, 2022
Tweet
Share
Other Decks in Programming
See All in Programming
Startups on Rails in Past, Present and Future–Irina Nazarova, RailsConf 2025
irinanazarova
0
110
VS Code Update for GitHub Copilot
74th
2
650
“いい感じ“な定量評価を求めて - Four Keysとアウトカムの間の探求 -
nealle
1
10k
Google Agent Development Kit でLINE Botを作ってみた
ymd65536
2
250
第9回 情シス転職ミートアップ 株式会社IVRy(アイブリー)の紹介
ivry_presentationmaterials
1
320
なんとなくわかった気になるブロックテーマ入門/contents.nagoya 2025 6.28
chiilog
1
270
PipeCDのプラグイン化で目指すところ
warashi
1
280
20250628_非エンジニアがバイブコーディングしてみた
ponponmikankan
0
690
A2A プロトコルを試してみる
azukiazusa1
2
1.4k
「テストは愚直&&網羅的に書くほどよい」という誤解 / Test Smarter, Not Harder
munetoshi
0
170
技術同人誌をMCP Serverにしてみた
74th
1
650
ペアプロ × 生成AI 現場での実践と課題について / generative-ai-in-pair-programming
codmoninc
2
18k
Featured
See All Featured
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
950
Embracing the Ebb and Flow
colly
86
4.7k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
50
5.5k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.9k
Typedesign – Prime Four
hannesfritz
42
2.7k
Building an army of robots
kneath
306
45k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Fireside Chat
paigeccino
37
3.5k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.6k
Build The Right Thing And Hit Your Dates
maggiecrowley
36
2.8k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
35
2.4k
Transcript
1 RustによるWeb開発のエコシステム
自己紹介 本田紘規 2021年4月新卒入社 金融系PJに従事 2
RustでWeb開発に触れたいきさつ ITほとんど未経験で入社 → 弊社はWebシステムの構築案件が多いので、Web開発の基礎を身に つける必要がある →Rustが好きだから、RustでWeb開発に入門しよう🤪 3
RustでWeb開発を行うメリット • GCがなく、C/C++と同程度に高速。 • 型付けが強く、コンパイラの補助も強力なので、安定したシステムを 構築しやすいかもしれない。 • クールな機能をたくさん持っているので生産性高く開発できる。 4
本発表で参照するクレートの関係 axum hyper Service tokio mio use use web framework
http server asynchronous runtime I/O library Routing ObjectをServiceに 変換してhyperに渡す 5
参照したバージョン axum 0.5.4 hyper 0.14.18 tokio 0.17.0 mio 0.8.0 tower
0.4.11 6
tokio axum hyper Service tokio mio use use web framework
http server asynchronous runtime I/O library Routing ObjectをServiceに 変換してhyperに渡す 7
tokio Rustのデファクトの非同期ランタイム。AWSの人が中心となって開発 していて、AWS内部でも使われている。 V1.0が出ていて成熟している。 関連クレートも充実しつつある。 • tracing • tokio-metrics •
tokio-console 8
tokio サンプル コード 9
Output 10
イメージ図 tokio runtime contextでspawnを呼べばtokioがtaskを良しなに実 行してくれる。 Thread Pool tokio runtime (multi
thread scheduler) spawn Future tokio runtime context SpawnにFutureを渡すとtaskが生成される block_onを呼ぶことでruntimeを起動 11
Futureトレイト 12
Futureトレイト Runtimeはpollを呼ぶことでtaskを進行させる。 pollはすぐに値を返すことが期待されていて • Poll::Pending • Poll::ready(val) のいずれかを返す 13
runtime task群の実行を管理 協調的スケジューリング taskがブロッキングI/Oを行って、ブロッキングしたり、busy loop に陥るのは厳禁 runtime全体がスタックする可能性がある。 ワークスティーリング idle状態のスレッドがbusyなスレッドからtaskを奪う 14
mio axum hyper Service tokio mio use use web framework
http server asynchronous runtime I/O library Routing ObjectをServiceに 変換してhyperに渡す 15
mio クロスプラットフォームI/Oライブラリ I/Oイベントを監視する。 I/O多重化 このI/Oイベント監視して! (複数イベント登録可能) mio register OS poll
Event loop 16
hyper axum hyper Service tokio mio use use web framework
http server asynchronous runtime I/O library Routing ObjectをServiceに 変換してhyperに渡す 17
hyper HTTPクライアント・サーバーライブラリ。SeanさんというAWSの人が開発 している。 高速であること、正確であることを重視しているらしい V1.0へのロードマップが公開されていて、V1.0になるのもそう遠くなさそう。 Web開発エコシステムにおける主な役割 • HTTPプロトコルによるクライアントとのやり取り • Serviceとソケットを紐づけ
18
axum axum hyper Service tokio mio use use web framework
http server asynchronous runtime I/O library Routing ObjectをServiceに 変換してhyperに渡す 19
axum tokioチームのdavidさんという方を中心に開発されているWebフレーム ワーク 2021年7月に発表された若いフレームワーク。現在も活発に開発が進め られている。 RouterとHandlerに注力している。 20
Routing 21
Handler 引数に欲しいものを書き並べていく方式 22
Handler トレイト 23
call 関数 ライブラリ使用者が実装したハンドラとcall関数の紐づけ call Request<B> handler URI Method Body res
Response (Pin<…>) from_request from_request from_request Into_response 24
tower axum hyper Service tokio mio use use web framework
http server asynchronous runtime I/O library Routing ObjectをServiceに 変換してhyperに渡す 25
tower Serviceトレイトを定義 雰囲気的にはJavaのServlet インターフェースのような もの axumとhyperの橋渡し 26
まとめ • RustによるWeb開発でaxumを使おうとすると、デフォルトでは hyper、tokio、mioが使われる。 • 基盤となるtokio、hyperは成熟していて、プロダクションで使えるク オリティ。 • Rustを使えば高速で安定したWebシステムを生産性高く構築できる かも?
27