Skip to content

refactor: clean up logging and add system status reporter#1204

Open
sufubao wants to merge 3 commits intomainfrom
clean_log
Open

refactor: clean up logging and add system status reporter#1204
sufubao wants to merge 3 commits intomainfrom
clean_log

Conversation

@sufubao
Copy link
Collaborator

@sufubao sufubao commented Feb 6, 2026

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @sufubao, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request primarily focuses on enhancing the observability and reducing log verbosity within the LightLLM system. By demoting detailed per-request logs to a debug level and introducing a comprehensive SystemStatusReporter, the changes aim to provide a clearer, more actionable view of the system's performance and state without overwhelming users with excessive information. Additionally, improvements to CUDA graph capture feedback and autotuner log formatting contribute to a more user-friendly development and operational experience.

Highlights

  • Logging Level Adjustment: Per-request log messages across router, detokenization, and HTTP server components have been demoted from "info" to "debug" to significantly reduce log noise in production environments.
  • System Status Reporting: The legacy Stats class has been replaced by a new SystemStatusReporter that provides a single, periodic status line. This line includes key metrics such as throughput (input/output tokens per second), counts of running, waiting, and paused requests, KV cache utilization, prefix cache hit rate, and MTP acceptance length.
  • Default Log Level Change: The default log level for LightLLM has been elevated from debug to info, ensuring a cleaner default output.
  • CUDA Graph Capture Enhancement: Progress bars, including real-time memory utilization information, have been added to the CUDA graph capture process for better visibility and user feedback.
  • Autotuner Log Readability: Autotuner logs now convert frozenset keys to dict() before printing, improving the readability of cached configuration information.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • lightllm/common/basemodel/cuda_graph.py
    • Added tqdm import for progress bars.
    • Integrated tqdm progress bars into warmup and warmup_overlap functions for CUDA graph capture.
    • Enhanced progress bar descriptions to include current batch size and available GPU memory in GB.
  • lightllm/common/triton_utils/autotuner.py
    • Modified logging statements to cast static_key (a frozenset) to dict() for improved readability when logging cached configurations.
  • lightllm/server/detokenization/manager.py
    • Changed log level for "detokenization recv req id" and "detoken release req id" messages from info to debug.
  • lightllm/server/httpserver/manager.py
    • Changed log level for "recieved req", "first_token_cost", and "left req id" messages from info to debug.
  • lightllm/server/router/batch.py
    • Changed log level for "router release req id" messages from info to debug.
  • lightllm/server/router/manager.py
    • Imported SystemStatusReporter and removed log_time_ready.
    • Initialized self.status_reporter to None and instantiated it after req_queue setup.
    • Updated loop_for_fwd to use status_reporter for output token counting and periodic status printing, replacing old token ratio debug logs.
    • Added status_reporter.count_prompt_tokens call in _add_batch.
    • Implemented status_reporter.on_request_completed for finished requests in _filter_reqs_from_running_batch.
    • Changed log level for "router recive req id" messages from info to debug.
  • lightllm/server/router/stats.py
    • Renamed Stats class to SystemStatusReporter.
    • Refactored the class to track prompt/output tokens and global request completion statistics (input, cache, MTP accepted).
    • Introduced count_prompt_tokens, count_output_tokens, and on_request_completed methods.
    • Implemented maybe_print to generate a comprehensive, periodic status log line with throughput, request states, KV cache utilization, prefix cache hit rate, and MTP acceptance length.
    • Switched to init_system_status_logger for logging.
  • lightllm/utils/log_utils.py
    • Added _STATUS_FORMAT for the new system status logger.
    • Changed the default LIGHTLLM_LOG_LEVEL environment variable fallback from debug to info.
    • Introduced init_system_status_logger to create a dedicated logger for system status, configured with INFO level and a concise format.
Activity
  • There is no explicit activity (comments, reviews, approvals, etc.) recorded in the provided context for this pull request.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request significantly improves the logging and system monitoring capabilities. It introduces a SystemStatusReporter that provides a clean, consolidated, and informative view of the system's state, replacing scattered debug logs. The change of many INFO level logs to DEBUG and setting the default log level to INFO is a good practice for production environments. Additionally, the introduction of a progress bar for CUDA graph capturing is a nice user experience enhancement.

My review includes a suggestion to fix a bug in metric reporting where a value was being overwritten in a loop, and another suggestion to improve the design of the new SystemStatusReporter by simplifying its method signatures for better maintainability. Overall, this is a high-quality refactoring.

Comment on lines 250 to 252
for dp_index in range(self.dp_size_in_node):
token_ratio1 = self.get_used_tokens(dp_index) / self.max_total_token_num
token_ratio2 = (
self.max_total_token_num
- self.read_only_statics_mem_manager.get_unrefed_token_num(dp_index)
) / self.max_total_token_num
d_i = dp_index
frozen_token_num = self.shared_token_load.get_frozened_token_count(d_i)
estimated_peak_token_count = self.shared_token_load.get_estimated_peak_token_count(d_i)
paused_req_num = self._get_paused_req_num_in_dp_index(dp_index=d_i)
logger.debug(
f"dp_i {d_i} current batch size: {len(self.running_batch.reqs)} \n"
f"dp_i {d_i} paused req num: {paused_req_num} \n"
f"dp_i {d_i} frozen token num: {frozen_token_num} \n"
f"dp_i {d_i} estimated_peak_token_count: {estimated_peak_token_count} \n"
f"dp_i {d_i} token used ratio: {token_ratio1} not contain prompt cache tree unrefed token\n"
f"dp_i {d_i} token used ratio: {token_ratio2} contain prompt cache tree unrefed token"
)
paused_req_num = self._get_paused_req_num_in_dp_index(dp_index=dp_index)
self.metric_client.gauge_set("lightllm_batch_pause_size", paused_req_num)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The loop over dp_index repeatedly overwrites the lightllm_batch_pause_size metric. This means only the value for the last dp_index is actually reported, which is likely not the intended behavior.

If the goal is to report the total number of paused requests across all data-parallel ranks, you should calculate the total and set the metric once. You can reuse the existing _get_paused_req_num() method for this, which already calculates the total.

                    paused_req_num = self._get_paused_req_num()
                    self.metric_client.gauge_set("lightllm_batch_pause_size", paused_req_num)

Comment on lines +39 to +47
def maybe_print(
self,
running_batch,
req_queue,
read_only_statics_mem_manager,
paused_req_num=0,
radix_cache_client=None,
disable_dynamic_prompt_cache=False,
):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The maybe_print method has a large number of parameters. Many of these, such as req_queue, read_only_statics_mem_manager, radix_cache_client, and disable_dynamic_prompt_cache, are available when SystemStatusReporter is initialized and seem to be constant throughout its lifetime.

To improve code clarity and maintainability, consider moving these stable dependencies to the __init__ method. This simplifies the maybe_print signature and makes the dependencies of SystemStatusReporter more explicit.

For example, you could modify __init__ to accept these objects and store them as instance attributes. Then maybe_print would only need the parameters that change on each call, like running_batch and paused_req_num.

- Fix typo 'recive' -> 'receive' in router manager
- Uppercase 'mtp' -> 'MTP' in status line for consistency
- Only show MTP metric when MTP is actually active
- Remove dead code: log_time_ready and unused time import
- Add file handler to status logger when LIGHTLLM_LOG_DIR is set
- Warn when log_stats_interval is below 5s minimum
The loop over dp_index was repeatedly overwriting the same
lightllm_batch_pause_size metric, so only the last dp_index value
was reported. Use _get_paused_req_num() which sums across all dp
indices.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant