Successfully reported this slideshow.
Your SlideShare is downloading. ×

How Swoole Blows Up your Mind about PHP?

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad

Check these out next

1 of 32 Ad
Advertisement

More Related Content

Recently uploaded (20)

Advertisement

How Swoole Blows Up your Mind about PHP?

  1. 1. How Swoole Blows Up Your Mind? @PHPCon Okinawa 2019 By Albert Chen
  2. 2. About Me • Albert Chen • Software Architect • M17 HandsUp • Open Source Maintainer
  3. 3. What is Swoole?
  4. 4. What is Swoole? • A C extension for PHP • An asynchronous network engine for PHP • Features: • Event-driven non-blocking I/O • HTTP / HTTP2 / Websocket / TCP / UDP • Coroutine (CSP Model) • High performance for high concurrency
  5. 5. Why PHP Performs Poorly in High Concurrency?
  6. 6. Lifecycle in PHP
  7. 7. Lifecycle in PHP PHP Files Tokenizing Semantic Parsing AST Generate Bytecode Execute Bytecode Output Load Bytecode From Memory Check Bytecode Cache
  8. 8. Blocking I/O in PHP Request Request Request Request PHP FPM FPM Pool FPM Pool Worker Worker Worker Worker Blocking I/O
  9. 9. Eventloop in NodeJS
  10. 10. There’s no Eventloop in Traditional PHP
  11. 11. Let’s See What Changes in Swoole?
  12. 12. Structure in Swoole Server
  13. 13. Structure in Swoole Server • Code Is Persistent in Memory • Swoole Takes Lifecycle Over PHP • Reduce Initialization Steps • Reduce Response Latency • Event-driven Non-blocking I/O for Requests
  14. 14. Benchmark Comparison of Go with Swoole
  15. 15. Server Benchmark in Go
  16. 16. Server Benchmark in Go
  17. 17. Server Benchmark in Swoole
  18. 18. Server Benchmark in Swoole
  19. 19. This Doesn’t Mean PHP with Swoole is Faster Than Go (Of Course Not)
  20. 20. Coroutine in Swoole
  21. 21. Coroutine in Swoole • Blocking I/Os Are Scheduled By Coroutine Automatically.
  22. 22. Coroutine in Swoole • Blocking I/Os Are Scheduled By Coroutine Automatically.
  23. 23. Coroutine in Swoole • CSP Model
  24. 24. Does This Mean Every Blocking I/O Doesn’t Block Anymore?
  25. 25. Coroutine in Swoole • How about This?
  26. 26. Coroutine in Swoole • How about This?
  27. 27. Runtime Hooks Transform Blocking I/Os into Coroutines with Magic!
  28. 28. Use Case In HandsUp
  29. 29. Use Case Facebook Webhooks Message Load Balancer Server Server Server Queue PubNub Service Analysis Service Swoole Service PubSub Many to Many Queue Workers High Concurrent Requests
  30. 30. Use Case • Replace Guzzle Handler with Swoole Client
  31. 31. Q&A

×