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
Boost.Asio入門
Search
Ryo Okubo
March 31, 2014
Programming
0
2.9k
Boost.Asio入門
会社の同期向け勉強会で発表した Boost.Asioの基本的な説明とか自分の気になった部分を調べたまとめ。
Ryo Okubo
March 31, 2014
Tweet
Share
More Decks by Ryo Okubo
See All by Ryo Okubo
メルカリ・メルペイの成長を支える データ基盤とはどんなものか
syucream
7
6.6k
バッチとストリーミング、それぞれの障害に立ち向かう
syucream
3
3.4k
How Scala works at Mercari
syucream
2
970
Production-ready stream data pipeline in Merpay, Inc
syucream
2
13k
データとML周辺エンジニアリン グを考える会 #2 イントロ
syucream
0
590
マイクロサービスにおける ログ収集の課題と取り組み
syucream
7
2.6k
Stream Data Pipeline for Microservices in Merpay
syucream
6
1.2k
メルペイにおける、マイクロサービスに寄り添うログ収集基盤 / Microservices-frendly Data Pipeline
syucream
0
18k
Merpay のデータ収集基盤
syucream
5
1k
Other Decks in Programming
See All in Programming
5年分のツケを一気に払った話
soogie
3
1.5k
Scan with Decoupled Look-back and Onesweep Radix Sort
shocker_0x15
0
110
rtcamp 10 (vk-illuminati)
yumcyawiz
0
130
Cloud Adoption Frameworkにみる組織とクラウド導入戦略(縮小版)
tomokusaba
1
220
Why I Choose NetBeans for Jakarta EE
ivargrimstad
0
290
CSC509 Lecture 04
javiergs
PRO
0
150
メルカリ ハロ アプリの技術スタック
atsumo
2
820
Cohesion in Modeling and Design
mploed
3
220
Jakarta EE as Seen Trough the Lens of the ASF
ivargrimstad
0
300
もう実家に手頃な情シス娘は不要!Bedrockでもう一人の娘を作る
komakichi
0
110
perl for shell, awk and sed programmers
mackee
1
740
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
1.2k
Featured
See All Featured
Adopting Sorbet at Scale
ufuk
73
9k
Gamification - CAS2011
davidbonilla
80
5k
The Power of CSS Pseudo Elements
geoffreycrofte
71
5.3k
It's Worth the Effort
3n
183
27k
Building Your Own Lightsaber
phodgson
102
6k
Building Better People: How to give real-time feedback that sticks.
wjessup
362
19k
Speed Design
sergeychernyshev
22
490
Designing for humans not robots
tammielis
249
25k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
664
120k
Product Roadmaps are Hard
iamctodd
PRO
48
10k
YesSQL, Process and Tooling at Scale
rocio
167
14k
Creatively Recalculating Your Daily Design Routine
revolveconf
217
12k
Transcript
Boost.Asio ೖ @syu_cream
ΞδΣϯμ Boost.Asio ͷհ جຊతͳಛ ΠϕϯτۦಈͱBoost.Asio εϨουͱBoost.Asio ίϧʔνϯͱBoost.Asio (༨༟͕͋Ε)αϯϓϧίʔυಡΈ (ߋʹ༨༟͕͋Ε)झຯͰॻ͍͍ͯΔ HTTP/2
؆қ࣮ʹ͍ͭͯ
Boost.Asio ͱ Boost ͷඇಉظωοτϫʔΫ௨৴ϥΠϒϥϦ ΠϕϯτۦಈI/Oͷαϙʔτ ϓϥοτϑΥʔϜͷࠩҟΛٵऩͯ͘͠ΕΔ ಉظ௨৴αϙʔτ
Asio Ͱαϙʔτ͢Δ௨৴ αϙʔτ͢Δϓϩτίϧͷछྨ TCP/UDP/ICMP ιέοτ γϦΞϧϙʔτ UNIX Domain Socket
Πϕϯτۦಈͱ Boost.Asio
Πϕϯτۦಈ I/O ಉ࣌ʹෳͷ I/O Λॲཧ͢ΔϞσϧ I/OͷྃΛݕग़͢ΔΠϕϯτϧʔϓΛ࣋ͭ I/Oྃ࣌ʹΠϕϯτϋϯυϥΛ࣮ߦ͢Δ ! " !!
!! !! ①"I/O" ! ! " ②"I/O"" !! ③!! "
Proactor pattern ΠϕϯτۦಈI/OΛ࣮ݱ͢ΔσβΠϯύλʔϯͷҰछ Πϕϯτϧʔϓͱϋϯυϥͷ࣮Λ લऀOSͷػೳ(select, poll, epoll/kqueueͳͲ)Λར༻ ޙऀࣗલͰ࣮ɻඞཁͳΒεϨουͰฒྻॲཧɻ
Boost.Asio ʹ͓͚Δ Proactor io_service ΦϒδΣΫτΛհͯ͠ I/O Λॲཧ͢Δ $:@.>< 8A7> I/O$+91*-6$
(:$3/46) io_service +;?B5)A.025< ①$I/O+9 1*-6 ② 8A7> " ③io_service$(run() !( ④$I/O$ ( ⑤$I/O % ,=B#'& io_service$'( ⑥I/O$( 8A7>#&$
io_service Boost.Asio ͷ௨৴ͷཁͱͳΔΦϒδΣΫτ Πϕϯτϧʔϓͷ࣮ߦ εϨουϓʔϧͷཧ OS ͷΠϕϯτ௨ػߏΛݺͼग़͠ ྃϋϯυϥͷݺͼग़͠
io_service ͷૢ࡞ io_service::run() ΠϕϯτॲཧϧʔϓΛϒϩοΩϯά࣮ͯ͠ߦ io_service::poll() ΠϕϯτॲཧϧʔϓΛϒϩοΩϯάͤͣʹ࣮ߦ io_service::post() Ωϡʔʹॲཧ͖͢ϋϯυϥΛՃ io_service::dispatch() ʢՄೳͰ͋Εʣͨ͠ϋϯυϥΛଈ࠲ʹ࣮ߦ
Asio ʹΑΔඇಉظTCP௨৴ boost::asio::ip::tcp::socket TCPιέοτΛදݱ͢Δ I/O ΦϒδΣΫτ boost::asio::async_connect ඇಉظʹ connect ͢Δ
boost::asio::ip::tcp::socket::async_accept ඇಉظʹ accept ͢Δ boost::asio::async_(read | write) ඇಉظʹ read/write ͢Δ
εϨουͱ Boost.Asio
εϨουͱͷؔ εϨουϓʔϧ ྃϋϯυϥͷॲཧΛ؆୯ʹϚϧνεϨουԽՄೳ io_service::run() ΛෳεϨου͔Βݺͼग़͢ͱε Ϩουϓʔϧ͕ߏங͞ΕΔ ෦εϨου ϗετ໊ղܾͳͲϥΠϒϥϦͰฒྻԽ͞ΕΔ
ίϧʔνϯͱ Boost.Asio
ྃϋϯυϥͷ࣮1: ී௨ʹίʔϧόοΫؔΛఆٛ ఆ൪ͷྃϋϯυϥͷॻ͖ํ ͨͩ͠ίʔυͷݟ௨͠ѱ͘ͳΔɻ
ྃϋϯυϥͷ࣮2: ແ໊ؔΛ͏ ؔ࿈͢Δॲཧͷهड़ΛूͰ͖Δ ͔͠͠ɺωετ͕ਂ͘ͳΔɻ
ྃॲཧͱίϧʔνϯ ௨৴ॲཧஞ࣍తʹهड़ग़དྷͨํ͕ײత ෳճͷରΛཁ͢Δϓϩτίϧ͠ΌΔ߹ͳͲ ॲཧ͕ෳࡶʹͳΔͱίʔϧόοΫࠈʹؕΔ ! Boost 1.53 ͔ΒBoost.Coroutine Λαϙʔτʂ ஞ࣍ॲཧͬΆ͘ඇಉظ௨৴ॲཧ͕هड़Ͱ͖Δ
ྃϋϯυϥͷ࣮3: ελοΫϨείϧʔνϯ Boost.Coroutine Λͬͯஞ࣍ॲཧతʹهड़ reenter() ʹίϧʔνϯͰ࣮ߦ͢ΔॲཧΛهड़ I/O ͢Δࡍ yield ͰίϯςΩετΛ”ৡΔ”
reenter() ֎ʢؔݺͼग़͠ઌͳͲʣͰ yield Ͱ͖ͳ͍͜ͱʹҙ
ྃϋϯυϥͷ࣮4: ελοΫϑϧίϧʔνϯ boost::asio::spawn() ʹίϧʔνϯΛ͚ͩ͢ Boost.Coroutine ͷهड़Λҙࣝ͠ͳͯ͘ྑ͘ͳΔ ελοΫϨείϧʔνϯͱҧ͍ɺݺͼग़͠ઌͷؔͰ yield Մೳ yield_context
Λൖ͢Δඞཁ͋Δ
·ͱΊ Boost.Asio ඇಉظ I/O ॲཧͷهड़ʹศར ΠϕϯτۦಈɺϓϥοτϑΥʔϜඇґଘͷ هड़ΛӅṭՄೳ ඇಉظॲཧͷهड़ൺֱత༰қ