Skip to content

v3.0.0-alpha.1

Pre-release
Pre-release

Choose a tag to compare

@matsumotory matsumotory released this 25 Nov 04:17
574a0e4

What 3.0.0-alpha.1 brings

ngx_mruby 3.0 is the next major version. In addition to ordinary web services, it aims to run Ruby rules in front of AI applications, model APIs and MCP servers. This first pre-release brings the new core; the AI gateway features are planned for the pre-releases after it ("What comes next" below).

  • Fewer instructions per request. Before the tag, this release was compared with 2.7.13 under callgrind (#862). The total instructions per request fell in 15 of the 16 measured scenarios: by 18% in the scenario that reads and sets headers, by 11% for a subrequest and by 7% for a handler that returns hello. One scenario, an output body filter, rose by 2.7%. These are instruction counts, not wall-clock times; #862 has the table, including the figures that the check gates on.
  • Bundles mruby 4.1.0-rc2 instead of 3.3.0: scripts can use pattern matching (case/in), it in blocks, and the methods added in mruby 3.4 through 4.1.
  • One defined behavior for handlers that wait. A handler that waits in Nginx::Async.sleep or Nginx::Async::HTTP.sub_request resumes and ends the request in the same way in every phase. sub_request works in content handlers and returns the response of the subrequest (#712, #714, #715, #720, #722, #727, #728, #735).
  • Mistakes show up. A method that would have no effect in the handler that calls it now raises a RuntimeError, so the mistake reaches error.log instead of being ignored (#826).
  • Values passed between handlers. Nginx::Request#store passes values between the handlers of one request (#832), and mruby_variable declares variables for scripts to assign (#780).
  • Headers in nginx's own fields. Content-Type, Location, Date and Server set through Nginx::Headers_out are stored in nginx's own fields, so nginx's filters use them, and request headers added with Nginx::Headers_in#[]= are recognized by proxy_pass (#855).
  • Try it locally. examples/start uses Docker Compose to run an nginx that routes requests by model to two mock APIs. No provider API key is needed.

What comes next

The next pre-releases are planned to add the parts of an AI gateway that 2.x does not have. None of them is in this pre-release.

  • A dictionary that all workers share, for budgets and rate-limit counters.
  • A filter that reads the server-sent events (SSE) of a streamed model response one event at a time, for example to count token usage.
  • Re-selecting the upstream, and a first-byte timeout, for model API fallback.
  • A reference agent proxy built on these parts.

Step 7 of the v3 plan lists the parts and their order. The uses they serve include MCP tool authorization, limits on bursts of agent calls, model API fallback and AI crawler control; the home page and the list of uses show the design status of each.

Behavior changes: read before upgrading

This is the first pre-release of 3.0.0, so the section lists every behavior change since 2.7.13. It has 78 entries; each heading below links to its full text (before, now, why it changed, what is affected, what to do) in the release notes of this tag.


3.0.0-alpha.1で得られるもの

ngx_mruby 3.0は、次のメジャーバージョンです。通常のWebサービスに加えて、AIアプリケーション、モデルAPI、MCPサーバーの前でRubyのルールを動かすことを目指しています。この最初のプレリリースには、新しいコアが入っています。AIゲートウェイの機能は、この後のプレリリースで足す予定です。下の「これから入るもの」を見てください。

  • リクエストあたりの命令数が減りました。 タグを付ける前の確認で、このリリースと2.7.13をcallgrindで比べました(#862)。測った16のシナリオのうち15で、リクエストあたりの命令数の合計が減りました。ヘッダを読んで設定するシナリオで18%、サブリクエストで11%、helloを返すハンドラで7%減っています。出力ボディフィルターのシナリオだけは、2.7%増えました。これは命令数で、実行時間ではありません。確認で合否の判定に使う値を含む表は、#862にあります。
  • mruby 4.1.0-rc2を同梱します。 同梱のmrubyが3.3.0から上がったので、スクリプトでパターンマッチ(case/in)、ブロックのit、mruby 3.4から4.1で増えたメソッドを使えます。
  • 待つハンドラの動き方が1つに定まりました。 Nginx::Async.sleepやNginx::Async::HTTP.sub_requestで待ったハンドラは、どのフェーズでも同じ形で再開し、リクエストを終えます。sub_requestはcontentハンドラでも使え、サブリクエストの応答を返します(#712、#714、#715、#720、#722、#727、#728、#735)。
  • 誤りが見えるようになりました。 呼んだハンドラで効果の無いメソッドは、RuntimeErrorを発生させます。誤りは無視されずに、error.logに出ます(#826)。
  • ハンドラの間で値を渡せます。 Nginx::Request#storeで、1つのリクエストのハンドラの間で値を渡せます(#832)。mruby_variableで、スクリプトが代入する変数を宣言できます(#780)。
  • ヘッダがnginxのフィールドに入ります。 Nginx::Headers_outで設定したContent-Type、Location、Date、Serverは、nginxが持つフィールドに入り、nginxのフィルターもその値を使います。Nginx::Headers_in#[]=で足したリクエストヘッダは、proxy_passが認識します(#855)。
  • 手元で試せます。 examples/startは、Docker Composeで、リクエストをモデルごとに2つのモックAPIへ振り分けるnginxを動かします。プロバイダのAPIキーは不要です。

これから入るもの

この後のプレリリースでは、2.xに無いAIゲートウェイの部品を足す予定です。どれも、このプレリリースにはまだありません。

  • すべてのworkerが共有する辞書を足します。予算やレート制限のカウンターに使います。
  • ストリーミングで返るモデルの応答から、SSE(server-sent events)のイベントを1つずつ読むフィルターを足します。トークンの使用量を数えるときなどに使います。
  • 中継先を選び直す仕組みと、最初のバイトまでのタイムアウトを足します。モデルAPIのフォールバックに使います。
  • これらの部品で作る、リファレンス実装のエージェントプロキシを足します。

部品とその順序は、v3の計画のステップ7にあります。部品が支える用途には、MCPのツール呼び出しの認可、エージェントが短時間に繰り返す呼び出しの制限、モデルAPIのフォールバック、AIクローラーの制御などがあります。用途ごとの設計の状態は、トップページと用途の一覧にあります。

更新前に確認する挙動の変更

3.0.0の最初のプレリリースなので、2.7.13からの挙動の変更をすべて挙げます。項目は78個あります。各見出しは、このタグのリリースノートにある項目の全文へのリンクです。全文には、変更前、変更後、変更の理由、影響の範囲、必要な対応を書いています。