Analyzer lj-slowest-str-match-find

Name

lj-slowest-str-match-find - Slowest String Match/Find

This analyzer identifies the slowest string matching and finding operations in Lua code within LuaJIT-based applications such as OpenResty and Kong. It captures execution time for string.match and string.find function calls, aggregating statistics on patterns that cause performance degradation. The analyzer outputs histogram and bar chart visualizations showing the most time-consuming string operations, helping developers optimize pattern matching logic and reduce CPU overhead in string processing.

Resource Category

CPU.

Application Type & Technical Stack

  • OpenResty
  • Kong
  • APISIX

Command Line Syntax

The analyzer can be invoked directly on the command-line via the orxray utility from the openresty-xray-cli software package.

Alternatively, the analyzer can also be invoked manually or automatically on the web console UI of OpenResty XRay (like on the Advanced web page).

# PID is the target process PID.
orxray analyzer run lj-slowest-str-match-find -p PID

# trace a shell command directly
orxray analyzer run lj-slowest-str-match-find -c SHELL_CMD

# PGID is the process group ID or any process's PID within the target process
# group.
orxray analyzer run lj-slowest-str-match-find -p -PGID

# trace any processes started from the specified executable path.
orxray analyzer run lj-slowest-str-match-find --exe /path/to/exe/file

Tracing Multiple Processes

Supported.

Output Formats

  • Bar Charts
  • Histogram Bar Charts
  • Plain Texts

Output Example

{
  "distributions": {
    "find_latencies": [
      {"count": 0, "key": "512"},
      {"count": 0, "key": "1024"},
      {"count": 1, "key": "2048"},
      {"count": 2, "key": "4096"},
      {"count": 1, "key": "8192"},
      {"count": 0, "key": "16384"},
      {"count": 0, "key": "32768"}
    ]
  },
  "unit": "ns",
  "find_summary": {
    "find_top": {
      "min": 4002,
      "max": 11814,
      "count": 4,
      "sum": 24709,
      "avg": 6177
    }
  }
}

Author

The OpenResty Inc. Team.

Copyright (C) by OpenResty Inc. All rights reserved.