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
第9回 情シス転職ミートアップ 株式会社IVRy(アイブリー)の紹介
ivry_presentationmaterials
1
250
Bytecode Manipulation 으로 생산성 높이기
bigstark
2
390
Rubyでやりたい駆動開発 / Ruby driven development
chobishiba
1
510
Team topologies and the microservice architecture: a synergistic relationship
cer
PRO
0
1.1k
NPOでのDevinの活用
codeforeveryone
0
470
Go1.25からのGOMAXPROCS
kuro_kurorrr
1
830
関数型まつりレポート for JuliaTokai #22
antimon2
0
160
Hypervel - A Coroutine Framework for Laravel Artisans
albertcht
1
110
PHP 8.4の新機能「プロパティフック」から学ぶオブジェクト指向設計とリスコフの置換原則
kentaroutakeda
2
680
今ならAmazon ECSのサービス間通信をどう選ぶか / Selection of ECS Interservice Communication 2025
tkikuc
20
3.8k
Node-RED を(HTTP で)つなげる MCP サーバーを作ってみた
highu
0
110
ソフトウェア品質を数字で捉える技術。事業成長を支えるシステム品質の マネジメント
takuya542
0
240
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
2.8k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
130
19k
Build The Right Thing And Hit Your Dates
maggiecrowley
36
2.8k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
17
950
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
252
21k
GraphQLとの向き合い方2022年版
quramy
49
14k
Building an army of robots
kneath
306
45k
What's in a price? How to price your products and services
michaelherold
246
12k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
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