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
Inside SWOOLE: 非同期処理はどのようにして動くのか/inside_swoole
Search
KOYAMA Tetsuji
February 09, 2020
Programming
0
18k
Inside SWOOLE: 非同期処理はどのようにして動くのか/inside_swoole
KOYAMA Tetsuji
February 09, 2020
Tweet
Share
More Decks by KOYAMA Tetsuji
See All by KOYAMA Tetsuji
全日本PHPカンファレンス2024スタンプラリーについて/stamprally-php2024
koyhoge
0
120
日本PHPカンファレンス2024スタンプラリーとその実装/phpcon-stamprally
koyhoge
1
1k
日本のPHPカンファレンスの歩みと、その辺もろもろ/phpcon_japan_history
koyhoge
0
240
映画を年300本観る技術/watch_300_movies_in_a_year
koyhoge
0
1.1k
Swooleで実装するPHP非同期処理の世界/phpcondo2019-swoole
koyhoge
3
5.1k
CloudFormation と FaaS のはざま - Kubernetes の設計思想を探る -/cf-faas-k8s
koyhoge
0
1.4k
ITイベントマニアから見る技術イベントの動向/techevent
koyhoge
0
300
Skaffoldを使ってKubernetes してみた/skaffold_k8s
koyhoge
2
1.2k
東京が大雪の日に何気ない写真がバズった/snow_tree_buzz
koyhoge
0
520
Other Decks in Programming
See All in Programming
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
120
ヤプリ新卒SREの オンボーディング
masaki12
0
130
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
4
640
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
290
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
Jakarta EE meets AI
ivargrimstad
0
590
CSC509 Lecture 11
javiergs
PRO
0
180
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.7k
Realtime API 入門
riofujimon
0
150
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
190
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
230
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Teambox: Starting and Learning
jrom
133
8.8k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Building Adaptive Systems
keathley
38
2.3k
Code Reviewing Like a Champion
maltzj
520
39k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Done Done
chrislema
181
16k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
860
Music & Morning Musume
bryan
46
6.2k
Transcript
*OTJEF4800-& ඇಉظॲཧͲͷΑ͏ʹͯ͠ ಈ͘ͷ͔ খࢁࢤ !LPZIPHF PHPerKaigi 2020 / 2020-02-09
PHPerKaigi 2020 / 2020-02-09 ࣗݾհ খࢁࢤ ͜·ͯͭ͡ ߹ಉձࣾ΄ٕ͛ݚ Ϣʔβձ͍͔ͭ͘
ຊ6/*9Ϣʔβձ ຊ1PTUHSF42-Ϣʔβձ ຊ1)1Ϣʔβձ SBLVNPגࣜձࣾΤϯδχΞ өըΛ؍Δਓˡ/&8 !LPZIPHF LPZIPHF
PHPerKaigi 2020 / 2020-02-09 1)1ΧϯϑΝϨϯεւಓ ΈΜͳͷ1)1ݱͰཱͭ࠷৽ϊϋ ʮ4XPPMFʹΑΔ1)1ඇಉظॲཧʯ 8&# %#13&44WPM
PHPerKaigi 2020 / 2020-02-09 4XPPMFͱ w1)1ͰඇಉظॲཧΛ࣮ݱ͢Δػೳ֦ு w͔Β։ൃ wݩӳࠃ5SBOTGPOʹΑͬͯ wݱࡏதࠃݍͷ։ൃऀ͕ʹ
PHPerKaigi 2020 / 2020-02-09 ඇಉظॲཧ wฒߦฒྻ wίϧʔνϯ wO݄ؒϥϜμ ϊʔτ WPM
/Pʹৄ͍͠
PHPerKaigi 2020 / 2020-02-09 4XPPMFͷ࣮ݱ๏Λ୳Δ wରຊ ࣌ͷ HJUIVCNBTUFS wW
Ћ
PHPerKaigi 2020 / 2020-02-09 ελʔτ͔͜͜Β go(function() { // something })
PHPerKaigi 2020 / 2020-02-09 HP 473 if (SWOOLE_G(use_shortname)) 474 {
475 SW_FUNCTION_ALIAS(CG(function_table), "swoole_coroutine_create", CG(function_table), "go"); 476 SW_FUNCTION_ALIAS(CG(function_table), "swoole_coroutine_defer", CG(function_table), "defer"); 477 } swoole.cc
PHPerKaigi 2020 / 2020-02-09 TXPPMF@DPSPVUJOF@DSFBUF 931 PHP_FUNCTION(swoole_coroutine_create) 932 { 933
zend_fcall_info fci; 934 zend_fcall_info_cache fci_cache; 935 936 ZEND_PARSE_PARAMETERS_START(1, -1) 937 Z_PARAM_FUNC(fci, fci_cache) 938 Z_PARAM_VARIADIC('*', fci.params, fci.param_count) 939 ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 940 941 if (sw_unlikely(SWOOLE_G(req_status) == PHP_SWOOLE_CALL_USER_SHUTDOWNFUNC_BEGIN)) swoole_coroutine.cc
PHPerKaigi 2020 / 2020-02-09 951 long cid = PHPCoroutine::create(&fci_cache, fci.param_count,
fci.params); swoole_coroutine.cc
PHPerKaigi 2020 / 2020-02-09 1)1$PSPVUJOFDSFBUF 814 long PHPCoroutine::create(zend_fcall_info_cache *fci_cache, uint32_t
argc, zval *argv) 815 { : 838 php_coro_args php_coro_args; 839 php_coro_args.fci_cache = fci_cache; 840 php_coro_args.argv = argv; 841 php_coro_args.argc = argc; 842 save_task(get_task()); 843 844 return Coroutine::create(main_func, (void*) &php_coro_args); 845 } swoole_coroutine.cc
PHPerKaigi 2020 / 2020-02-09 $PSPVUJOFDSFBUF 121 static inline long create(coroutine_func_t
fn, void* args = nullptr) 122 { 123 return (new Coroutine(fn, args))->run(); 124 } include/coroutine.h
PHPerKaigi 2020 / 2020-02-09 $PSPVUJOF$PSPVUJOF 205 Coroutine(coroutine_func_t fn, void *private_data)
: 206 ctx(stack_size, fn, private_data) 207 { 208 cid = ++last_cid; 209 coroutines[cid] = this; 210 if (sw_unlikely(count() > peak_num)) 211 { 212 peak_num = count(); 213 } 214 } include/coroutine.h
PHPerKaigi 2020 / 2020-02-09 $PSPVUJOFSVO 216 inline long run() 217
{ 218 long cid = this->cid; 219 origin = current; 220 current = this; 221 ctx.swap_in(); 222 check_end(); 223 return cid; 224 } include/coroutine.h
PHPerKaigi 2020 / 2020-02-09 $PSPVUJOFDUY 199 sw_coro_state state = SW_CORO_INIT;
200 long cid; 201 void *task = nullptr; 202 Context ctx; 203 Coroutine *origin; include/coroutine.h
PHPerKaigi 2020 / 2020-02-09 $POUFYUTXBQ@JO 110 bool Context::swap_in() 111 {
112 jump_fcontext(&swap_ctx_, ctx_, (intptr_t) this, true); 113 return true; 114 } src/coroutine/context.cc
PHPerKaigi 2020 / 2020-02-09 KVNQ@GDPOUFYU wTXPPMFTSDʹͳ͍ wCPPTUDPOUFYUͷؔ
PHPerKaigi 2020 / 2020-02-09 CPPTUDPOUFYU •https://github.com/boostorg/ context w$ ͰγϯάϧεϨουϚϧνλεΫ Λ࣮ݱ͢ΔϥΠϒϥϦ
wsetjmp(), longjmp()ͷਐԽ൛
PHPerKaigi 2020 / 2020-02-09 λεΫ͑BTNͰ
PHPerKaigi 2020 / 2020-02-09 ࢀߟਤ w ʲ4XPPMFݯݚڀʳਂೖཧղ4XPPMFླྀఔൌགྷ • https://segmentfault.com/a/1190000019089997
PHPerKaigi 2020 / 2020-02-09 λεΫͲ͏อ࣋͞Ε͍ͯΔ 114 static std::unordered_map<long, Coroutine*> coroutines;
include/coroutine.h
PHPerKaigi 2020 / 2020-02-09 ·ͱΊ w4XPPMFCPPTUDPOUFYUͷλεΫ Λར༻͍ͯ͠Δ wҰݟຐ๏ͷΑ͏ʹݟ͑ͯɺͻͱͭͣ ͭḷ͍ͬͯ͘ͱཧղͰ͖Δ w$
ίϫ͘ͳ͍ΑX