When you profile a live Python application in production, the biggest worry is usually not whether you can pinpoint the problem, but whether the profiling tool itself will drag down your production service. We measured the overhead of OpenResty XRay on a live gunicorn (WSGI) application in production mode: during active sampling, maximum throughput dropped by only 3.4% and average latency rose by just 0.16 ms, while the Agent’s overhead is exactly zero when idle. This is possible because, unlike always-on APM agents, it performs no code injection or modification on the target process and only collects data — at low frequency — when a user explicitly starts an analysis; the sections below use point-by-point benchmark data to show its real impact on CPU, memory, and load, as well as on throughput and latency. For the full walkthrough, see the video version at the top of this article.

Test Environment and Performance Baseline

To establish a baseline for comparison, we captured system metrics using the top command before starting the analyzer. As shown below, the target gunicorn process (a Python application) had a CPU usage of approximately 46.5%. The system’s one-minute load average was 0.7, the CPU idle percentage was approximately 87.2%, and available memory was approximately 2632 MB.

gunicorn process baseline

gunicorn 进程基线

What Happens to CPU, Memory, and Load During Profiling?

To replicate a real-world diagnostic scenario, we used the OpenResty XRay console to launch a 300-second (5-minute) “High CPU usage” analysis against the Python process in production mode (path: Guided Analysis → High CPU usage → select target process).

Analysis in progress, lasting 300 seconds

Selecting “production mode” is critical, as it is specifically designed for live production environments. Through optimizations such as low-frequency sampling, it minimizes performance impact — though this also means analysis runs may take longer.

During the analysis, we observed the following minor changes across system metrics:

  • Target process CPU usage: Increased to ~48%, up approximately 1.5 percentage points from the baseline.
  • One-minute load average: Rose to 0.84, an increase of 0.14 over the baseline of 0.7.
  • CPU idle percentage: Dropped to ~86.7%, nearly identical to the baseline of 87.2%.
  • Available memory: Held steady at ~2631 MB, a decrease of roughly 1 MB — no meaningful change.

System metrics during analyzer operation

System metrics during analyzer operation

In summary, while OpenResty XRay does introduce some measurable impact on system-level resources (CPU, memory, and load) during active profiling, the magnitude is negligible and poses no threat to system stability.

How Much Does Profiling Affect Throughput and Latency?

For production services, throughput and latency are the defining measures of performance. We ran three sets of comparative benchmarks covering both of these core metrics. The table below summarizes the results across all three scenarios:

ScenarioMax throughputAvg latency
OpenResty XRay Agent not installed~2,300 RPS4.32 ms
Agent installed, profiler idle~2,300 RPS (unchanged)4.32 ms (unchanged)
Profiler actively sampling~2,220 RPS (−3.4%)4.48 ms (+0.16 ms)

1. Maximum Throughput

We used a load testing tool to measure the server’s maximum throughput across different configurations.

  • With the OpenResty XRay Agent not installed, maximum throughput is approximately 2,300 requests per second.
  • With the Agent installed but the profiler not running, maximum throughput remains unchanged.
  • With the profiler actively sampling, maximum throughput is approximately 2,220 RPS — only 3.4% lower than the baseline without sampling.

To summarize: with the profiler running, maximum throughput sits at approximately 2,220 requests per second, just 3.4% below the no-sampling baseline.

Throughput with profiler running

2. Average Request Latency

We measured how profiler sampling affects request latency.

  • With the OpenResty XRay Agent not installed, average request latency is 4.32 ms.
  • With the Agent installed but the profiler not running, average request latency is unchanged.
  • With the profiler running, request latency increases to 4.48 ms — an added overhead of just 0.16 ms.

Request latency with profiler running

Conclusion

Across all three dimensions — system resource consumption, application throughput, and request latency — the data confirms that OpenResty XRay’s dynamic tracing architecture delivers measurable, predictable overhead when performing real-time diagnostics on production Python applications, with negligible impact on core business metrics. This makes it a profiling tool that can be safely and continuously deployed in production environments without hesitation.

The overhead introduced by automatic analysis on the Insights and Dashboard pages is equally minimal.

Insights and Dashboard pages

