Skip to content

v3.0.0-alpha.5

Pre-release
Pre-release

Choose a tag to compare

@matsumotory matsumotory released this 01 Dec 05:20
2829bfd

What 3.0.0-alpha.5 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 fifth pre-release adds a deadline for the first byte of an upstream's response, the second part of the planned agent proxy, and fixes mruby_upstream_keepalive. The other parts of the agent proxy are still planned for the pre-releases after it ("What comes next" below).

  • A deadline for the first byte from an upstream. A model API can accept a request and then send nothing. nginx has one timeout for that, proxy_read_timeout, and it is the time between two reads, for the header of the response and for each pause of the body alike; a proxy of model APIs has to set it above the longest pause of a stream, so a server that never answers holds a request for as long. mruby_upstream_first_byte_timeout TIME; in the http, server or location block bounds the wait for the header alone (#899):

    upstream model_api {
        server 192.0.2.10:8080;
        server 192.0.2.11:8080;
    }
    
    server {
        listen 8080;
    
        location /v1/ {
            mruby_upstream_first_byte_timeout 20s;
            proxy_read_timeout 600s;
            proxy_next_upstream error timeout non_idempotent;
            proxy_buffering off;
            proxy_pass http://model_api;
        }
    }

    A server that accepts the request and sends nothing is given up after 20 seconds, and nginx sends the request to the next server; a POST only with non_idempotent. Without proxy_next_upstream timeout, the client gets 504. A stream that has begun may pause for up to 600 seconds.

    • The time of an attempt starts when nginx has chosen the server, so the connection, the TLS handshake and the sending of the request are in it. It ends when nginx has read the whole header; a 103 (Early Hints) does not end it. Each attempt has the whole time.
    • It works for all modules of nginx that use an upstream (proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass, memcached_pass and grpc_pass), to an upstream {} block or to an address that is written in one of them, and not for an address that nginx takes from a variable or resolves at request time: a request in such a location logs a line at warn at its end.
    • The directive runs no Ruby, and a configuration without it runs no code for it.
    • The page of mruby_upstream_first_byte_timeout has the details, and the guide on relaying model API requests shows where it goes.
  • Fixes of mruby_upstream_keepalive. It now works with the modules of nginx that use the call that nginx makes to the peer of an upstream when the header of a response has arrived (sticky learn with the parameter header, and least_time header inflight): with sticky learn before mruby_upstream_keepalive in the block, a request could get no response. It also replaces the two functions that keep a TLS session of the upstream under the condition under which nginx declares them, so that an https upstream of such a block works in a module that was configured with --with-compat and without SSL, and it no longer keeps a connection whose request body was not fully sent, as nginx's own keepalive does not. A module built without SSL does not keep a TLS connection that it cannot shut down. 2.7.17 has the same fixes; "Behavior changes" below has the three that change what a configuration can observe.

  • Instructions per request close to those of 3.0.0-alpha.4. The tree of this release was compared with 3.0.0-alpha.4 under callgrind before the tag. No scenario is at WARN or FAIL. In the number that the comparison judges, without the GC and the constant lookups that missed mruby's cache, the largest change is in the handler from a file (+0.03%, 5 instructions per request), and the largest decrease in a plain proxy of a stream (-0.02%, 9 instructions). The scenarios of the first-byte deadline have no base to compare with. A request of a configuration without mruby_upstream_first_byte_timeout runs no code of it. In one with it, a proxied request of about 21,400 instructions runs about 260 more with a deadline and about 50 more in a location without one, as the reference says (measured on 2026-11-30). These are instruction counts, not wall-clock times; the table is below.

  • 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. The migration guide lists what changes for a configuration or a script of 2.x.

The comparison with 3.0.0-alpha.4 (callgrind, before the tag)

Base v3.0.0-alpha.4 (96d2dc9a9), head the tree of this tag, in a Linux container on an arm64 host. The scenarios peer_hook_* and first_byte_* need a directive that the base does not have, so they have no comparison (n/a).

perf: N=20000 WARMUP=2000; Ir per request of nginx; WARN from 3.0%, FAIL from 5.0% on the number in the column judged: w/o GC/const (Ir/req minus the GC and the constant lookups that missed the cache), or w/o GC (minus the GC only) where the head clears the constant cache more often, or clears it and misses more lookups (const_clears, const_misses)
perf: units: stream_sleep = completed TCP session; other rows = HTTP request
perf: gems: 8 in both builds, 0 at different commits, 0 only in base, 0 only in head
perf: mruby: base 4.1.0, head 4.1.0; accepted differences (accepted.txt): none apply

scenario                   base Ir/req  head Ir/req  change  base w/o GC  head w/o GC  change w/o GC  base w/o GC/const  head w/o GC/const  change w/o GC/const     GC share        judged                         result
hello                            11154        11157  +0.02%        10446        10449         +0.02%              10446              10449               +0.02%    6.3%/6.3%  w/o GC/const                             ok
headers                          29940        29942  +0.01%        24683        24685         +0.01%              24683              24685               +0.01%  17.6%/17.6%  w/o GC/const                             ok
var                              20208        20210  +0.01%        17150        17152         +0.01%              17150              17152               +0.01%  15.1%/15.1%  w/o GC/const                             ok
filter                           14596        14596  +0.00%        12798        12798         +0.00%              12798              12798               +0.00%  12.3%/12.3%  w/o GC/const                             ok
sleep                            15325        15325  +0.00%        14098        14098         +0.00%              14098              14098               +0.00%    8.0%/8.0%  w/o GC/const                             ok
sub_request                      43562        43564  +0.01%        41884        41886         +0.01%              41884              41886               +0.01%    3.9%/3.9%  w/o GC/const                             ok
file                             14174        14179  +0.03%        12370        12375         +0.03%              12370              12375               +0.03%  12.7%/12.7%  w/o GC/const                             ok
dict_base                        11572        11575  +0.02%        10611        10613         +0.02%              10611              10613               +0.02%    8.3%/8.3%  w/o GC/const                             ok
dict_lookup                      12301        12303  +0.02%        11340        11342         +0.02%              11340              11342               +0.02%    7.8%/7.8%  w/o GC/const                             ok
dict_get                         13822        13824  +0.01%        12350        12352         +0.02%              12350              12352               +0.02%  10.7%/10.7%  w/o GC/const                             ok
dict_incr                        13448        13451  +0.02%        12227        12229         +0.02%              12227              12229               +0.02%    9.1%/9.1%  w/o GC/const                             ok
proxy_plain_2k                   21817        21818  +0.01%        21817        21818         +0.01%              21817              21818               +0.01%    0.0%/0.0%  w/o GC/const                             ok
proxy_plain_64k                  22132        22134  +0.01%        22132        22134         +0.01%              22132              22134               +0.01%    0.0%/0.0%  w/o GC/const                             ok
proxy_stream_plain_50            54154        54145  -0.02%        54154        54145         -0.02%              54154              54145               -0.02%    0.0%/0.0%  w/o GC/const                             ok
responses_stream_plain_50        55394        55395  +0.00%        55394        55395         +0.00%              55394              55395               +0.00%    0.0%/0.0%  w/o GC/const                             ok
auth                             48144        48146  +0.00%        41832        41834         +0.00%              41832              41834               +0.00%  13.1%/13.1%  w/o GC/const                             ok
route_json_2k                   106979       106981  +0.00%        98316        98318         +0.00%              98316              98318               +0.00%    8.1%/8.1%  w/o GC/const                             ok
ruby_call_1                      10917        10917  +0.00%        10176        10176         +0.00%              10176              10176               +0.00%    6.8%/6.8%  w/o GC/const                             ok
ruby_call_10                     41451        41451  +0.00%        34092        34092         +0.00%              34092              34092               +0.00%  17.8%/17.8%  w/o GC/const                             ok
peer_hook_2k                         -            -       -            -            -              -                  -                  -                    -            -             -  n/a (base: unknown directive)
peer_hook_stream_50                  -            -       -            -            -              -                  -                  -                    -            -             -  n/a (base: unknown directive)
first_byte_2k                        -            -       -            -            -              -                  -                  -                    -            -             -  n/a (base: unknown directive)
first_byte_stream_50                 -            -       -            -            -              -                  -                  -                    -            -             -  n/a (base: unknown directive)
stream_sleep                     12236        12236  +0.00%        11293        11293         +0.00%              11293              11293               +0.00%    7.7%/7.7%  w/o GC/const                             ok

What comes next

The next pre-releases are planned to add the parts of an AI gateway below. None of them is in this pre-release.

  • 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.
  • Reading one value of a JSON request body, such as the model, without turning the whole body into Ruby values.
  • A reference agent proxy built on these parts and on the shared dictionary. It is planned to keep the token and money budgets of each client key in the shared dictionary of one host; a non-blocking socket API that would share them across hosts is in the plan too, and its design is still to be evaluated.

Step 7 of the v3 plan lists the parts and their order: the shared dictionary and the first-byte deadline are its parts (a) and (c), and these are the others. 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

Three entries of "Behavior changes" were added since 3.0.0-alpha.4, all on mruby_upstream_keepalive. The other changes of the release notes since 3.0.0-alpha.4 are under "New features" (the first-byte deadline), "Fixes" and "Build and test changes". The release notes of this tag have all 83 entries.

least_time header inflight counts the time of the header in an upstream block with mruby_upstream_keepalive

  • Before: with nginx 1.31 built with --with-http_ssl_module, nginx did not count the time to receive the header of a response for the servers of an upstream {} block with least_time header inflight and mruby_upstream_keepalive. When requests came one after another to two servers, the one that sends its header after a second got as many of them as the one that answers at once.
  • Now: nginx counts that time, and prefers the server with the least time, as it does with its own keepalive directive.
  • Why it changed:
    • The defect: least_time header inflight takes the time of the header from the call that nginx makes to the peer of an upstream when the header of a response has arrived (peer.notify). mruby_upstream_keepalive puts functions of its own in the place of those of the peer and had none for this call, so least_time did not count the time.
    • Why the old behavior could not be kept: the same call is what requests need that got no response (the first entry of "Fixes" in the release notes). Once mruby_upstream_keepalive passes it on, least_time counts the time.
    • What the documentation promised: nginx's documentation of least_time says that a request is passed to the server with the least average response time and the least number of active connections, and that with the parameter header the time to receive the response header is used. mruby_upstream_keepalive is documented as the same as nginx's keepalive, with which nginx counts the time.
  • Affected: upstream {} blocks with least_time header inflight and, after it, mruby_upstream_keepalive, in nginx 1.31 built with --with-http_ssl_module. least_time without inflight or with last_byte does not use the call and is the same as before.
  • What to do: nothing where the block is meant to prefer the faster server. A block that should not take the time of the header into account needs another load balancing method, for example least_conn.

mruby_upstream_keepalive does not keep an upstream connection whose request body was not fully sent

  • Before: an upstream {} block with mruby_upstream_keepalive kept an upstream connection in its pool, to reuse for a later request, even when nginx had sent the response before it finished sending the request body to that upstream.
  • Now: mruby_upstream_keepalive closes such a connection instead of keeping it, as nginx's own keepalive directive does.
  • Why it changed:
    • The defect: an upstream connection whose request body nginx had not finished sending was kept and reused for a later request. When it was reused, the upstream could read bytes of the earlier request's body as the beginning of the later request, which may come from a different client; GHSA-qq6c-wv62-6wjh has the details.
    • Why the old behavior could not be kept: nginx's keepalive does not keep such a connection, so the fix closes it the same way; nginx's keepalive has closed it since nginx 1.9.10.
    • What the documentation promised: mruby_upstream_keepalive is documented as the same as nginx's keepalive, which does not keep such a connection (nginx's keepalive).
  • Affected: upstream {} blocks with mruby_upstream_keepalive whose upstream sends the response before nginx finishes sending the request body. A block whose upstream reads the whole body before it responds, or closes the connection, is unchanged.
  • What to do: nothing; rebuild with this release.

