Design pattern for embedding mruby into middleware
summary
mruby is embedded into middleware like ngx_mruby with a clear pattern: create mrb_state at init, compile Ruby into bytecode, and execute cached bytecode per request for high throughput. Experiments show per-request mrb_state creation limits throughput to ~6k req/s, per-request compile reaches ~46k req/s, and cached bytecode runs ~64k req/s. Design covers precompile bytecode at init, per-thread/per-worker mrb_state reuse, and a suspend/resume model using fibers and event-loop callbacks to keep blocking Ruby calls nonblocking.
AI-written summary · about
chapters (6)
- 0:00Introduction and background
- 10:18Why embed mruby in middleware
- 13:37Design patterns for mruby state
- 27:47Non-blocking operations with mruby
- 36:53Implementation in nginx
- 40:14Conclusion and Q&A








