Share
Embed
Transcript
22 slides
-
LARAVEL LIVE JAPAN 2026 A coroutine upgrade path for Laravel
queues Supercharge Laravel Queues with Hypervel Breaking I/O bottlenecks in the AI era PRESENTED BY Albert Chen file talk.php runtime swoole + coroutine target queue:work --concurrency=1000 -
// SPEAKER Albert Chen Enjoy building high-concurrency architectures with PHP.
Software Architect, Taiwan Laravel Artisan Swoole Enthusiast Creator of Hypervel x / @albert_cht 02 / 22 · SPEAKER hypervel.org HYPERVEL / CREATOR $ /usr/bin/ whoami -
// PROBLEM · 01 PHP is blocking I/O by default.
Same workload in single process. Two very different clocks. BLOCKING I/O PHP · Laravel TOTAL — req 1 req 2 req 3 req 4 req 5 COROUTINE Hypervel · Swoole TOTAL — req 1 req 2 req 3 req 4 req 5 03 / 22 · WHY NOT PHP blocking i/o vs. coroutine -
// TRADITIONAL ANSWER Push slow work into a queue. TYPICAL
QUEUE WORKLOADS Welcome emails & SMS verification Error reporting & log shipping CRM / billing sync Stripe & external webhooks < 1s per job. Workers keep up without breaking a sweat. INCOMING ▶ QUEUE ▶ WORKER W PER-JOB < 1 s PROCESSED 0 WORKER calm 04 / 22 · HAPPY PATH laravel queue · defaults -
// THEN AI ARRIVED A single job now takes seconds
— or minutes. AI WORKLOADS Chatbot completion Image generation Voice / TTS synthesis Video processing & agent flows 3s → 30s → 3min Even at low QPS, the queue outruns the workers. INCOMING ▶ QUEUE ▶ WORKER W PER-JOB ~30 s PROCESSED 0 QUEUE BACKLOGS ↑ growing 05 / 22 · AI ERA jobs minutes long · backlog grows -
// MATH · 100 QPS At 100 QPS, how many
workers do you need? PER-JOB DURATION WORKERS REQUIRED WORKLOAD EXAMPLE 0.5 s 50 Email / SMS 1 s 100 Threshold 5 s 500 Light AI call 10 s 1,000 Typical LLM inference 30 s 3,000 Complex reasoning / image gen 60 s 6,000 Video / agentic flow ※ Little's Law: Required Processes = QPS × I/O Time. 06 / 22 · THE MATH 100 qps · workers number -
// INTRODUCING Hypervel A coroutine-native framework on top of Swoole
. 01 Laravel-style PHP framework with native coroutine support 02 Ports of most first-party Laravel packages 03 Minimal learning curve for Laravel Artisans 04 Extremely high performance for concurrent workloads 05 Wire-compatible queue & cache protocols INSTALL $ composer create-project hypervel/hypervel $ cd hypervel && php artisan serve 07 / 22 · HYPERVEL coroutine-native framework -
// VERSION DIFF Hypervel 0.3→0.4 DIMENSION 0.3 0.4 Framework base
Based on Hyperf Fully ported from Laravel Laravel API ~90% similar Near 1:1 parity Ported packages All core components · + Horizon, Scout, Socialite, Sanctum, Telescope All of 0.3 · + Ignition, Inertia, Reverb, Boost, Laravel AI (planning) Release status Current Beta coming soon 08 / 22 · ROADMAP 0.3 → 0.4 -
// THEY SPEAK THE SAME LANGUAGE One wire format. Two
runtimes. 09 / 22 · INTEROP laravel ⇄ wire ⇄ hypervel LARAVEL PHP-FPM · blocking DISPATCH SendInvoiceJob LISTEN OrderShipped CACHE Cache::put() The lingua franca JSON envelope · common contract // queue payload { "job": "Illuminate\\Queue\\CallQueuedHand ler@call", "uuid": "06bb1f24-52a6-4b65-8e79-72196e39 17cd", "data": { "command": ... }, "attempts": 0, "timeout": null } queues events cache locks read by both runtimes · protocol-compatible // shared wire protocol HYPERVEL Swoole · coroutine WORK queue:work EMIT event(OrderShipped) CACHE Cache::get() -
// CONSTRAINTS · READ THIS FIRST What works, what doesn't.
Laravel wasn't built for coroutines — state bleeds across them. CODE CATEGORY USE AS-IS? WHAT TO DO Laravel ecosystem packages Auth, Log, Eloquent, Redis, Cache, Http, etc. ✕ no Swap for Hypervel's ports — API is near-identical. Native PHP I/O file_get_contents, fopen, fsockopen, sleep, etc. ✓ yes Auto-coroutinized by Swoole's runtime hook. cURL-based libraries native curl, Guzzle, most of 3rd-party SDKs, etc. ✓ yes Works unchanged (assuming no global-state abuse). 10 / 22 · CONSTRAINTS state bleeding · swap your packages -
// STRATEGY Give Hypervel its own queue. One Redis, two
lanes. Laravel keeps default , Hypervel owns hypervel . LARAVEL APP dispatch(new Job) Routes by $queue Job → default Job → hypervel LARAVEL WORKER php artisan queue:work --queue=default HYPERVEL WORKER php hypervel queue:work --queue=hypervel --concurrency=1000 queue: default laravel-only queue: hypervel hypervel-only REDIS · shared 11 / 22 · STRATEGY queue lanes · clean separation -
// LARAVEL SIDE On the Laravel side: an empty listener.
01 Create a listener implementing ShouldQueue . 02 Leave handle() empty — real work runs in Hypervel. 03 Set public $queue = 'hypervel' . 04 Wire the event→listener mapping as usual. namespace App\Listeners; use App\Events\UserRegistered; use Illuminate\Contracts\Queue\ShouldQueue; class SendWelcomeEmail implements ShouldQueue { public $queue = 'hypervel'; // ← routed to Hypervel public function handle(UserRegistered $event): void { // Intentionally empty. // The Hypervel worker owns the real implementation. } } app/Listeners/SendWelcomeEmail.php 12 / 22 · LARAVEL SIDE shim listener · ~12 lines -
// HYPERVEL SIDE · THE LISTENER All you do is
swap Illuminate→Hypervel. Same Http facade. Same Eloquent query. Same code shape. Different runtime. Laravel BLOCKING → Hypervel NON-BLOCKING · COROUTINE DIFF One line. Illuminate → Hypervel. Http facade + Eloquent query are byte-for-byte identical — and now they yield on I/O. namespace App\Listeners; use Illuminate \Support\Facades\Http; use App\Models\User; class SyncUserProfile { public function handle(UserRegistered $event): void { $response = Http::timeout(10) ->get('https://api.crm.io/users/'.$event->id); User::where('id', $event->id) ->update(['profile' => $response->json()]); } } app/Listeners/SyncUserProfile.php R E P L A C E N A M E S P A C E namespace App\Listeners; use Hypervel \Support\Facades\Http; use App\Models\User; class SyncUserProfile { public function handle(UserRegistered $event): void { $response = Http::timeout(10) ->get('https://api.crm.io/users/'.$event->id); User::where('id', $event->id) ->update(['profile' => $response->json()]); } } app/Listeners/SyncUserProfile.php 13 / 22 · THE TRICK illuminate ⇢ hypervel · 1 line -
// DEMO · STRESS TEST 1,000 jobs · 5 seconds
each. JOB sleep(5) — simulates an AI call COUNT 1,000 CONTENDERS Laravel worker Hypervel worker · --concurrency public function handle(): void { for ($i = 0; $i < 1000; $i++) { event(new UserRegistered($i)); } $this->info('Dispatched 1,000 jobs to queue: hypervel'); } // Listener handle(): public function handle(UserRegistered $event): void { sleep(5); // simulated 5s AI call } app/Console/Commands/StressTest.php 14 / 22 · DEMO SETUP deterministic · reproducible -
// RESULT · LARAVEL Laravel: one process, one job at
a time. t = 0.0s … 996 more, one after another … PROCESSES 1 IN FLIGHT 1 TIME TO DRAIN ~5,000 s Laravel's worker can only process one job at a time due to the limit of blocking I/O in PHP. job #1 · sleep(5) job #2 · sleep(5) job #3 · sleep(5) job #4 · sleep(5) 15 / 22 · LARAVEL WORKER serial · blocking -
// RESULT · HYPERVEL Hypervel: --concurrency=1000 . t = 0.0s
1,000 COROUTINES · ONE PROCESS · ALL PARALLEL job #1 · sleep(5) job #2 · sleep(5) job #3 · sleep(5) … job #999 · sleep(5) job #1000 · sleep(5) PROCESSES 1 COROUTINES 1,000 TIME TO DRAIN ~5 s Single process. Single memory footprint. 1,000× throughput. 16 / 22 · HYPERVEL WORKER parallel · coroutine -
// RESOURCE FOOTPRINT · SAME THROUGHPUT To match c=1000 ,
Laravel scales the process count. Hypervel scales coroutines inside one. Laravel · scale-out 1 / 1,000 processes MEMORY 32 MB CPU CONTEXT SWITCHES ~1× Hypervel · scale- in 1 / 1,000 coroutines · 1 process MEMORY 32 MB CPU CONTEXT SWITCHES ~1× Δ 1,000× 1,000× PROCESSES · MEMORY pid 8421 · php (swoole) 17 / 22 · RESOURCE SCALE same throughput · very different bill -
// HEAD TO HEAD · 1000 × 5S Same job.
Same count. Three orders of magnitude. METRIC LARAVEL (1 WORKER) HYPERVEL (1 WORKER · C=1000) Processes 1 1 Jobs in flight 1 1,000 Total duration ~5,000 s ~5 s Workers for equivalent throughput 1,000 — Memory / CPU footprint Linear in worker count Flat · one process 18 / 22 · HEAD TO HEAD 1000× throughput · 1/1000 cost -
// LIVE DEMO · QUEUE WORKERS Laravel vs Hypervel —
side by side. 19 / 22 · DEMO coroutines vs processes -
// OPERATOR QUESTION …and yes, Horizon still works. Hypervel ports
Horizon — protocol-compatible, same dashboard, same metrics. 20 / 22 · HORIZON dashboards preserved -
// TAKEAWAYS Three things to walk out with. 01 The
traditional queue model breaks in the AI era. Multi-second jobs don't fit into 1-process-per-worker economics. 02 Offload your I/O-heavy jobs to Hypervel's queue worker. The API is Laravel's. The runtime is Swoole's. The DX is already familiar. 03 You don't rewrite anything — you add a lane. Open one hypervel queue. Laravel and Hypervel share Redis. Ship tomorrow. Laravel + Hypervel = Better together. 21 / 22 · TAKEAWAYS ship tomorrow -
// THE END Thank you. Questions welcome. Speaker Albert Chen
· @albert_cht GitHub github.com/hypervel/hypervel Website hypervel.org scan for more about Hypervel