Skip to content

use cached contexts for access logs in request path#55166

Merged
zcin merged 10 commits into
masterfrom
abrar-logging-context
Aug 7, 2025
Merged

use cached contexts for access logs in request path#55166
zcin merged 10 commits into
masterfrom
abrar-logging-context

Conversation

@abrarsheikh

@abrarsheikh abrarsheikh commented Aug 2, 2025

Copy link
Copy Markdown
Contributor

Performance Comparison Table

Metric GET / (Before) GET / (After) Aggregated (Before) Aggregated (After)
# Requests 27,390 284,097 27,390 284,097
# Fails 0 0 0 0
Median (ms) 450 400 450 400
95%ile (ms) 520 520 520 520
99%ile (ms) 540 570 540 570
Average (ms) 451.13 400.84 451.13 400.84
Min (ms) 226 160 226 160
Max (ms) 728 777 728 777
Average size (bytes) 13 13 13 13
Current RPS 220.5 256.8 220.5 256.8
Current Failures/s 0 0 0 0
Signed-off-by: abrar <abrar@anyscale.com>
Signed-off-by: abrar <abrar@anyscale.com>
@abrarsheikh abrarsheikh changed the base branch from master to abrar-logging-opt August 2, 2025 03:57

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Summary of Changes

Hello @abrarsheikh, 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 optimizing the logging mechanism within Ray Serve, particularly for access logs. It introduces a strategy to pre-compute and cache common logging context attributes at the proxy and replica levels, reducing the overhead of dynamically gathering this information for each log entry. This change also includes a performance improvement for JSON log serialization and refactors how core Ray context is added to logs.

Highlights

  • Optimized Access Logging: I've implemented a strategy to pre-compute and cache common Ray core and Serve-specific context attributes (such as job ID, worker ID, component type, etc.) for access logs within Serve proxies and replicas. This significantly reduces the overhead of dynamically gathering this information for each log entry, as it avoids expensive runtime lookups.
  • Logging Filter Bypass Mechanism: A new skip_context_filter mechanism has been introduced. This allows log records that have already been pre-populated with context to bypass certain context-enriching logging filters, preventing redundant processing and improving efficiency.
  • Faster JSON Serialization: For JSON log formatting, I've switched the underlying serialization library from Python's built-in json module to orjson. orjson is known for its higher performance, which will lead to faster log processing.
  • Refactored Core Context Retrieval: The logic for retrieving Ray core logging context has been centralized into a reusable class method within CoreContextFilter. This improves code organization and reusability across different logging components.
  • Streamlined Replica Logging: Redundant 'started executing request' log messages have been removed from Serve replicas. The new optimized access logging mechanism now provides sufficient detail, making these previous logs unnecessary.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 or fill out our survey to provide feedback.

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.

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

Copy link
Copy Markdown
Contributor

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 introduces an optimization for access logging by caching the logging context. The changes are well-structured and the main idea is sound. However, I've identified a few issues:

  1. The implementation for non-JSON (i.e., TEXT) formatted logs is incorrect, which would lead to missing context information in access logs for both proxies and replicas.
  2. The application_name is missing from the proxy's access logs.
  3. There's some repetitive code in the logging filters that could be refactored for better maintainability.
Comment thread python/ray/serve/_private/proxy.py
Comment thread python/ray/serve/_private/replica.py
Comment thread python/ray/serve/_private/proxy.py
Comment thread python/ray/serve/_private/proxy.py
Comment thread python/ray/serve/_private/logging_utils.py Outdated
@abrarsheikh abrarsheikh changed the base branch from abrar-logging-opt to master August 4, 2025 20:09
Signed-off-by: abrar <abrar@anyscale.com>
Signed-off-by: abrar <abrar@anyscale.com>
@abrarsheikh abrarsheikh added the go add ONLY when ready to merge, run all tests label Aug 4, 2025
@abrarsheikh abrarsheikh marked this pull request as ready for review August 5, 2025 01:03
@abrarsheikh abrarsheikh requested review from a team as code owners August 5, 2025 01:03

@can-anyscale can-anyscale left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm for core part

Comment thread python/ray/_private/ray_logging/filters.py
Comment thread python/ray/serve/_private/replica.py Outdated
Comment thread python/ray/serve/_private/replica.py
Comment thread python/ray/serve/_private/replica.py Outdated
Comment thread python/ray/serve/_private/logging_utils.py Outdated
Comment thread python/ray/serve/_private/proxy.py
Comment thread python/ray/serve/_private/replica.py
Signed-off-by: abrar <abrar@anyscale.com>
Comment thread python/ray/serve/_private/logging_utils.py Outdated

@ok-scale ok-scale left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: abrar <abrar@anyscale.com>
Signed-off-by: abrar <abrar@anyscale.com>
Comment thread python/ray/serve/_private/replica.py
Comment thread python/ray/serve/_private/proxy.py Outdated
Comment thread python/ray/serve/_private/proxy.py
Signed-off-by: abrar <abrar@anyscale.com>
@zcin zcin enabled auto-merge (squash) August 7, 2025 19:46
@zcin zcin requested a review from can-anyscale August 7, 2025 19:47
@zcin

zcin commented Aug 7, 2025

Copy link
Copy Markdown
Contributor

@can-anyscale could you help stamp as core codeowner?

@can-anyscale can-anyscale left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@zcin zcin merged commit e340530 into master Aug 7, 2025
6 checks passed
@zcin zcin deleted the abrar-logging-context branch August 7, 2025 20:07
dioptre pushed a commit to sourcetable/ray that referenced this pull request Aug 20, 2025
### Performance Comparison Table

| Metric | GET / (Before) | GET / (After) | Aggregated (Before) |
Aggregated (After) |

|--------------------------|----------------|----------------|----------------------|---------------------|
| # Requests | 27,390 | 284,097 | 27,390 | 284,097 |
| # Fails | 0 | 0 | 0 | 0 |
| Median (ms) | 450 | 400 | 450 | 400 |
| 95%ile (ms) | 520 | 520 | 520 | 520 |
| 99%ile (ms) | 540 | 570 | 540 | 570 |
| Average (ms) | 451.13 | 400.84 | 451.13 | 400.84 |
| Min (ms) | 226 | 160 | 226 | 160 |
| Max (ms) | 728 | 777 | 728 | 777 |
| Average size (bytes) | 13 | 13 | 13 | 13 |
| Current RPS | 220.5 | 256.8 | 220.5 | 256.8 |
| Current Failures/s | 0 | 0 | 0 | 0 |

---------

Signed-off-by: abrar <abrar@anyscale.com>
Signed-off-by: Andrew Grosser <dioptre@gmail.com>
jugalshah291 pushed a commit to jugalshah291/ray_fork that referenced this pull request Sep 11, 2025
### Performance Comparison Table

| Metric | GET / (Before) | GET / (After) | Aggregated (Before) |
Aggregated (After) |

|--------------------------|----------------|----------------|----------------------|---------------------|
| # Requests | 27,390 | 284,097 | 27,390 | 284,097 |
| # Fails | 0 | 0 | 0 | 0 |
| Median (ms) | 450 | 400 | 450 | 400 |
| 95%ile (ms) | 520 | 520 | 520 | 520 |
| 99%ile (ms) | 540 | 570 | 540 | 570 |
| Average (ms) | 451.13 | 400.84 | 451.13 | 400.84 |
| Min (ms) | 226 | 160 | 226 | 160 |
| Max (ms) | 728 | 777 | 728 | 777 |
| Average size (bytes) | 13 | 13 | 13 | 13 |
| Current RPS | 220.5 | 256.8 | 220.5 | 256.8 |
| Current Failures/s | 0 | 0 | 0 | 0 |

---------

Signed-off-by: abrar <abrar@anyscale.com>
Signed-off-by: jugalshah291 <shah.jugal291@gmail.com>
dstrodtman pushed a commit to dstrodtman/ray that referenced this pull request Oct 6, 2025
### Performance Comparison Table

| Metric | GET / (Before) | GET / (After) | Aggregated (Before) |
Aggregated (After) |

|--------------------------|----------------|----------------|----------------------|---------------------|
| # Requests | 27,390 | 284,097 | 27,390 | 284,097 |
| # Fails | 0 | 0 | 0 | 0 |
| Median (ms) | 450 | 400 | 450 | 400 |
| 95%ile (ms) | 520 | 520 | 520 | 520 |
| 99%ile (ms) | 540 | 570 | 540 | 570 |
| Average (ms) | 451.13 | 400.84 | 451.13 | 400.84 |
| Min (ms) | 226 | 160 | 226 | 160 |
| Max (ms) | 728 | 777 | 728 | 777 |
| Average size (bytes) | 13 | 13 | 13 | 13 |
| Current RPS | 220.5 | 256.8 | 220.5 | 256.8 |
| Current Failures/s | 0 | 0 | 0 | 0 |

---------

Signed-off-by: abrar <abrar@anyscale.com>
Signed-off-by: Douglas Strodtman <douglas@anyscale.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests

6 participants