expfmt: TextParser cost grows quadratically with the number of labels on a sample

オープン 初心者向け
#1,051 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go, yaml

調査の方向性

二次的な重複チェックは、expfmt のテキストパーサー(prometheus/common の expfmt/text_parse.go)内の startLabelName にあります。まずこの関数を読み、その後、各サンプルに対してこれを呼び出すラベル読み取りループを読んでください。完了の条件は、サンプルごとに1つのセットを保持し、ラベル名ごとに1回だけ挿入すること、既存のテキストパーサーのテストが引き続き通ること、そして40ラベルのゲージがより安価になったことを示すベンチマークがあることです。

索引モデルが issue の本文から書いたものです。

説明

The text parser checks each label name of a sample for duplicates in startLabelName. At each label it builds a new map of all the labels read so far, so a sample with n labels costs n maps and n(n+1)/2 inserts: 136 for 16 labels, 820 for 40.

Info-style metrics often carry many labels. vLLM exposes vllm:cache_config_info as one sample with 40 labels, and a scraper built on this parser parses it on every scrape. In llm-d's endpoint picker, which parses a few families from each vLLM endpoint every 50 ms, this line is half of the scrape CPU.

TextParser.TextToMetricFamilies on v0.74.0 with model.UTF8Validation, a new parser per iteration, Go 1.27.0 on darwin/arm64 (Apple M5), medians of six runs:

input time allocated allocations
gauge, 1 label 1.0 µs 5.4 KB 36
gauge, 16 labels 6.9 µs 13.5 KB 173
gauge, 40 labels 35.5 µs 73.0 KB 487
vllm:cache_config_info from vLLM 0.34 (HELP, TYPE and the 40-label sample) 41 µs 73.6 KB 492
vLLM 0.34 /metrics page, 643 lines 614 µs 589 KB 16,301
the same page without vllm:cache_config_info 553 µs 520 KB 15,818

Above the 1-label line, going from 16 to 40 labels multiplies the time by 5.9, close to the 6.0 ratio of the insert counts. In a CPU profile of the 40-label gauge, startLabelName takes 86% of the time spent in TextToMetricFamilies and 90% of the allocated bytes. On the full vLLM page, the one 40-label line accounts for 12% of the bytes the parser allocates.

Keeping one set per sample and adding each label name as it is read would make the check one insert per label.

主要言語
Go
スター
297
フォーク
380
平均マージ
3日 18時間
マージ済み PR(30日)
12

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

prometheus/common のほかの issue

prometheus/common の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。