Repository navigation
[TRTLLM-9181][feat] improve disagg-server prometheus metrics; synchronize workers' clocks when workers are dynamic - #9726
Conversation
📝 WalkthroughWalkthroughThis PR enhances port management, networking, metrics collection, and observability across the distributed serving infrastructure. It adds centralized free port utilities, improves localhost handling in cluster workers, introduces server-side metrics with queue latency tracking, and extends test infrastructure with logging and configuration support. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~65 minutes
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
tensorrt_llm/serve/disagg_auto_scaling.py (1)
242-263: Localhost-aware worker registration is reasonable; minor constant/type tweaksThe new
LOCALHOST_IPSlogic inDisaggClusterWorker.__init__correctly avoids registering workers underlocalhost/0.0.0.0when the cluster storage URI is non-local, which should make cross-host routing more robust.Two small follow-ups:
- To reflect that
LOCALHOST_IPSis a class-level constant and avoid mutable-class-attribute lint noise, consider making it immutable and annotating it as aClassVar:-from typing import Any, Awaitable, Callable, Dict, List, Optional, Tuple +from typing import Any, Awaitable, Callable, ClassVar, Dict, List, Optional, Tuple @@ -class DisaggClusterWorker: - """ - The cluster worker is responsible for registering and deregistering the worker to the cluster storage. - It will send heartbeat to the cluster storage every heartbeat_interval_sec seconds. - If the worker heartbeat fails, it will re-register itself. - """ - LOCALHOST_IPS = ["localhost", "127.0.0.1", "0.0.0.0", "::1"] +class DisaggClusterWorker: + """ + The cluster worker is responsible for registering and deregistering the worker to the cluster storage. + It will send heartbeat to the cluster storage every heartbeat_interval_sec seconds. + If the worker heartbeat fails, it will re-register itself. + """ + LOCALHOST_IPS: ClassVar[Tuple[str, ...]] = ( + "localhost", + "127.0.0.1", + "0.0.0.0", + "::1", + )
- The
if localhost in self._config.cluster_uricheck is a pragmatic heuristic. Ifcluster_uriformats ever get more complex (e.g., hostnames that merely contain the substring"localhost"), it may be worth tightening this by parsing the URI and comparing only the host component, but that’s not strictly required for the current usage.The
random.randint(...)inworker_idcontinues to be fine for non‑cryptographic uniqueness; the S311 warning from static analysis can be treated as informational here.tensorrt_llm/serve/openai_client.py (1)
184-187: Metrics instrumentation is consistent; consider covering streaming handshake failuresThe new client-side metrics look coherent:
- Non-streaming requests now observe
complete_latency_secondsafter a successful response and finishing the request.- Streaming requests track
first_token_latency_secondsandper_token_latency_secondsonly when actual chunks are received, and observecomplete_latency_secondsonce the stream ends._finish_requestcentralizes router finalization andcompleted_requestsaccounting.One subtle gap worth noting (likely pre-existing): for streaming requests where the HTTP connection never succeeds and
_response_generatoris never entered (e.g.,aiohttp.ClientErroron all retries while establishing the connection),_finish_requestis never invoked because that logic lives only in_response_generator’sfinallyand in the non-stream error path of_send_request. This can leave the router thinking the request is still in flight.If this scenario is relevant in practice, consider a follow-up refactor so that streaming paths also guarantee
_finish_requestis awaited exactly once in all outcomes, including “no response body” failures (for example, by wrapping the returned async generator or adding a small streaming-specific cleanup in the retry loop).Also applies to: 223-237, 243-245, 258-260
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
tensorrt_llm/_utils.py(1 hunks)tensorrt_llm/llmapi/mpi_session.py(1 hunks)tensorrt_llm/serve/disagg_auto_scaling.py(2 hunks)tensorrt_llm/serve/openai_client.py(3 hunks)tensorrt_llm/serve/openai_disagg_server.py(5 hunks)tensorrt_llm/serve/perf_metrics.py(4 hunks)tests/integration/defs/examples/serve/test_serve_negative.py(2 hunks)tests/integration/test_lists/test-db/l0_dgx_h100.yml(1 hunks)tests/unittest/llmapi/apps/_test_openai_mmencoder.py(1 hunks)tests/unittest/llmapi/apps/openai_server.py(7 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
**/*.py: The code developed for TensorRT-LLM should conform to Python 3.8+
Indent Python code with 4 spaces; do not use tabs
Always maintain the namespace when importing in Python, even if only one class or function from a module is used (e.g., usefrom package.subpackage import fooand thenfoo.SomeClass()instead offrom package.subpackage.foo import SomeClass)
Python filenames should use snake_case (e.g.,some_file.py)
Python class names should use PascalCase (e.g.,class SomeClass)
Python function and method names should use snake_case (e.g.,def my_awesome_function():)
Python local variable names should use snake_case, with prefixkfor variable names that start with a number (e.g.,k_99th_percentile = ...)
Python global variables should use upper snake_case with prefixG(e.g.,G_MY_GLOBAL = ...)
Python constants should use upper snake_case (e.g.,MY_CONSTANT = ...)
Avoid shadowing variables declared in an outer scope in Python
Initialize all externally visible members of a Python class in the constructor
For Python interfaces that may be used outside a file, prefer docstrings over comments
Python comments should be reserved for code within a function, or interfaces that are local to a file
Use Google style docstrings for Python classes and functions, which can be parsed by Sphinx
Python attributes and variables can be documented inline with type and description (e.g.,self.x = 5followed by"""<type>: Description of 'x'""")
Avoid using reflection in Python when functionality can be easily achieved without reflection
When using try-except blocks in Python, limit the except clause to the smallest set of specific errors possible instead of catching all exceptions
When using try-except blocks in Python to handle multiple possible variable types (duck-typing), keep the body of the try as small as possible and use the else block to implement the logic
Files:
tensorrt_llm/llmapi/mpi_session.pytests/integration/defs/examples/serve/test_serve_negative.pytensorrt_llm/serve/openai_disagg_server.pytensorrt_llm/serve/disagg_auto_scaling.pytensorrt_llm/_utils.pytensorrt_llm/serve/openai_client.pytests/unittest/llmapi/apps/_test_openai_mmencoder.pytensorrt_llm/serve/perf_metrics.pytests/unittest/llmapi/apps/openai_server.py
**/*.{cpp,h,cu,py}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
All TensorRT-LLM Open Source Software code files should contain an NVIDIA copyright header that includes the current year at the top
Files:
tensorrt_llm/llmapi/mpi_session.pytests/integration/defs/examples/serve/test_serve_negative.pytensorrt_llm/serve/openai_disagg_server.pytensorrt_llm/serve/disagg_auto_scaling.pytensorrt_llm/_utils.pytensorrt_llm/serve/openai_client.pytests/unittest/llmapi/apps/_test_openai_mmencoder.pytensorrt_llm/serve/perf_metrics.pytests/unittest/llmapi/apps/openai_server.py
🧠 Learnings (6)
📓 Common learnings
Learnt from: Shixiaowei02
Repo: NVIDIA/TensorRT-LLM PR: 9582
File: tests/integration/defs/accuracy/test_disaggregated_serving.py:73-83
Timestamp: 2025-12-02T03:40:40.572Z
Learning: In the disaggregated serving tests (tests/integration/defs/accuracy/test_disaggregated_serving.py), calling get_free_port() multiple times in succession is acceptable because the tests run in a controlled single-process environment where race conditions for port allocation are not a concern.
📚 Learning: 2025-09-09T09:40:45.658Z
Learnt from: fredricz-20070104
Repo: NVIDIA/TensorRT-LLM PR: 7645
File: tests/integration/test_lists/qa/llm_function_core.txt:648-648
Timestamp: 2025-09-09T09:40:45.658Z
Learning: In TensorRT-LLM test lists, it's common and intentional for the same test to appear in multiple test list files when they serve different purposes (e.g., llm_function_core.txt for comprehensive core functionality testing and llm_function_core_sanity.txt for quick sanity checks). This duplication allows tests to be run in different testing contexts.
Applied to files:
tests/integration/test_lists/test-db/l0_dgx_h100.yml
📚 Learning: 2025-09-17T02:48:52.732Z
Learnt from: tongyuantongyu
Repo: NVIDIA/TensorRT-LLM PR: 7781
File: tests/integration/test_lists/waives.txt:313-313
Timestamp: 2025-09-17T02:48:52.732Z
Learning: In TensorRT-LLM, `tests/integration/test_lists/waives.txt` is specifically for waiving/skipping tests, while other test list files like those in `test-db/` and `qa/` directories are for different test execution contexts (pre-merge, post-merge, QA tests). The same test appearing in both waives.txt and execution list files is intentional - the test is part of test suites but will be skipped due to the waiver.
Applied to files:
tests/integration/test_lists/test-db/l0_dgx_h100.yml
📚 Learning: 2025-08-26T09:49:04.956Z
Learnt from: pengbowang-nv
Repo: NVIDIA/TensorRT-LLM PR: 7192
File: tests/integration/test_lists/test-db/l0_dgx_b200.yml:56-72
Timestamp: 2025-08-26T09:49:04.956Z
Learning: In TensorRT-LLM test configuration files, the test scheduling system handles wildcard matching with special rules that prevent duplicate test execution even when the same tests appear in multiple yaml files with overlapping GPU wildcards (e.g., "*b200*" and "*gb200*").
Applied to files:
tests/integration/test_lists/test-db/l0_dgx_h100.yml
📚 Learning: 2025-07-28T17:06:08.621Z
Learnt from: moraxu
Repo: NVIDIA/TensorRT-LLM PR: 6303
File: tests/integration/test_lists/qa/examples_test_list.txt:494-494
Timestamp: 2025-07-28T17:06:08.621Z
Learning: In TensorRT-LLM testing, it's common to have both CLI flow tests (test_cli_flow.py) and PyTorch API tests (test_llm_api_pytorch.py) for the same model. These serve different purposes: CLI flow tests validate the traditional command-line workflow, while PyTorch API tests validate the newer LLM API backend. Both are legitimate and should coexist.
Applied to files:
tests/integration/test_lists/test-db/l0_dgx_h100.yml
📚 Learning: 2025-12-02T03:40:40.572Z
Learnt from: Shixiaowei02
Repo: NVIDIA/TensorRT-LLM PR: 9582
File: tests/integration/defs/accuracy/test_disaggregated_serving.py:73-83
Timestamp: 2025-12-02T03:40:40.572Z
Learning: In the disaggregated serving tests (tests/integration/defs/accuracy/test_disaggregated_serving.py), calling get_free_port() multiple times in succession is acceptable because the tests run in a controlled single-process environment where race conditions for port allocation are not a concern.
Applied to files:
tensorrt_llm/llmapi/mpi_session.pytests/integration/defs/examples/serve/test_serve_negative.pytensorrt_llm/_utils.pytests/unittest/llmapi/apps/_test_openai_mmencoder.pytests/unittest/llmapi/apps/openai_server.py
🧬 Code graph analysis (7)
tests/integration/defs/examples/serve/test_serve_negative.py (1)
tensorrt_llm/_utils.py (1)
get_free_port(476-477)
tensorrt_llm/serve/openai_disagg_server.py (2)
tensorrt_llm/serve/responses_utils.py (1)
get_steady_clock_now_in_seconds(111-112)tensorrt_llm/logger.py (2)
error(126-127)info(138-139)
tensorrt_llm/serve/disagg_auto_scaling.py (2)
tensorrt_llm/llmapi/disagg_utils.py (2)
ServerRole(19-22)DisaggClusterConfig(59-64)tensorrt_llm/serve/cluster_storage.py (1)
ClusterStorage(60-106)
tensorrt_llm/serve/openai_client.py (2)
tensorrt_llm/serve/responses_utils.py (2)
get_steady_clock_now_in_seconds(111-112)on_first_token(1803-1807)tensorrt_llm/serve/openai_disagg_server.py (1)
on_first_token(70-73)
tests/unittest/llmapi/apps/_test_openai_mmencoder.py (1)
tensorrt_llm/_utils.py (1)
get_free_port(476-477)
tensorrt_llm/serve/perf_metrics.py (1)
tensorrt_llm/llmapi/disagg_utils.py (1)
ServerRole(19-22)
tests/unittest/llmapi/apps/openai_server.py (3)
tensorrt_llm/_utils.py (1)
get_free_port(476-477)tests/integration/defs/stress_test/stress_test.py (1)
url(91-93)tests/integration/defs/examples/serve/test_serve_negative.py (1)
url_for(35-36)
🪛 Ruff (0.14.7)
tensorrt_llm/llmapi/mpi_session.py
544-544: Unused function argument: num
(ARG001)
tensorrt_llm/serve/openai_disagg_server.py
63-63: Unused method argument: request
(ARG002)
tensorrt_llm/serve/disagg_auto_scaling.py
242-242: Mutable class attributes should be annotated with typing.ClassVar
(RUF012)
242-242: Possible binding to all interfaces
(S104)
263-263: Standard pseudo-random generators are not suitable for cryptographic purposes
(S311)
tensorrt_llm/serve/perf_metrics.py
113-113: Avoid specifying long messages outside the exception class
(TRY003)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Pre-commit Check
🔇 Additional comments (10)
tests/integration/test_lists/test-db/l0_dgx_h100.yml (1)
44-44: Verify if the test was added to both 2-GPU and 4-GPU sections as claimed in the AI summary.The review identifies a potential inconsistency: the AI summary states the test was added to "two pre-merge test groups (covering 2-GPU and 4-GPU configurations)", but only line 44 in the 2-GPU section is shown with a change annotation. Confirm whether the same test addition appears in the 4-GPU section (lines 49–111) as the summary implies. Additionally, verify that
unittest/llmapi/apps/test_disagg_serving_perf_metrics.pyexists as part of this PR.tensorrt_llm/serve/perf_metrics.py (2)
99-114: LGTM! Clean implementation of lazy metric factory.The
instance_metricfunction correctly:
- Lazily imports
prometheus_clientto avoid side effects withset_prometheus_multiproc_dir.- Handles role-based name prefixing appropriately.
- Creates the correct metric type based on the definition.
154-163: LGTM! Server metrics integration looks good.The
_metricsdictionary and__getattr__implementation provide clean dynamic access to server-side metrics, consistent with theClientMetricsCollectorpattern.tests/unittest/llmapi/apps/_test_openai_mmencoder.py (1)
27-30: LGTM! Correctly migrated to centralized port utility.The import change from
tensorrt_llm.llmapi.mpi_session.find_free_porttotensorrt_llm._utils.get_free_portaligns with the broader codebase shift toward centralized port-lookup utilities.tensorrt_llm/serve/openai_disagg_server.py (4)
54-64: LGTM! Queue latency instrumentation is well-implemented.The
RawRequestResponseHookscorrectly captures the request arrival time from middleware state and observes queue latency inon_req_begin. The unusedrequestparameter (flagged by static analysis ARG002) is intentional as it matches theResponseHooksinterface contract.
162-176: LGTM! Comprehensive request/response metrics instrumentation.The metrics coverage is thorough:
total_requests,stream_requests,nonstream_requestsat entry.total_responseson successful completion.- Error counters delegated to
_handle_exception.
178-189: LGTM! Error metrics categorization is appropriate.The exception handler correctly categorizes and counts:
http_exceptionsforHTTPException.internal_errorsfor other exceptions.validation_exceptionshandled separately in the validation exception handler (line 136).
209-210: LGTM! Useful startup logging added.The server startup log message with host and port information aids debugging and operational visibility.
tests/integration/defs/examples/serve/test_serve_negative.py (1)
21-21: Centralizedget_free_portusage in tests looks goodImporting and using
tensorrt_llm._utils.get_free_port()in the server fixture keeps port handling consistent with the rest of the test suite. In a single-process integration test like this, the race window for free-port selection is acceptable and aligns with the existing disaggregated-serving tests that use the same helper.Also applies to: 61-61
tests/unittest/llmapi/apps/openai_server.py (1)
14-15: Helper updates for ports, logging, and disagg config look solid
- Switching both helpers to
tensorrt_llm._utils.get_free_port()for default ports aligns them with the centralized port utilities; for these single-process unittest helpers the free-port pattern is appropriate, and matches the existing disaggregated-serving tests’ usage.- The new
log_path/_get_outputmechanism cleanly routes subprocess stdout/stderr either to a shared log file or to stdout, andterminate()now properly closes the log file to avoid descriptor leaks.RemoteOpenAIServer.wait_for_server()provides a simple way to delay readiness checks whenwait=Falseis used in tests.- For
RemoteDisaggOpenAIServer, accepting adisagg_configdict and dumping it viayaml.dumpinto a temp file is clearer than working with pre-serialized YAML, and the added logging support mirrors the non-disaggregated helper.Overall, these changes make the test harness more flexible and observable without altering its core semantics.
Also applies to: 21-34, 37-39, 57-60, 62-69, 92-95, 143-159, 162-163, 175-176, 181-192
ea07f68 to
32a5878
Compare
|
/bot run |
|
PR_Github #27092 [ run ] triggered by Bot. Commit: |
|
PR_Github #27092 [ run ] completed with state |
|
/bot run --disable-fail-fast |
|
PR_Github #27111 [ run ] triggered by Bot. Commit: |
|
PR_Github #27111 [ run ] completed with state |
63301ce to
67f5207
Compare
pcastonguay
left a comment
There was a problem hiding this comment.
Thanks Lizhi, lgtm.
|
bot run --disable-fail-fast |
|
/bot run --disable-fail-fast |
|
PR_Github #27394 [ run ] triggered by Bot. Commit: |
|
PR_Github #28111 [ run ] completed with state |
3793303 to
eecbbf7
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #28185 [ run ] triggered by Bot. Commit: |
|
PR_Github #28185 [ run ] completed with state |
eecbbf7 to
9b86ed4
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #28246 [ run ] triggered by Bot. Commit: |
|
PR_Github #28246 [ run ] completed with state |
Signed-off-by: Lizhi Zhou <[email protected]>
Signed-off-by: Lizhi Zhou <[email protected]>
9b86ed4 to
db541b1
Compare
|
/bot run --disable-fail-fast --disable-reuse-test |
|
PR_Github #28307 [ run ] triggered by Bot. Commit: |
|
PR_Github #28307 [ run ] completed with state |
|
/bot run --disable-fail-fast |
|
PR_Github #28404 [ run ] triggered by Bot. Commit: |
|
PR_Github #28404 [ run ] completed with state |
|
/bot run --disable-fail-fast |
1 similar comment
|
/bot run --disable-fail-fast |
|
PR_Github #28538 [ run ] triggered by Bot. Commit: |
|
PR_Github #28538 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #28569 [ run ] triggered by Bot. Commit: |
|
PR_Github #28569 [ run ] completed with state |
…nize workers' clocks when workers are dynamic (NVIDIA#9726) Signed-off-by: Lizhi Zhou <[email protected]>
…nize workers' clocks when workers are dynamic (NVIDIA#9726) Signed-off-by: Lizhi Zhou <[email protected]>
get_free_portandwait_for_endpoint_readyOpenAIMMEncoderfromtests/unittest/llmapi/apps/_test_openai_mmencoder.pytotests/unittest/llmapi/apps/openai_server.pyand fix its API a little bit .Summary by CodeRabbit
New Features
Refactor
Tests
✏️ Tip: You can customize this high-level summary in your review settings.
Description
Test Coverage
PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...Provide a user friendly way for developers to interact with a Jenkins server.
Run
/bot [-h|--help]to print this help message.See details below for each supported subcommand.
Details
run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]Launch build/test pipelines. All previously running jobs will be killed.
--reuse-test (optional)pipeline-id(OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.--disable-reuse-test(OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.--disable-fail-fast(OPTIONAL) : Disable fail fast on build/tests/infra failures.--skip-test(OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.--stage-list "A10-PyTorch-1, xxx"(OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.--gpu-type "A30, H100_PCIe"(OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.--test-backend "pytorch, cpp"(OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.--only-multi-gpu-test(OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.--disable-multi-gpu-test(OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.--add-multi-gpu-test(OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.--post-merge(OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx"(OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".--detailed-log(OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.--debug(OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in thestage-listparameter to access the appropriate container environment. Note: Does NOT update GitHub check status.For guidance on mapping tests to stage names, see
docs/source/reference/ci-overview.mdand the
scripts/test_to_stage_mapping.pyhelper.kill
killKill all running builds associated with pull request.
skip
skip --comment COMMENTSkip testing for latest commit on pull request.
--comment "Reason for skipping build/test"is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.reuse-pipeline
reuse-pipelineReuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.