If your Python process is stuck at low CPU usage with poor throughput, see how off-CPU analysis traced a blocking subprocess.run call: off-CPU analysis of Python applications. We ran the same production-mode overhead measurement on other languages as well — see the results for Go, Rust, PHP, and Perl applications.

OpenResty XRay vs. Always-On APM Agents

The reason the overhead stays this low is architectural. Traditional APM agents inject code into the target process and collect data continuously, so they impose runtime overhead at all times — whether or not anyone is looking. OpenResty XRay takes the opposite approach: it is non-intrusive and samples only on demand.

Traditional always-on APM agentOpenResty XRay
Data collectionContinuous, always onOn demand, only during a user-initiated analysis
Target processCode injection / instrumentationNon-intrusive, no code modification
Overhead when idlePersistentExactly zero
Overhead while samplingPersistent~3.4% throughput, +0.16 ms latency

FAQ

How much performance overhead does OpenResty XRay add to a production Python application?

During active analysis, OpenResty XRay lowers maximum throughput by about 3.4% (from ~2,300 to ~2,220 requests per second) and adds about 0.16 ms of average latency (from 4.32 ms to 4.48 ms). When the Agent is installed but not actively sampling, throughput and latency are unchanged, and when it is idle the overhead is exactly zero.

Is OpenResty XRay safe to run on a production gunicorn or Django app?

Yes. The OpenResty XRay Agent is non-intrusive — it performs no code injection or modification on the target process and only collects data when you explicitly start an analysis, at a low sampling frequency. During a 300-second production-mode analysis of a live gunicorn process, the one-minute load average rose only from 0.7 to 0.84 and target-process CPU from 46.5% to about 48%, so it can be deployed continuously in production.

Does OpenResty XRay slow down my Python app when it is not actively analyzing?

No. The Agent only collects data while a user-initiated analysis is running. When it is installed but idle, maximum throughput and request latency are identical to having no Agent at all — the performance overhead is exactly zero.

How does OpenResty XRay’s overhead compare to a traditional always-on APM agent?

Traditional APM agents inject code into the target process and run continuously, imposing overhead at all times. OpenResty XRay instead samples on demand at a low frequency, so it adds zero overhead when idle and only about 3.4% throughput impact while actively profiling.

How much CPU and memory does OpenResty XRay use while profiling a Python process?

While sampling the gunicorn process, target-process CPU usage rose from a baseline of 46.5% to about 48% (roughly 1.5 percentage points), CPU idle dropped only from 87.2% to 86.7%, and available memory held steady at about 2631 MB — a change of roughly 1 MB.

What is OpenResty XRay

OpenResty XRay is a dynamic-tracing product that automatically analyzes your running applications to troubleshoot performance problems, behavioral issues, and security vulnerabilities with actionable suggestions. Under the hood, OpenResty XRay is powered by our Y language targeting various runtimes like Stap+, eBPF+, GDB, and ODB, depending on the contexts.

If you like this tutorial, please subscribe to this blog site and/or our YouTube channel. Thank you!

About The Author

Yichun Zhang (Github handle: agentzh), is the original creator of the OpenResty® open-source project and the CEO of OpenResty Inc..

Yichun is one of the earliest advocates and leaders of “open-source technology”. He worked at many internationally renowned tech companies, such as Cloudflare, Yahoo!. He is a pioneer of “edge computing”, “dynamic tracing” and “machine coding”, with over 22 years of programming and 16 years of open source experience. Yichun is well-known in the open-source space as the project leader of OpenResty®, adopted by more than 40 million global website domains.

OpenResty Inc., the enterprise software start-up founded by Yichun in 2017, has customers from some of the biggest companies in the world. Its flagship product, OpenResty XRay, is a non-invasive profiling and troubleshooting tool that significantly enhances and utilizes dynamic tracing technology. And its OpenResty Edge product is a powerful distributed traffic management and private CDN software product.

As an avid open-source contributor, Yichun has contributed more than a million lines of code to numerous open-source projects, including Linux kernel, Nginx, LuaJIT, GDB, SystemTap, LLVM, Perl, etc. He has also authored more than 60 open-source software libraries.