Perl High CPU Usage: 100% CPU Traced to a Regex Hotspot with Flame Graphs
When a Perl process pins a CPU core at 100%, the cause is usually buried in a hot code path. We profiled a live, unmodified Perl process with OpenResty XRay and traced the CPU usage to regex matching inside Services::Processor::scan (line 14, Dancer2 framework) — specifically the Perl_fbm_instr C function that implements Fast Boyer-Moore string search.
This walkthrough shows the complete profiling process — from observing the Perl high CPU usage to pinpointing the exact source file and line number responsible.
Observing 100% CPU Usage in a Perl Process
The top command shows a Perl process consuming 100% of a CPU core.
The ps command confirms this is the standard Perl binary executable shipped with the Linux distribution.
Profiling Perl CPU Usage with OpenResty XRay
We use OpenResty XRay to analyze this unmodified process in real time — no code changes, no restarts required. In the web console, navigate to Guided Analysis and select High CPU Usage as the problem type. OpenResty XRay auto-discovers running applications on the target machine. Select the Perl application from the dropdown.
Select the specific process consuming 99% CPU — the same one we observed in top.
OpenResty XRay can analyze multiple language levels at the same time. We keep both Perl and C selected.
After starting the analysis, the system keeps performing different rounds of analysis. Two rounds are enough for this case.
C-Level CPU Flame Graph Analysis
We can see it automatically creates a report.
This is the hottest C code path for CPU.
This is a C function named Perl_fbm_instr in the Perl VM runtime. It uses the FBM (Fast Boyer-Moore) algorithm to search strings for regular expression matching.
The C function here indicates that it is indeed performing regular expression matching.
The perl_run function means that the Perl VM is currently executing Perl code.
Perl-Level CPU Flame Graph Analysis
After checking the hottest C code path, we then look at the hottest Perl code paths.
This C function is still Perl_fbm_instr we just discussed.
This is a Perl function named scan. It is part of the business logic and it’s in the Services::Processor package.
These two caller Perl functions give more context in the business-level code base.
And this Perl function belongs to the Dancer2 Perl web framework.
This is the second hottest Perl code path.
The only difference is this Glibc function, memchr. It searches a character in a memory buffer using the Intel AVX2 instruction set. It is also part of the regular expression matching operation. The Perl function call chain is exactly the same.
Pinpointing the Perl Source File and Line Number
Click “More” to see details about the #1 hottest Perl code path.
The code path was automatically derived from this Perl-land CPU flame graph.
Below are more detailed explanations and suggestions regarding the current issue.
It talks about the Perl_fbm_instr C function we saw earlier.
It mentions that this function uses the “Fast Boyer-Moore” string search algorithm.
And it also covers the Perl function scan.
It mentions that this function is in the Services::Processor package.
Hover the mouse over the green box for the Perl function named scan. We can see the Perl source file of the scan function, and its full path for the Processor.pm file in the tooltip.
The Perl source line number is 14.
Click the icon to copy the full Perl source file path for this function.
Use the vim editor and paste the file path we just copied to look at the corresponding business Perl code. You can use any editor you like.
Go to line 14 as shown in the report tooltip.
We see that this Perl code line is indeed doing regular expression matching.
It is also in the function scan as shown in the report.
Automatic Monitoring and Reports
For production workloads, OpenResty XRay monitors processes continuously and generates daily and weekly reports on the Insights page — no manual guided analysis required.
FAQ
Why is my Perl process using 100% CPU?
A common cause of Perl high CPU usage is an expensive regex operation in a hot code path. In this case, OpenResty XRay traced the CPU bottleneck to Perl_fbm_instr — the C function implementing Fast Boyer-Moore string search for regex matching — called from Services::Processor::scan at line 14. CPU flame graphs reveal the full call chain from the Dancer2 framework down to the VM-level regex function.
How do I find the Perl code causing high CPU?
Use OpenResty XRay’s guided analysis to generate CPU flame graphs at both the C and Perl levels. The flame graph shows stacked function calls where width represents CPU time. Hover over a function box to see the source file path and line number, then open that file in any editor to inspect the exact code responsible.
Can regex patterns cause high CPU in Perl?
Yes. The Perl VM function Perl_fbm_instr implements Fast Boyer-Moore string search for regex matching, and it was the dominant CPU consumer in this case — appearing as the leaf function in both the #1 and #2 hottest C-land code paths. The associated memchr glibc function (using Intel AVX2 instructions) also contributed to the regex workload.
What is a CPU flame graph for Perl?
A CPU flame graph is a visualization of stacked function calls where the width of each box represents relative CPU time. OpenResty XRay generates both C-level and Perl-level CPU flame graphs, making it possible to trace CPU hotspots from the Perl VM internals (like Perl_fbm_instr) down to the exact Perl source file and line number.
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.


















