mruby_upstream_keepalive does not keep an upstream connection it cannot shut down in a module built without SSL

  • Before: a module built with --with-compat and without --with-http_ssl_module, loaded into an nginx that has SSL, kept an upstream connection of an https upstream of a block with mruby_upstream_keepalive in its pool, to reuse for a later request, although it could not shut that connection's SSL down when it later closed it.
  • Now: mruby_upstream_keepalive does not keep such a connection in such a build; nginx opens a new connection to the https upstream for each request and closes each one, with its SSL object, itself. A module built with the same SSL options as nginx is unchanged.
  • Why it changed:
    • The defect: in a module built without SSL, a cached https upstream connection was closed without its SSL being shut down. This release also lets such a build answer the https upstream requests of a block with mruby_upstream_keepalive (the second entry under "Fixes" in the release notes), so these connections reach the cache.
    • Why the old behavior could not be kept: a module built without SSL cannot call ngx_ssl_shutdown, so it cannot shut such a connection down itself; by not keeping it, it leaves the close to nginx, which does.
    • What the documentation promised: mruby_upstream_keepalive is documented as the same as nginx's keepalive; nginx's own keepalive shuts an SSL connection down when it closes it.
  • Affected: a module built with --with-compat and without --with-http_ssl_module and loaded into an nginx that has SSL, with an https upstream of a block with mruby_upstream_keepalive. A build where nginx and the module have the same SSL options is unchanged.
  • What to do: nothing; rebuild with this release. To reuse TLS connections to an https upstream, build the module with --with-http_ssl_module.

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

