Manual:maxlag パラメーター

This page is a translated version of the page Manual:Maxlag parameter and the translation is 78% complete.

maxlag is something that can be added to any Action API query. When set, the API query will ask the server if it is too busy. If it is, the API query will return an error instead of processing the API request. The error message will include the number of seconds behind it is, and this information can be used to determine how long to wait before retrying the query. The idea is to pause bot edits during times of high server load, to give human edits priority. This is an optional but recommended parameter, and many major bot frameworks such as pywikibot implement it by default.

(ウィキメディアのように) 複製データベース クラスター上で MediaWiki を稼働させている場合、高い編集率によってレプリカ サーバーが遅延することがあります。 複製の遅延を和らげる一つの方法は遅延がある値を超えたときはすべてのボットとメンテナンスタスクを自動的に停止させることです。 MediaWiki 1.10において、導入されたmaxlagパラメーターはクライアントサイドで同じことを行うことを可能にします。 1.27以降では、api.phpリクエストにのみ適用されます。

maxlag パラメーターは、URL パラメーター、POST データ、 Cookie を通して api.php に渡せます。秒数の整数値です。 For example, this link shows metadata about the page "MediaWiki" unless the lag is greater than 1 second while this one (with -1 at the end) shows you the actual lag without metadata.

リクエスト時に指定された遅延時間を超えた場合、APIは以下のようなエラー(200のステータスコード、タスク T33156参照)を返します:

{
    "error": {
        "code": "maxlag",
        "info": "Waiting for $host: $lag seconds lagged",
        "host": $host,
        "lag": $lag,
        "*": "See https://www.mediawiki.org/w/api.php for API usage"
    }
}

次のようなHTTPヘッダーが設定されます:

  • Retry-After: 再試行をする前にクライアントが待つ推奨の最小秒数。
  • X-Database-Lag: もっとも遅延した複製の遅延秒数

Wikimediaのwiki群に対する推奨される使い方は次の通りです:

  • maxlag=5 (5秒)を指定する。これはリクエストが激しくならない適切な値で、Pywikibot の既定値にもなっています。大きい値にするほど動作が激しくなり、小さい値にするほど控えめになります。
  • 遅延エラーを受け取る場合、再び試す前に少なくとも5秒間はスクリプトを停止させて下さい。ビジーループに陥らないように注意して下さい。
  • この値によって、データベースの負荷が高いときに低いデューティサイクルを得る可能性があります。それはOKで、負荷が高い状態が終わるのを待ってください。編集を拒否することで利用者の時間を無駄にしたくないため、負荷が高いときは人間を優先します。
  • 普通ではない高いもしくは持続する遅延はIRC上の#wikimedia-tech 接続に報告されます。
  • Interactive tasks (where a user is waiting for the result) may omit the maxlag parameter. Noninteractive tasks should always use it.

See also API:Etiquette#The maxlag parameter.

アップストリーム サーバーのタイムアウトが原因で、キャッシュ層 (Varnish または Squid) が 503 ステータス コードを持つエラーメッセージを生成する場合もあることにご注意ください。 Clients should treat these errors differently, because they may occur consistently when you try to perform a long-running expensive operation. Repeating the operation on timeout would use excessive server resources and may leave your client in an infinite loop. 以下のいずれかを使用して、キャッシュ層のエラーとMediaWikiの遅延条件を区別できます:

  • X-Database-Lag header is distinctive to replication lag errors in MediaWiki
  • Varnish エラーでは Retry-After はありません
  • X-Squid-Errorヘッダーはsquidエラーで表示されます
  • 複製遅延エラーでのレスポンス ボディは正規表現の /Waiting for [^ ]*: [0-9.-]+ seconds? lagged/ にマッチします

テストの目的のために、負の値を渡すことで故意にソフトウェアにリクエストを拒否させることが出来ます。例えば次のURLです: //www.mediawiki.org/w/api.php?action=query&titles=MediaWiki&format=json&maxlag=-1