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
Async programming is all about programming sync...
Search
seki at druby.org
June 01, 2013
Programming
6
850
Async programming is all about programming synchronously.
RubyKaigi 2013 - 10:00 room A
rev.7
seki at druby.org
June 01, 2013
Tweet
Share
More Decks by seki at druby.org
See All by seki at druby.org
RWC 2024 DICOM & ISO/IEC 2022
m_seki
0
230
ERB, ancient and future
m_seki
3
800
ERB Hacks
m_seki
1
1.3k
わりこまれるはなし
m_seki
0
710
ぼくのかんがえたさいきょうのけいやくによるプログラミング
m_seki
1
1k
Learn Ractor
m_seki
1
2.4k
How many copies did you buy the first print?
m_seki
1
670
Create my own search engine.
m_seki
1
5.2k
Rinda in the real-world embedded systems.
m_seki
0
400
Other Decks in Programming
See All in Programming
週次リリースを実現するための グローバルアプリ開発
tera_ny
1
110
良いユニットテストを書こう
mototakatsu
8
3.1k
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
650
EC2からECSへ 念願のコンテナ移行と巨大レガシーPHPアプリケーションの再構築
sumiyae
2
440
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
720
どうして手を動かすよりもチーム内のコードレビューを優先するべきなのか
okashoi
3
580
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
230
テストコード書いてみませんか?
onopon
2
210
testcontainers のススメ
sgash708
1
130
ある日突然あなたが管理しているサーバーにDDoSが来たらどうなるでしょう?知ってるようで何も知らなかったDDoS攻撃と対策 #phpcon.2024
akase244
2
410
CloudflareStack でRAGに入門
asahiiwm
0
100
毎日13時間もかかるバッチ処理をたった3日で60%短縮するためにやったこと
sho_ssk_
1
360
Featured
See All Featured
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.4k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Designing Experiences People Love
moore
138
23k
It's Worth the Effort
3n
183
28k
A Tale of Four Properties
chriscoyier
157
23k
How to Think Like a Performance Engineer
csswizardry
22
1.2k
Faster Mobile Websites
deanohume
305
30k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Transcript
Async Asynchronously. ඇಉظͬͯಉظΛॻ͘͜ͱ͡ΌΜɻ
[email protected]
programming is all about programming
Important First ϑολʔʹεϙϯαʔ͕ग़ͯΔ͔ΒݟͯͶ!!
About me
WEB+DB PRESS Vol.73 ʮͨͷ͍͠։ൃ࣮گதܧʯͷϨϏϡʔ͋Γ͕ͱ͏͍͟͝·ͨ͠ (ஶऀҰಉ) code ERB dRuby Rinda Drip
͑Ή͞ΜύΠϯΞϝ1kg͋Γ͕ͱ͏ talk RubyKaigi 2006, 7, 8, 9, 10, 11, 13
RubyConf 2012
ͺ͖ͬΎΔʙΜ!! @tsurumau and write dRuby ʹΑΔ ؔকढ़ஶ ࢄ ɾ Web
ϓϩάϥϛϯά
Answering the RubyConf 2012
ΦʔϜࣾץʰϓϩάϥϛϯάClojure ୈೋ൛ʱࢴͱిࢠॻ੶͋Θͤͯධൃചதʂ @koichiro RubyConf 2012 "dRubyࣦഊ࡞ͩ" dRubyಉظݺͼग़͔ͩ͠Βࣦഊͳ ʁʁʁ ݴ͍༁͠ͳ͍ͱʂ
RubyKaigi2013ָ͠ΈͰ͢ɻ@iwadon ࠓ͓͢Δ͜ͱ ඇಉظʹ͓͜Δ͍ΖΜͳ͜ͱ͍͍ͭͩͨ ͍ಉ͡Α͏ʹղ͘ΜͩΑͬͯ
ΫϦΞίʔυRubyձٞ2013ͷγϧόʔεϙϯαʔͰ͢ ਐΊํ ੈք͍͍ͩͨඇಉظͱಉظͰͰ͖͍ͯΔ ඇಉظ෩ͳঢ়گΛͨ͘͞Μࣔ͠·͢ ͍ͭಉ͡Α͏ʹղ༷͘ࢠΛݟͯͶ
ా͞Μָͬͦ͘͢͝͠͏ʹΛฉ͍ͯ͘Ε·͢ɻൃදͷ͋ͱʹ͔ͭ·͑ͯͯ͠ΈͯͶ ࠓ͓͢Δ͜ͱ 2 Μ͍͘͏ͳ dRubyඇಉظݺͼग़͞Ε RubyͰͰ͖ΔόοΫάϥϯυॲཧ વͰ͖Δͷ
Wait a moment ✓ +3:00ɹ ✓ ࠓͷAgenda ✓ એ͗͢͠ͳ͍ ✓
࣍ඇಉظݺͼग़͞Ε
͙Μ·Ͱ·ͬͯΔ ඇಉظͬͯͳʹ Α͘Θ͔Μͳ͍͚Ͳಉظత͡Όͳ͍ͷʁ ࠓࣗͷ߹ͱؔͳ͘ى͜Δͳʹ͔ɺ ͱ͠·͢
͔͚͠ͳ͍ͰΒ͑·͔͢ @track8 ඇಉظݺͼग़͞Εܥ ࣗͷ߹ʹؔͳ͘ݺΕΔ UNIX signal dRuby RMI
9/21 ͱͪ͗Rubyձٞ05ΑΖ͓͘͠Ͷ͕͍͠·͢ @mame UNIX signal ͳʹΛ͍ͯͯ͠ɺಥવొ͞Ε͕ͨؔݺ Εͯɺ͖ͬ͞ͷͱ͜Ζ͔Β࠶։͢Δ ओॲཧγάφϧ͕ൃੜͨ͜͠ͱΛΒͳ͍
͕Μͬ౦! @MUNAKATA_Akiko UNIX signal ͳʹΛ͍ͯͯ͠ɺಥવొ͞Ε͕ͨؔݺ Εͯɺ͖ͬ͞ͷͱ͜Ζ͔Β࠶։͢Δ int foo() { while(1)
{ bar(); baz(); } } int signal_hanlder(...) { }
Lang-8૬ޓఴܕSNSͰɺ190ϲࠃ͔Β80छྨҎ্ͷݴޠͰར༻͞Εͯ·͢ɻ@sasata299 dRuby RMI dRubyඇಉظݺͼग़͞ΕͰ͋Δ RMI͝ͱʹ৽͍͠εϨου͕Ͱ͖ͯॲཧ͢Δ ଞͷεϨουRMI͕͋ͬͨ͜ͱΛΒͳ͍
Δؾφϯγʔ @vestige_ dRuby RMI RMI͝ͱʹ৽͍͠εϨου͕Ͱ͖ͯॲཧ͢Δ ଞͷεϨουRMI͕͋ͬͨ͜ͱΛΒͳ͍ DRb.start_service(...) DRb.thread.join class Service
def foo ... end end
Yokohama.rbຖ݄ୈ2༵։࠵Ͱ͢ʂ ඇಉظݺͼग़͞Εͷಛ ·͞ʹඇಉظ ࣗͷ߹ʹؔͳ͘ݺͼग़͞ΕΔ ͦͯ͠ݺͼग़͞Εͨ͜ͱΛΒͳ͍ ݺΕͨΒͳʹ͔͢Δɺ͕ॻ͖ʹ͍͘
֏͞ΜڃʹΓͳ͍ʰͳΔ΄ͲUNIXϓϩηεʱୡਓग़൛ձ͔ΒେධൃചதͰ͢!! @kakutani ݺͼग़͞Εͨ͜ͱΛ͑Δ ͑Δνϟϯε͕͋Δͷݺͼग़͞Εͨଆ Ͳ͏ͬͯ͑Δʁ Global Variables Synchronization Mechanisms
ελʔτΞοϓRuby Kindle൛͡Ί·ͨ͠ @igaiga555 Global Variables ඇಉظʹݺͼग़͞Εͨ͜ͱΛϝϞ͢Δ ͰϝϞͨ͜͠ͱΛͯͳ͍ ϙʔϦϯά busy loopʹͳΔ͔...
EINTRͱ͏·͘Έ߹ΘͤΔͷख
hikari no cafe Ұॹʹߦ͜͏! ฏʹ༡ͼʹ͖ͯ!! > @ay Synchronization Mechanisms εϨουؒͷ߹ͤɺݴ
͕݅ἧ͏·ͰٳΉ εϨου͕ผεϨουʹใΛ͑Δ εϨου͕ผεϨου͔ΒͷใΛड͚Δ
@nagachika͞Μͷruby-trunk-changesɺ͍ͭݟͯ·͢! Latch, Semaphore, Monitor ͕݅ἧ͏·Ͱͭ ͋ͷඇಉظݺͼग़͕͋ͬͨ͠Αʂͱ͔Ͷ
6/5ͷAWS Summit Tokyo 2013Ͱ͠ΌΓ·͢ɻςΫχΧϧτϥοΫʹ͋ͿΕͨํͥͻɻ @tsuboi Queue ͯΔ্ʹϞϊΛͤΔ FIFO ͍͑ͨΦϒδΣΫτΛpush, pop
ۭͷͱ͖ΦϒδΣΫτ͕ಧ͘·ͰٳΉ
ϑΣΠτɾςελϩοα http://www.fatechan.com Queue QueueΛհʹೋͭεϨου͕ಉظ͢Δ while req = $q.pop do_it(req) end
ϑΣΠτɾςελϩοα http://www.fatechan.com Queue QueueΛհʹೋͭεϨου͕ಉظ͢Δ while req = $q.pop do_it(req) end
class Service def foo(bar) $q.push(bar) end end
ϑΣΠτɾςελϩοα http://www.fatechan.com Queue QueueΛհʹೋͭεϨου͕ಉظ͢Δ while req = $q.pop do_it(req) end
class Service def foo(bar) $q.push(bar) end end
ϑΣΠτɾςελϩοα http://www.fatechan.com Queue QueueΛհʹೋͭεϨου͕ಉظ͢Δ while req = $q.pop do_it(req) end
class Service def foo(bar) $q.push(bar) end end sync!!!
ϑΣΠτɾςελϩοα http://www.fatechan.com Queue QueueΛհʹೋͭεϨου͕ಉظ͢Δ while req = $q.pop do_it(req) end
class Service def foo(bar) $q.push(bar) end end sync!!!
RubyKaigi 2013ແࣄϦϦʔε͞ΕͯͨΒiRubyKaigi'13ͰνΣοΫ!! @gutskun socket ... ಉظϝΧχζϜͱݺΕͯͳ͍͚Ͳ... FIFO σʔλͷ౸ணΛͯΔ σʔλΛͤΔ
@hemge ʹձͬͨͷRubyձٞ2007Ͱͨ͠Ͷʔɻࠓͦ͜দߐͷ՛ࢠ͞ΜҊ͍ͯͩ͘͠͞ɻ Rinda::TupleSpace ॱংʹ͖·Γ͕ͳ͍ λϓϧͷऔΓग़͠ʹΑΔ߹ͤͱใަ ύλʔϯϚον ActorϞσϧͷϝοηʔδͷج൫ʹ߹͏Α Τʔςϧ
ΤϯδχΞืूதͰ͢ bit.ly/cookpad_jobs @mrkn Rinda::TupleSpace TupleSpaceΛத৺ʹෳͷεϨου͕ಉظ ඇಉظݺͼग़͞Εؔͳ͍͚ͲӈଆͶ req = $ts.take([:req, ..])
value = do_it(req) $ts.write([:ans, value])
ΤϯδχΞืूதͰ͢ bit.ly/cookpad_jobs @mrkn Rinda::TupleSpace TupleSpaceΛத৺ʹෳͷεϨου͕ಉظ ඇಉظݺͼग़͞Εؔͳ͍͚ͲӈଆͶ req = $ts.take([:req, ..])
value = do_it(req) $ts.write([:ans, value]) $ts.write([:req, ..]) $ts.take([:ans, nil])
ΤϯδχΞืूதͰ͢ bit.ly/cookpad_jobs @mrkn Rinda::TupleSpace TupleSpaceΛத৺ʹෳͷεϨου͕ಉظ ඇಉظݺͼग़͞Εؔͳ͍͚ͲӈଆͶ req = $ts.take([:req, ..])
value = do_it(req) $ts.write([:ans, value]) $ts.write([:req, ..]) $ts.take([:ans, nil]) sync!!!
ΤϯδχΞืूதͰ͢ bit.ly/cookpad_jobs @mrkn Rinda::TupleSpace TupleSpaceΛத৺ʹෳͷεϨου͕ಉظ ඇಉظݺͼग़͞Εؔͳ͍͚ͲӈଆͶ req = $ts.take([:req, ..])
value = do_it(req) $ts.write([:ans, value]) $ts.write([:req, ..]) $ts.take([:ans, nil]) sync!!!
ΤϯδχΞืूதͰ͢ bit.ly/cookpad_jobs @mrkn Rinda::TupleSpace TupleSpaceΛத৺ʹෳͷεϨου͕ಉظ ඇಉظݺͼग़͞Εؔͳ͍͚ͲӈଆͶ req = $ts.take([:req, ..])
value = do_it(req) $ts.write([:ans, value]) $ts.write([:req, ..]) $ts.take([:ans, nil]) sync!!! sync!!!
ΤϯδχΞืूதͰ͢ bit.ly/cookpad_jobs @mrkn Rinda::TupleSpace TupleSpaceΛத৺ʹෳͷεϨου͕ಉظ ඇಉظݺͼग़͞Εؔͳ͍͚ͲӈଆͶ req = $ts.take([:req, ..])
value = do_it(req) $ts.write([:ans, value]) $ts.write([:req, ..]) $ts.take([:ans, nil]) sync!!! sync!!!
Ұॹʹ͋ͷөըΛݟ͍ͨͰ͢ɻ > @nari3 ·ͱΊ ඇಉظʹݺͼग़͞Εͨ݁ՌΛΔͷ໘ ಉظϝΧχζϜΛ͏ͱ͑Δ͜ͱ͕Ͱ͖Δ
Wait a moment ✓ +13:00ɹ ✓ dRubyඇಉظݺͼग़͞Ε ✓ ݺͼग़͞Εͨ݁ՌΛผεϨουʹ͑Δಉظ ✓
࣍ଈ࣌෮ؼ
֏͞ΜͷಠಛͷงғؾಌΕ·͢! ֻ͍͔͚ͭ͠ʹ͍͖·͢! - @elim όοΫάϥϯυॲཧ ଈ࣌෮ؼ ॲཧΛड͚͚ͨΒ੍ޚ͕Δ ड͚͚ॲཧͩͱࢥ͏ͱྃͯ͠Δ
The dRuby Book ຊޠ൛δϡϯΫಊͰۚͰങ͑Δ ͜Εඇಉظʁ ͏ʔΜ ࣗͷ߹ͱؔͳ͘ॲཧΛ࣮ߦ ࣗͷ߹ͱؔͳྃ͘
9/21 ಹਢԘݪ ͱͪ͗Rubyձٞ05 Eiffelຊ༁ऀͷञ͞Μ͕͘ΔΑʂ ݁Ռ͕ؾʹͳΔ ଈ࣌෮ؼͷଟ͘ͷ߹ Γͬͺͳ͠Ͱͳ͘ ݁Ռʹڵຯ͕͋Δ ݁ՌΛͭAPI͕༻ҙ͞ΕͯΔ
The dRuby Book Japanese Edition : Best as GIFT FROM
JAPAN جຊతͳύλʔϯ ॲཧΛґཔ → νέοτΒ͏! ฒߦͯࣗ͠ͷࣄΛ͢Δ νέοτͬͯґཔͷ݁ՌΛͭ←ಉظ͢Δ
` service جຊతͳύλʔϯ d request join ticket value application background
task
dRubyHiroba - dRuby hands-on 6/2 10:30- (RubyHiroba) νέοτͷྫ ιέοτͦͷͷ͕νέοτ ґཔΛॻ͖ɺ݁ՌΛಡΉ
popenͳͲࣅͨΑ͏ͳͷ ticket = TCPClient.new(...) ticket.write('your task') my_important_task ticket.read
2013-9-21 ͱͪ͗Rubyձٞ05 @ ಹਢԘݪࢢ౦ಹਢެຽؗ νέοτͷྫ εϨουνέοτͷΑ͏ʹ͑Δ joinͰ߹ͤͱͷऔಘ͕ҰʹͰ͖ΔΑ ticket = Thread.new
{ your_task } my_important_task ticket.join
The dRuby Book νέοτͷྫ λϓϧεϖʔεͳΒλϓϧ ticket = Object.new tuple_space.write([:your_task, ticket])
my_important_task tuple_space.take([:your_task_done, ticket])
ʮαϯϥΠζग़ӢͰߦ͘ RubyWorld Conference 2013 ʯಉߦऀืूதʂ @yancya ͕ࣗ͠αʔόͩͬͨΒ ॲཧΛґཔ ฒߦͯࣗ͠ͷࣄ͢Δ νέοτͬͯґཔͷ݁ՌΛͭ
ʮαϯϥΠζग़ӢͰߦ͘ RubyWorld Conference 2013 ʯಉߦऀืूதʂ @yancya ͕ࣗ͠αʔόͩͬͨΒ ॲཧΛґཔ ฒߦͯࣗ͠ͷࣄΛ͢Δ νέοτͬͯґཔͷ݁ՌΛͭ
ґཔΛͭ
ʮαϯϥΠζग़ӢͰߦ͘ RubyWorld Conference 2013 ʯಉߦऀืूதʂ @yancya ͕ࣗ͠αʔόͩͬͨΒ ॲཧΛґཔ ฒߦͯࣗ͠ͷࣄΛ͢Δ νέοτͬͯґཔͷ݁ՌΛͭ
ґཔΛͭ ೋछྨ͍ͪͨ
dRubyHiroba - dRuby hands-on 6/2 10:30- (RubyHiroba) ͪํ͕·ͪ·ͪͩͱࠔΔ or Ͱͭͳ͛ͳ͍
࠷ॳͷ߹ͤͰࢭ·ͬͪΌ͏ ͍Ζ͍ΖҰʹͯͳ͍ͱμϝ queue.pop or soc.read or rinda.take or ...
dRubyHiroba - dRuby hands-on 6/2 10:30- (RubyHiroba) ҰൠԽͨ͠αʔόͷϧʔϓ ͍Ζ͍Ζ·ͱΊͯͭ ৽͍͠ґཔͳΒ...
ྃ௨ͳΒ...
dRubyHiroba - dRuby hands-on 6/2 10:30- (RubyHiroba) ۉ࣭ʹͯ͠·ͱΊͯͭ ͲΕಉ͡APIͰͯΔΑ͏ʹۉ࣭ʹ͢Δ select()શͯΛϑΝΠϧʹͯ͠Δ
TupleSpacetupleʹਖ਼نԽ
dRubyHiroba - dRuby hands-on 6/2 10:30- (RubyHiroba) ·ͱΊ ଈ࣌෮ؼ͢Δͱ͖ɺ͍͍ͨͯ݁Ռ͕ؾʹͳΔ ݁ՌΛͭͷಉظ
ඇಉظݺͼग़͞Εͱಉ͡Α͏ͳײ͡
Wait a moment ✓ +22:00ɹ ✓ ଈ࣌෮ؼͰಉظ͕ϛι ✓ ͚࣍ࣗͩݻ·Βͳ͍ྗͷ͜ͱ
Ruby's GC slide is here! : slidesha.re/19sbBwA (w/o animation, free
ver) and gumroad.com/l/xWCR (w/ animation, premium ver) selectଐϝΠϯϧʔϓ select(ͨ͘͞Μͷιέοτ) ϒϩοΫ͠ͳ͍ιέοτͷಡΈॻ͖ ͳʹ͔ॲཧΛ͢Δ
͵Ruby൪ɺ͍͓ͭੈʹͳ͓ͬͯΓ·͢ʂTIMEXɺ͔Θ͍͍Ͱ͋Γ·͢ʂ ίʔϧόοΫͷύλʔϯ select(ͨ͘͞Μͷιέοτ) ϒϩοΫ͠ͳ͍ιέοτͷಡΈॻ͖ ͳʹ͔ॲཧΛ͢Δ ϑϨʔϜϫʔΫ͕Ӆ͢ ͜ͷลίʔϧόοΫ
The dRuby Book ίʔϧόοΫͷ᠘ select(ͨ͘͞Μͷιέοτ) ϒϩοΫ͠ͳ͍ιέοτͷಡΈॻ͖ ͳʹ͔ॲཧΛ͢Δ ϑϨʔϜϫʔΫશମ͕͘ ͳΔ ͕͍͜͜ͱ
The dRuby Book ίʔϧόοΫͷ᠘ select(ͨ͘͞Μͷιέοτ) ϒϩοΫ͠ͳ͍ιέοτͷಡΈॻ͖ ͳʹ͔ॲཧΛ͢Δ ૬ޓʹݺͼ߹͍ͬͯΔͱγεςϜશ ମ͕ݻ·Δ... ͞Βʹผαʔόʹґཔͨ͘͠
ͯ͜͜Ͱ݁ՌΛͭͱ
The dRuby Book ίʔϧόοΫͷ᠘ select(ͨ͘͞Μͷιέοτ) ϒϩοΫ͠ͳ͍ιέοτͷಡΈॻ͖ ͳʹ͔ॲཧΛ͢Δ ͠ΐ͏͕ͳ͍͔Β݁Ռͪselect ϑϨʔϜϫʔΫͷཧ֎Ͱͭ͜ͱʹ
http://www.amazon.co.jp/registry/wishlist/1R43BBPSPUEEE/ γϯάϧεϨου ॲཧ͕Ͳ͜·ͰਐΜ͔ͩίϯςΩετΛ࡞ͬ ͯɺॲཧதͰϝΠϯϧʔϓʹΔ ࣗવͳίʔυʹ͢Δͷۤ࿑͢Δ Fiberͱ͔ܧଓͱ͔...
2013-9-21ͱͪ͗Rubyձٞ05 @ ಹਢԘݪࢢ౦ಹਢެຽؗ ͋Εʁ ιέοτͷͪͱFiberͳΒThreadͱେࠩͳ ͍ͷͰʁ
2013-9-21ͱͪ͗Rubyձٞ05 @ ಹਢԘݪࢢ౦ಹਢެຽؗ ϚϧνεϨουͰղ͘ acceptͨ͠ΒThreadੜͯ͠readɺॲཧɺ write͢Δ ίϯςΩετͷอଘ෮ݩ͕ෆཁ ࣗવͳίʔυ͕ॻ͚Δ ͍ॲཧͰ͖Δ͠ɺผαʔϏεʹྃ ෮ؼͰґཔͯ͠ྑ͍
2013-9-21ͱͪ͗Rubyձٞ05 @ ಹਢԘݪࢢ౦ಹਢެຽؗ dRubyͷ࣮ͦͷͷ େࣄͳΦνͰ͢Α!! Rubyʹ͓͚Διέοταʔόͷయܕ shttpsrv (ݪ͞ΜͷHTTPαʔόʔ) ඇৗʹૉ dRubyͦͷΑ͏ʹ࡞ΒΕ͍ͯΔ
dRubyHiroba - dRuby hands-on 6/2 10:30- (RubyHiroba) ·ͱΊ ඇಉظʹ͓͜Δ͍ΖΜͳ͜ͱ͍͍ͭͩͨ ͍ಉ͡Α͏ʹղ͘ΜͩΑͬͯͰͨ͠
dRubyHiroba - dRuby hands-on 6/2 10:30- (RubyHiroba) ͱͪ͗RubyKaigi 05 2013-9-21
ಹਢԘݪ টߨԋ: ञ