ngx_mruby 3.0は、次のメジャーバージョンです。通常のWebサービスに加えて、AIアプリケーション、モデルAPI、MCPサーバーの前でRubyのルールを動かすことを目指しています。この5つ目のプレリリースでは、upstreamのレスポンスの最初のバイトを待つ時間の上限を足し、mruby_upstream_keepaliveの不具合を直しました。上限は、計画しているエージェントプロキシの部品のうち、2つ目に入ったものです。ほかの部品は、この後のプレリリースで足す予定です。下の「これから入るもの」を見てください。

  • upstreamのレスポンスの最初のバイトを待つ時間を決められます。 モデルAPIは、リクエストを受け付けたまま、何も送らないことがあります。nginxで、その待ち時間を決めるのはproxy_read_timeoutだけです。これは2回の読み込みの間の時間で、レスポンスのヘッダにも、ボディの休止にも同じ値が使われます。モデルAPIを中継するプロキシでは、ストリームの最も長い休止より長くする必要があるので、何も応答しないサーバーへのリクエストも、その時間だけ待ちます。http、server、locationのブロックにmruby_upstream_first_byte_timeout TIME;を書くと、ヘッダを待つ時間だけに上限を設けます(#899)。

    upstream model_api {
        server 192.0.2.10:8080;
        server 192.0.2.11:8080;
    }
    
    server {
        listen 8080;
    
        location /v1/ {
            mruby_upstream_first_byte_timeout 20s;
            proxy_read_timeout 600s;
            proxy_next_upstream error timeout non_idempotent;
            proxy_buffering off;
            proxy_pass http://model_api;
        }
    }

    リクエストを受け付けたまま何も送らないサーバーを、nginxは20秒で打ち切り、次のサーバーへ送ります。POSTを次のサーバーへ送るのは、non_idempotentがあるときだけです。proxy_next_upstream timeoutが無ければ、クライアントに504を返します。始まったストリームは、600秒まで休止できます。

    • 時間は、nginxがサーバーを選んだときから数えます。接続、TLSハンドシェイク、リクエストの送信の時間も含みます。ヘッダを全部読んだときに終わります。103(Early Hints)では終わりません。試行ごとに、上限の全体を使えます。
    • upstreamを使うnginxのすべてのモジュール(proxy_pass、fastcgi_pass、uwsgi_pass、scgi_pass、memcached_pass、grpc_pass)で、upstreamブロックにも、これらのディレクティブに直接書いたアドレスにも使えます。nginxが変数から得るアドレスと、リクエストの処理中に名前解決するアドレスには使えません。そのようなlocationのリクエストでは、終わりにwarnのログを1行出します。
    • このディレクティブは、Rubyを動かしません。書いていない設定では、このディレクティブのコードは動きません。
    • 詳しくはmruby_upstream_first_byte_timeoutに、置く場所はモデルAPIの中継のガイドにあります。
  • mruby_upstream_keepaliveの不具合を直しました。 レスポンスのヘッダが届いたときにnginxがupstreamのピアに対して行う呼び出しを使うモジュール(パラメータheader付きのsticky learnと、least_time header inflight)と、一緒に使えるようになりました。sticky learnをmruby_upstream_keepaliveより前に書いたブロックでは、リクエストにレスポンスが返らないことがありました。upstreamとのTLSセッションを保持する2つの関数も、nginxがそれを宣言する条件に合わせて差し替えます。--with-compat付き、SSL無しでビルドしたモジュールでも、このブロックのhttpsのupstreamが動きます。リクエストの本文を送り切っていない接続は、nginx自身のkeepaliveと同じように、保持しません。SSL無しでビルドしたモジュールは、閉じられないTLS接続を保持しません。同じ修正は、2.7.17にも入っています。設定から見える挙動が変わる3つは、下の「更新前に確認する挙動の変更」にあります。

  • リクエストあたりの命令数は、3.0.0-alpha.4に近い値です。 タグを付ける前に、このリリースのtreeと3.0.0-alpha.4を、callgrindで比べました。WARNとFAILのシナリオはありません。判定に使う値は、GCと、mrubyの定数キャッシュに当たらなかった定数の参照を除いた命令数です。この値がいちばん大きく変わったのは、ファイルに書いたハンドラで、0.03%、1リクエストあたり5命令増えました。いちばん大きく減ったのは、ストリームをそのまま中継するシナリオで、0.02%、9命令です。最初のバイトの期限のシナリオには、比べる相手がありません。mruby_upstream_first_byte_timeoutを書いていない設定では、リクエストの処理でそのコードは動きません。書いた設定では、約21,400命令の中継のリクエスト1つが、期限のあるlocationでは約260命令、期限の無いlocationでは約50命令増えます。この値は、2026年11月30日に測って、リファレンスに書いたものです。どれも命令数で、実行時間ではありません。表は下にあります。

  • 手元で試せます。 examples/startは、Docker Composeで、モデルに応じてリクエストを2つのモックAPIのどちらかへ振り分けるnginxを動かします。プロバイダのAPIキーは不要です。2.xの設定やスクリプトで変わる点は、移行の手引きにあります。

タグを付ける前に測った、3.0.0-alpha.4との比較

callgrindで測りました。baseはv3.0.0-alpha.4(96d2dc9a9)、headはこのタグのtreeで、arm64のホストのLinuxのコンテナを使いました。peer_hook_*とfirst_byte_*のシナリオは、baseに無いディレクティブを使うので、比べられずn/aになります。

perf: N=20000 WARMUP=2000; Ir per request of nginx; WARN from 3.0%, FAIL from 5.0% on the number in the column judged: w/o GC/const (Ir/req minus the GC and the constant lookups that missed the cache), or w/o GC (minus the GC only) where the head clears the constant cache more often, or clears it and misses more lookups (const_clears, const_misses)
perf: units: stream_sleep = completed TCP session; other rows = HTTP request
perf: gems: 8 in both builds, 0 at different commits, 0 only in base, 0 only in head
perf: mruby: base 4.1.0, head 4.1.0; accepted differences (accepted.txt): none apply

scenario                   base Ir/req  head Ir/req  change  base w/o GC  head w/o GC  change w/o GC  base w/o GC/const  head w/o GC/const  change w/o GC/const     GC share        judged                         result
hello                            11154        11157  +0.02%        10446        10449         +0.02%              10446              10449               +0.02%    6.3%/6.3%  w/o GC/const                             ok
headers                          29940        29942  +0.01%        24683        24685         +0.01%              24683              24685               +0.01%  17.6%/17.6%  w/o GC/const                             ok
var                              20208        20210  +0.01%        17150        17152         +0.01%              17150              17152               +0.01%  15.1%/15.1%  w/o GC/const                             ok
filter                           14596        14596  +0.00%        12798        12798         +0.00%              12798              12798               +0.00%  12.3%/12.3%  w/o GC/const                             ok
sleep                            15325        15325  +0.00%        14098        14098         +0.00%              14098              14098               +0.00%    8.0%/8.0%  w/o GC/const                             ok
sub_request                      43562        43564  +0.01%        41884        41886         +0.01%              41884              41886               +0.01%    3.9%/3.9%  w/o GC/const                             ok
file                             14174        14179  +0.03%        12370        12375         +0.03%              12370              12375               +0.03%  12.7%/12.7%  w/o GC/const                             ok
dict_base                        11572        11575  +0.02%        10611        10613         +0.02%              10611              10613               +0.02%    8.3%/8.3%  w/o GC/const                             ok
dict_lookup                      12301        12303  +0.02%        11340        11342         +0.02%              11340              11342               +0.02%    7.8%/7.8%  w/o GC/const                             ok
dict_get                         13822        13824  +0.01%        12350        12352         +0.02%              12350              12352               +0.02%  10.7%/10.7%  w/o GC/const                             ok
dict_incr                        13448        13451  +0.02%        12227        12229         +0.02%              12227              12229               +0.02%    9.1%/9.1%  w/o GC/const                             ok
proxy_plain_2k                   21817        21818  +0.01%        21817        21818         +0.01%              21817              21818               +0.01%    0.0%/0.0%  w/o GC/const                             ok
proxy_plain_64k                  22132        22134  +0.01%        22132        22134         +0.01%              22132              22134               +0.01%    0.0%/0.0%  w/o GC/const                             ok
proxy_stream_plain_50            54154        54145  -0.02%        54154        54145         -0.02%              54154              54145               -0.02%    0.0%/0.0%  w/o GC/const                             ok
responses_stream_plain_50        55394        55395  +0.00%        55394        55395         +0.00%              55394              55395               +0.00%    0.0%/0.0%  w/o GC/const                             ok
auth                             48144        48146  +0.00%        41832        41834         +0.00%              41832              41834               +0.00%  13.1%/13.1%  w/o GC/const                             ok
route_json_2k                   106979       106981  +0.00%        98316        98318         +0.00%              98316              98318               +0.00%    8.1%/8.1%  w/o GC/const                             ok
ruby_call_1                      10917        10917  +0.00%        10176        10176         +0.00%              10176              10176               +0.00%    6.8%/6.8%  w/o GC/const                             ok
ruby_call_10                     41451        41451  +0.00%        34092        34092         +0.00%              34092              34092               +0.00%  17.8%/17.8%  w/o GC/const                             ok
peer_hook_2k                         -            -       -            -            -              -                  -                  -                    -            -             -  n/a (base: unknown directive)
peer_hook_stream_50                  -            -       -            -            -              -                  -                  -                    -            -             -  n/a (base: unknown directive)
first_byte_2k                        -            -       -            -            -              -                  -                  -                    -            -             -  n/a (base: unknown directive)
first_byte_stream_50                 -            -       -            -            -              -                  -                  -                    -            -             -  n/a (base: unknown directive)
stream_sleep                     12236        12236  +0.00%        11293        11293         +0.00%              11293              11293               +0.00%    7.7%/7.7%  w/o GC/const                             ok

これから入るもの

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

  • ストリーミングで返るモデルの応答から、server-sent events(SSE)のイベントを1つずつ読むフィルタを足す予定です。トークンの使用量を数えるときなどに使います。
  • JSONのリクエストボディから、モデルなどの値を1つだけ、ボディ全体をRubyの値にせずに読む仕組みを足す予定です。
  • これらの部品と共有辞書で作る、リファレンス実装のエージェントプロキシを足す予定です。このプロキシは、クライアントのキーごとのトークンと金額の予算を、1台のホストの共有辞書に置く計画です。複数のホストで予算を共有するための、ノンブロッキングのソケットAPIも計画にあり、設計はこれから評価します。

部品とその順序は、v3の計画のステップ7にあります。共有辞書と最初のバイトの期限は、その(a)と(c)で、上の部品は残りの部品です。これらの部品を使う用途には、MCPのツール呼び出しの認可、エージェントが短時間に繰り返す呼び出しの制限、モデルAPIのフォールバック、AIクローラーの制御などがあります。用途ごとの設計の状態は、トップページと用途の一覧にあります。

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

3.0.0-alpha.4から追加された項目は3つで、どれもmruby_upstream_keepaliveの項目です。3.0.0-alpha.4からのリリースノートの変更は、ほかに、「新機能」の最初のバイトの期限の項目、「不具合の修正」、「ビルドとテストの変更」の項目にあります。全83項目は、このタグのリリースノートにあります。

mruby_upstream_keepaliveのあるupstreamブロックで、least_time header inflightがレスポンスのヘッダを受け取るまでの時間を集計する

  • 変更前:--with-http_ssl_module付きでビルドしたnginx 1.31では、least_time header inflightとmruby_upstream_keepaliveのあるupstream {}ブロックのサーバーについて、レスポンスのヘッダを受け取るまでの時間を、nginxが集計していませんでした。サーバーが2台のブロックにリクエストが1つずつ順に届くと、ヘッダを1秒後に送るサーバーにも、すぐに応答するサーバーと同じ数のリクエストを渡していました。
  • 変更後:nginxは、その時間を集計し、時間が最も短いサーバーを優先します。nginx自身のkeepaliveディレクティブを使うときと同じ動作です。
  • 変更の理由:
    • 不具合:least_time header inflightは、レスポンスのヘッダが届いたときにnginxがupstreamのピアに対して行う呼び出し(peer.notify)で、この時間を集計します。mruby_upstream_keepaliveは、ピアの関数を自分の関数に差し替えますが、この呼び出しに対応する関数を用意していませんでした。そのため、least_timeは時間を集計しませんでした。
    • 前の挙動を残せなかった理由:リリースノートの「不具合の修正」の最初の項目にある、レスポンスが返らない不具合を直すには、mruby_upstream_keepaliveが、この呼び出しを、それを使うモジュールに渡す必要があります。渡すと、least_timeも時間を集計します。
    • ドキュメントが示していた挙動:nginxのleast_timeのドキュメントには、平均の応答時間が最も短く、アクティブな接続の数が最も少ないサーバーにリクエストを渡し、パラメータがheaderのときはレスポンスのヘッダを受け取るまでの時間を使う、とあります。mruby_upstream_keepaliveは、ドキュメントでは、nginxのkeepaliveと同じとされています。keepaliveを使うブロックでは、nginxはこの時間を集計します。
  • 影響の範囲:--with-http_ssl_module付きでビルドしたnginx 1.31で、least_time header inflightと、その後に書いたmruby_upstream_keepaliveがあるupstream {}ブロックです。inflightの無いleast_timeと、last_byteを指定したleast_timeは、peer.notifyの呼び出しを使わないので、前と同じです。
  • 必要な対応:速いサーバーを優先するためのブロックでは、対応は要りません。ヘッダを受け取るまでの時間をサーバーの選択に使いたくないブロックでは、least_connなどの別の負荷分散の方式に変えてください。

mruby_upstream_keepaliveは、リクエストの本文を送り切っていない接続を保持しない

  • 変更前:mruby_upstream_keepaliveのあるupstream {}ブロックは、nginxがリクエストの本文をupstreamへ送り切る前にレスポンスを返した接続でも、後続のリクエストで使い回すために、プールに保持していました。
  • 変更後:mruby_upstream_keepaliveは、その接続を保持せず閉じます。nginx自身のkeepaliveディレクティブと同じ動作です。
  • 変更の理由:
    • 不具合:nginxが本文を送り切っていない接続を、保持して後続のリクエストで使い回していました。使い回すと、upstreamが、前のリクエストの送り切られなかった本文のバイトを、後続のリクエストの先頭として読むことがありました。後続のリクエストは、別のクライアントのものであることもあります。詳細はGHSA-qq6c-wv62-6wjhにあります。
    • 前の挙動を残せなかった理由:nginxのkeepaliveは、このような接続を保持しないので、修正でも同じように閉じます。nginxのkeepaliveは、nginx 1.9.10以降、このように閉じています。
    • ドキュメントが示していた挙動:mruby_upstream_keepaliveは、ドキュメントでは、nginxのkeepaliveと同じとされています。nginxのkeepaliveは、このような接続を保持しません(nginxのkeepalive)。
  • 影響の範囲:mruby_upstream_keepaliveのあるupstream {}ブロックで、upstreamが、nginxがリクエストの本文を送り切る前にレスポンスを返す場合です。upstreamが本文を全部読んでから応答するブロックや、接続を閉じるブロックは、前と同じです。
  • 必要な対応:ありません。このリリースでモジュールをビルドし直してください。

mruby_upstream_keepaliveは、SSL無しでビルドしたモジュールでは、閉じられない接続を保持しない

  • 変更前:--with-compat付き、--with-http_ssl_module無しでビルドしたモジュールを、SSL付きのnginxで使うとき、mruby_upstream_keepaliveのあるブロックのhttpsのupstreamの接続を、後続のリクエストで使い回すためにプールに保持していました。しかし、後でその接続を閉じるときに、接続のSSLをシャットダウンできませんでした。
  • 変更後:このビルドでは、mruby_upstream_keepaliveはその接続を保持しません。nginxが、httpsのupstreamへの接続をリクエストごとに新しく開き、SSLオブジェクトも含めて自分で閉じます。nginxとモジュールを同じSSLのオプションでビルドしているときは、前と同じです。
  • 変更の理由:
    • 不具合:SSL無しでビルドしたモジュールで、キャッシュしたhttpsのupstreamの接続を、SSLをシャットダウンせずに閉じていました。このリリースでは、このビルドでもmruby_upstream_keepaliveのあるブロックのhttpsのupstreamのリクエストに応答するようになる(リリースノートの「不具合の修正」の2つ目の項目)ので、これらの接続がキャッシュに入ります。
    • 前の挙動を残せなかった理由:SSL無しでビルドしたモジュールは、ngx_ssl_shutdownを呼べないので、このような接続を自分で閉じられません。接続を保持しないことで、閉じる処理をnginxに任せ、nginxがSSLをシャットダウンします。
    • ドキュメントが示していた挙動:mruby_upstream_keepaliveは、ドキュメントでは、nginxのkeepaliveと同じとされています。nginx自身のkeepaliveは、SSLの接続を閉じるときにSSLをシャットダウンします。
  • 影響の範囲:--with-compat付き、--with-http_ssl_module無しでビルドしたモジュールを、SSL付きのnginxで使い、mruby_upstream_keepaliveのあるブロックにhttpsのupstreamがある場合です。nginxとモジュールを同じSSLのオプションでビルドしているときは、前と同じです。
  • 必要な対応:ありません。このリリースでモジュールをビルドし直してください。httpsのupstreamへのTLS接続を使い回すには、--with-http_ssl_module付きでモジュールをビルドしてください。