Analyzer lj-alloc-stats
Name
lj-alloc-stats - Statistics for LuaJIT’s builtin Allocator (Directly allocated memory blocks larger than 128K will not be counted)
This analyzer monitors memory allocation patterns in LuaJIT’s built-in allocator within OpenResty and Kong applications. It captures three types of allocation data:
- ‘used’ - currently allocated memory blocks (up to ~512KB)
- ‘free’ - freed memory blocks available for reuse (up to ~6MB)
- ‘segments’ - large memory segments allocated from system (128KB+) The analyzer generates histograms visualizing allocation size distributions, helping identify memory usage patterns and optimize Lua memory management. Note that extremely large direct allocations may bypass LuaJIT’s allocator entirely.
Resource Category
Memory.
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-alloc-stats -p PID
# trace a shell command directly
orxray analyzer run lj-alloc-stats -c SHELL_CMD
Tracing Multiple Processes
Not supported.
Output Formats
- Histogram Bar Charts
- Plain Texts
Output Example
{
"distributions": {
"segments": [
{"count": 0, "key": "32768"},
{"count": 10, "key": "131072"},
{"count": 15, "key": "262144"},
{"count": 18, "key": "524288"},
{"count": 26, "key": "1048576"},
{"count": 8, "key": "2097152"},
{"count": 5, "key": "4194304"},
{"count": 3, "key": "8388608"}
],
"free": [
{"count": 1070, "key": "32"},
{"count": 278, "key": "64"},
{"count": 1758, "key": "128"},
{"count": 2885, "key": "256"},
{"count": 2218, "key": "512"},
{"count": 934, "key": "1024"},
{"count": 1345, "key": "2048"},
{"count": 423, "key": "4096"},
{"count": 187, "key": "8192"},
{"count": 266, "key": "32768"},
{"count": 27, "key": "65536"},
{"count": 22, "key": "131072"}
],
"used": [
{"count": 178, "key": "8"},
{"count": 37270, "key": "32"},
{"count": 32734, "key": "64"},
{"count": 7169, "key": "128"},
{"count": 8421, "key": "256"},
{"count": 4924, "key": "512"},
{"count": 1818, "key": "1024"},
{"count": 4562, "key": "2048"},
{"count": 2112, "key": "4096"},
{"count": 939, "key": "8192"},
{"count": 475, "key": "32768"}
]
},
"segments": {
"min": 131072,
"max": 14548992,
"count": 85,
"sum": 140115968
},
"used": {
"min": 8,
"max": 524296,
"count": 100842,
"sum": 83237768
},
"luajit_big_chunks": 790277,
"luajit_GC_managed": 84028045,
"free": {
"min": 32,
"max": 6259368,
"count": 11502,
"sum": 58973688
}
}
Author
The OpenResty Inc. Team.
Copyright
Copyright (C) by OpenResty Inc. All rights reserved.