Share
Embed
Transcript
46 slides
-
02 Limitations of Laravel Octane Outline 01 Introduction of Laravel
Octane 04 Coroutines in Hypervel 05 Benchmark Comparison 07 Q&A 06 Live Demo 03 Introduction of Hypervel -
🙍♂️ I’m Albert Chen 💻 Software Architect based in Taiwan
🐘 Laravel Artisan ⚡ Swoole Enthusiast 🧙 Hyperf Contributor 🧙 Creator of Laravel Swoole (archived) 🧙 Creator of Hypervel X: @albert_cht Who am I? -
Published in April 2021 Maintained by official Laravel team Supports
Swoole, Roadrunner and FrankenPHP as drivers Requires Laravel 10 and PHP 8.1 in 2.x Supercharge performance of Laravel Hot reload support Additional features in Swoole driver: Concurrent Tasks Ticks and Intervals The Octane Cache Swoole Table What is Laravel Octane? -
Request PHP Startup Framework Bootstrapped Handle Request PHP Terminate What
is Laravel Octane? Workflow in traditional stateless PHP-FPM Response Heavy Task -
Request Response What is Laravel Octane? Workflow in stateful Laravel
Octane PHP Startup Reset States Handle Request PHP Terminate -
What is Laravel Octane? More Details about Laravel Octane Laracon
US 2024 https://youtu.be/dOXXL-98Zbs -
Boost your Laravel application up to 5x faster in QPS
With lower response latency What is Laravel Octane? Is Laravel Octane Always Fast? (Mac M1 Pro 2021, 8 CPU, 16G Ram) -
Consider building an LLM-powered chatbot with Laravel Octane Building a
Chatbot https://x.com/heytjmiller/status/1928808983239733359 Prism https://prismphp.com -
Consider building an LLM-powered chatbot with Laravel Octane If each
request takes about 3-5 seconds How many concurrent requests can Laravel Octane provide? LLM response takes time... Building a Chatbot -
Simulate 1 second sleep for I/O wait What happend? 😱
Building a Chatbot -
Laravel Octane only decreases the response latency by keeping bootstrapped
framework in the memory I/O requests in Laravel Octane are still blocking Processes will be blocked until the end of the I/O 80% of requests in the web application are I/O bound Laravel Octane doesn’t help in blocking I/Os at all Laravel is not suitable for handling I/O bound requests in high concurrency even with the help of Laravel Octane Limitations of Laravel Octane -
It’s a bad idea to build LLM-based chatbots in production
with blocking I/O in PHP even with Laravel Octane The only way to increase QPS is to scale your machines It’s extremely inefficient for the machine resource and cost Limitations of Laravel Octane -
Main yield Waiting resume Main process doesn’t get blocked while
waiting for I/O Coroutine in Laravel Octane Blocking I/O vs. Non-blocking I/O Main I/O call Waiting return Main process gets blocked while waiting for I/O -
Resolved User Foo Request Lifecycle Singleton Service Request A Request
B 1 2 Coroutine in Laravel Octane -
Coroutine in Laravel Octane Does Octane support coroutine with Swoole?
No, it’s highly risky! Laravel is designed for stateless environment States bleeding among coroutines will be a mess in Laravel Event if Laravel supports coroutines within single request , the worker is still occupied until the end of all I/O operations Laravel team has little possibility to support coroutine due to the considerations of the current ecosystem and backward compatibility It’s not a package-level thing, it’s about the whole framework and related ecosystem -
This project was launched in 2023 Initially crafted for internal
use in my team, aiming to help Laravel artisans enjoy the high performance of coroutines while maintaining familiar Laravel development practices Ported bunch of packages from Laravel to support coroutine Reduce the learning cost for a new framework Share the same package ecosystem with Hyperf framework What is Hypervel? https://github.com/hypervel/hypervel -
What is Hypervel? Auth Hypervel Framework Broadcasting Bus Cache Config
Console Container Cookie Coroutine Dispatcher Encryption Event Filesystem Foundation Hashing Http Client JWT Mail Log Notification Object Pool Process Prompts Router Queue Session Support Translation Validation Testbench Telescope -
What is Hypervel? We ported most of the components from
Laravel to make them coroutine-safe in Hypervel Packages from Hyperf are compatible with Hypervel Some components provide similar usage while keeping compatibility with Hyperf framework Requests, Responses, Cookies Laravel packages are NOT compatible with Hypervel -
Coroutine in Hypervel Resolved User Request Lifecycle A&B User A
Request A Request B 1 2 User B Unlike Octane, states in shared objects are isolated via Context -
Coroutine Supports Automated yield an resume while switching I/O states
Runtime Hooks Channel (CSP Model) Defer WaitGroup Parallel Coroutine Context Coroutine in Hypervel which can’t be achieved in other async libraries -
1 2 2 Coroutine in Hypervel Global States Bleeding in
Coroutines Global states are shared in coroutines That’s why Laravel can’t support coroutines -
Polyglot Stack If you already have lots of projects built
with Laravel... How to migrate to Hypervel? -
Load Balancer Laravel Hypervel Polyglot Stack You can integrate Hypervel
with your Laravel projects Share Data and Communicate -
Communication in Polyglot Stack Cache, locks and queues can be
shared between Laravel Laravel Cache Hypervel Cache Hypervel Lock Laravel Lock Same Communication Protocol Hypervel Queue Laravel Queue Payload -
Benchmark Comparison More than 10x faster than Laravel Octane in
QPS Lower response latency (Mac M1 Pro 2021, 8 CPU, 16G Ram) Laravel Octane Hypervel Hello World Test -
1s I/O Test Benchmark Comparison Hypervel is excellent at I/O
requests with coroutines (Mac M1 Pro 2021, 8 CPU, 16G Ram) Laravel Octane Hypervel -
Benchmark Comparison Hypervel is a game changer for the ultra-performance
in PHP Laravel Octane Hypervel