BT.stats

BT.stats

BT.stats

Function

returns the runtime resource statistics of the current BT process, which is used to locate I/O running boundaries, background tasks, timers, network services, FFI resources and VM cache status.

Syntax

Parameters

ParametersTypeRequiredDefault valueDescription
None-NoNoneNo parameters required.

Return Value

TypeDescription
ObjectReturns the runtime resource statistics object. See "Return Object Fields" below for fields.

Return object field

FieldTypeMust existDescription
uptimeIntYesThe number of seconds the current BT process has been running, calculated by subtracting start_time from the current Unix timestamp.
threadsIntYesNumber of parallel threads available in the current system. 1 is returned when the read fails.
start_timeIntYesBT process startup timestamp, in seconds.
ioObjectYesConfiguration, number of activities, number of completions, number of rejections, and number of timeouts for the process-level I/O runtime and blocking pool.
taskObjectYesWhether the background task executor is started, the upper limit of the queue, the number of worker threads, the number of queues, the number of runs, the number of completions, and the number of rejections.
timerObjectYesWhether the timer runtime is started, the number of active timers, the number of scheduling heap entries, the upper limit, and the single VM event queue upper limit.
netObjectYesNetwork Web services, event services, bounded event queues, connection and message resource limits.
httpObjectYesHTTP client pool configuration, number of entries, hits, eliminations, creation failures, and slow calls.
mysqlObjectYesMySQL normal query connection pool configuration, number of DSN groups, number of connections, number of hits, number of eliminations, number of creation failures and number of slow calls.
bytesObjectYesBytes Buffer limit and configuration error.
ffiObjectYesWhether FFI is enabled, the number of open dynamic libraries, the number of Buffers and the actual number of allocated bytes.
cacheObjectYesCurrent thread include Compilation cache and template fragment cache entry count, byte count, hit, invalidation, and eviction statistics.
permissionObjectYesPermission configuration snapshot, current actual allowed capabilities and number of permission denials.

ffi Field:

FieldTypeMust existDescription
enabledBoolYesWhether the FFI feature is enabled for the current build.
open_librariesIntYesThe number of dynamic libraries currently opened logically, the upper limit is 32.
buffersIntYesThe current number of surviving FfiBuffers, the upper limit is 256.
buffer_bytesIntYesThe actual total allocation of the current FfiBuffer after rounding up to 16 bytes, with an upper limit of 64 MiB.

I/O default configuration:

Environment variablesDefault valueDescription
BT_IO_WORKERSNumber of CPU threads, maximum 64Number of shared Tokio runtime worker threads.
BT_IO_BLOCKING_WORKERSNumber of CPU threads, max 64Number of bounded blocking pool worker threads.
BT_IO_BLOCKING_QUEUE256, maximum 8192blocking pool wait queue length.
BT_IO_TIMEOUT_MS30000Default synchronization wait timeout, in milliseconds.
BT_IO_SHUTDOWN_TIMEOUT_MS1000Blocking pool shutdown waiting time, in milliseconds.

io Main fields:

FieldTypeMust existDescription
async_runtime_startedBoolYesShared Whether the Tokio runtime has been initialized.
async_activeIntYesThe number of asynchronous I/O tasks currently executing.
async_completedIntYesThe number of asynchronous I/O tasks that have been completed.
async_failedIntYesThe number of asynchronous I/O tasks that failed.
async_timeoutsIntYesThe number of timeouts that occurred while waiting synchronously for the results of an asynchronous task.
async_rejectedIntYesThe number of asynchronous tasks that were rejected due to runtime shutdown or scheduling failure.
blocking_pool_startedBoolYesWhether the bounded blocking pool has been initialized.
blocking_queuedIntYesThe number of blocking tasks currently queued for execution.
blocking_runningIntYesThe number of blocking tasks currently being executed.
blocking_completedIntYesThe number of completed blocking tasks.
blocking_rejectedIntYesThe number of blocking tasks that were rejected because the queue was full or the thread pool was closed.
blocking_timeoutsIntYesThe number of blocking task timeouts waiting for results.
blocking_shutdownBoolYesWhether the blocking pool has entered the shutdown state.
configObjectYesI/O configuration snapshot, including async_workers, blocking_workers, blocking_queue_limit, default_timeout_ms, shutdown_timeout_ms.

io.config Fields:

FieldTypeMust existDescription
async_workersIntYesNumber of shared Tokio runtime worker threads.
blocking_workersIntYesNumber of bounded blocking pool worker threads.
blocking_queue_limitIntYesblocking pool waiting queue length upper limit.
default_timeout_msIntYesDefault synchronization wait timeout, in milliseconds.
shutdown_timeout_msIntYesblocking pool shutdown waiting time, in milliseconds.

task main fields:

FieldTypeMust existDescription
executor_startedBoolYesWhether the background task executor has been initialized.
queue_limitIntYesThe upper limit of the background task waiting queue length.
workersIntYesNumber of background task workers.
queuedIntYesThe number of tasks currently queued for execution.
runningIntYesThe number of tasks currently being executed.
completedIntYesThe number of completed tasks.
rejectedIntYesThe number of tasks that were rejected because the queue was full or the executor was shut down.

timer main fields:

FieldTypeMust existDescription
runtime_startedBoolYesWhether the timer has been initialized during runtime.
activeIntYesThe number of currently active timers.
queuedIntYesThe number of timer entries in the current scheduling heap.
limitIntYesThe maximum number of active timers allowed for the current process.
event_queue_limitIntYesMaximum single VM timer event queue length.

net Default configuration:

Environment VariablesDefault ValueDescription
BT_NET_EVENT_QUEUE4096, maximum 65536TCP, UDP, WebSocket Bounded queue length for background event delivery to the VM.
BT_NET_CONNECTION_LIMIT4096, maximum 65536Maximum number of single-protocol connections or sockets.
BT_NET_MESSAGE_LIMIT1048576, maximum 16777216The upper limit of single TCP/UDP/WebSocket message bytes.
BT_NET_WRITE_QUEUE1024, maximum 8192The length of the queue of pending writes for a single TCP/WebSocket connection.
BT_NET_IDLE_TTL_MS0TCP/WebSocket connection idle closing time, in milliseconds; 0 means not to actively close due to idleness.

net main fields:

FieldTypeMust existDescription
runtime_startedBoolYesWhether the network runtime has been initialized.
web_servicesIntYesThe number of web services currently held by net.listen({type:'web'}) or the web runner.
event_servicesIntYesThe current number of TCP, UDP, and WebSocket event services.
event_queue_boundedBoolYesWhether to enable bounded network event queues. Currently fixed to true.
event_queue_limitInt/EmptyYesNetwork event queue limit. empty when the event queue is not enabled.
event_queue_queuedIntYesThe number of network events currently waiting for distribution by the VM.
event_queue_sentIntYesThe number of network events that were successfully delivered to the VM.
event_queue_rejectedIntYesNumber of network events that were rejected because the queue was full or the channel was closed.
connection_limitIntYesThe maximum number of single-protocol connections or sockets.
message_limitIntYesThe upper limit of bytes in a single message.
write_queue_limitIntYesSingle connection write queue limit.
idle_ttl_msIntYesTCP/WebSocket connection idle closing time, in milliseconds; 0 means closing this policy.

Bytes Default configuration:

Environment variableDefault valueDescription
BT_BYTES_LIMIT16777216, maximum 67108864The maximum number of bytes buffered by a single Bytes.

bytes Main fields:

FieldTypeMust existDescription
limitIntYesSingle Bytes buffer upper limit, unit byte.
config_errorString/EmptyYesBytes Configuration error text; empty when there is no error.

cache Main fields:

FieldTypeMust existDescription
compiled_file_entriesIntYesThe number of current thread include/Web entry file compilation cache entries.
compiled_file_limitIntYesThe upper limit of current thread file compilation cache entries.
compiled_file_bytesIntYesThe estimated number of bytes in the current thread file compilation cache.
compiled_file_bytes_limitIntYesThe estimated byte limit of the current thread file compilation cache.
compiled_file_hitsIntYesNumber of file compilation cache hits.
compiled_file_missesIntYesNumber of file compilation cache misses.
compiled_file_invalidationsIntYesThe number of failures caused by changes in file metainformation, source code fingerprint, source code mode, compilation configuration, or bytecode format.
compiled_file_evictionsIntYesThe number of times the file compilation cache has been evicted due to the maximum number of entries or bytes being reached.
compiled_file_fingerprint_checksIntYesThe number of times to perform content fingerprint checks on recently modified files.
template_fragment_entriesIntYesNumber of template fragment compilation cache entries for the current thread.
template_fragment_limitIntYesThe upper limit of current thread template fragment cache entries.
template_fragment_bytesIntYesThe estimated number of bytes of the current thread's template fragment cache.
template_fragment_bytes_limitIntYesThe estimated byte limit of the current thread template fragment cache.
template_fragment_hitsIntYesNumber of template fragment cache hits.
template_fragment_missesIntYesNumber of template fragment cache misses.
template_fragment_evictionsIntYesThe number of times the template fragment cache has been evicted due to the maximum number of entries or bytes being reached.
template_fragment_bypassedIntYesThe number of times the template fragment is cached when it is too large or exceeds the cache capacity.
template_fragment_max_code_bytesIntYesThe maximum number of source code bytes allowed to be cached for a single template fragment.

permission Default configuration:

Environment variableDefault valueDescription
BT_PERMISSION_ALLOWNot configuredList of allowed capabilities. After configuration, only the capabilities in the list are allowed; support fs, process, net, http, mysql, device, env, desktop, all, none.
BT_PERMISSION_DENYNot configuredDeny capability list. Deny lists have higher priority than allow lists.

permission main fields:

FieldTypeMust existDescription
deniedIntYesThe number of permission denials in the current process.
configObjectYesPermission configuration snapshot. See the permission.config fields below.

permission.config Field:

FieldTypeMust existDescription
allow_configuredBoolYesWhether BT_PERMISSION_ALLOW is explicitly configured.
allowArrayYesCapability name in the allow list; returns all capabilities if not configured.
denyArrayYesName of the capability in the deny list.
allowedArrayYesThe name of the currently allowed capability.
config_errorString/EmptyYesPermission configuration error text; empty when there is no error.

HTTP client pool default configuration:

Environment variableDefault valueDescription
BT_HTTP_CLIENT_POOLtrueWhether to enable the HTTP client pool.
BT_HTTP_CLIENT_POOL_LIMIT32, maximum 1024Maximum number of client configuration groups to retain.
BT_HTTP_CLIENT_IDLE_TTL_MS300000client idle retention time, in milliseconds; 0 means not to be eliminated based on idle time.
BT_HTTP_SLOW_MS0Slow HTTP call log threshold, in milliseconds; 0 means off.

http main fields:

FieldTypeMust existDescription
pool_startedBoolYesWhether the HTTP client pool has been initialized.
entriesIntYesThe number of client entries in the current pool.
hitsIntYesNumber of pool hits.
missesIntYesNumber of pool misses.
createdIntYesNumber of client creations.
evictedIntYesThe number of client evictions.
bypassedIntYesThe number of times the pool was bypassed due to shutdown or cookie storage semantics.
build_failedIntYesNumber of client creation failures.
slow_callsIntYesThe number of slow calls exceeding BT_HTTP_SLOW_MS.
configObjectYesThe current HTTP client pool configuration. See the http.config fields below.

http.config Fields:

FieldTypeMust existDescription
enabledBoolYesWhether to enable the HTTP client pool.
pool_limitIntYesThe maximum number of client configuration groups to retain.
idle_ttl_msIntYesclient idle retention time, in milliseconds; 0 means not to be eliminated based on idle time.
slow_msIntYesSlow HTTP call log threshold, in milliseconds; 0 means closed.
config_errorString/EmptyYesHTTP client pool configuration error text; empty if there is no error.

MySQL common query connection pool default configuration:

Environment variableDefault valueDescription
BT_MYSQL_POOLtrueWhether to enable the common query global connection pool.
BT_MYSQL_POOL_LIMIT16, maximum 256Maximum number of DSN packets to retain.
BT_MYSQL_POOL_MIN_CONNECTIONS0Minimum number of connections per connection pool.
BT_MYSQL_POOL_MAX_CONNECTIONS8, maximum 1024Maximum number of connections per connection pool.
BT_MYSQL_POOL_IDLE_TTL_MS300000Connection pool idle retention time, in milliseconds; 0 means no elimination based on idle time.
BT_MYSQL_CONNECT_TIMEOUT_MS5000Get the connection timeout, in milliseconds.
BT_MYSQL_QUERY_TIMEOUT_MS30000Synchronization wait timeout for a single SQL call, in milliseconds.
BT_MYSQL_SLOW_MS0Slow MySQL call log threshold, in milliseconds; 0 means closed.

mysql main fields:

FieldTypeMust existDescription
pool_startedBoolYesWhether the MySQL global connection pool has been initialized.
entriesIntYesThe number of DSN packets in the current pool, excluding DSN plaintext.
connectionsIntYesThe total number of open connections in the current SQLx pool.
idle_connectionsIntYesTotal number of idle connections in the current SQLx pool.
hitsIntYesNumber of pool hits.
missesIntYesNumber of pool misses.
createdIntYesNumber of pool creations.
evictedIntYesNumber of pool evictions.
bypassedIntYesThe number of times the pool was bypassed due to closing the global pool.
build_failedIntYesNumber of pool creation failures.
slow_callsIntYesThe number of slow calls exceeding BT_MYSQL_SLOW_MS.
transactions_activeIntYesThe current number of active transactions.
transactions_startedIntYesNumber of transactions started.
transactions_committedIntYesNumber of transaction commits.
transactions_rolled_backIntYesNumber of transaction rollbacks, including the default rollback performed by close() on active transactions.
transactions_closedIntYesclose() Number of active transactions successfully closed.
transactions_failedIntYesThe number of transaction start, commit, rollback, or close failures.
configObjectYesThe current MySQL pool configuration. See the mysql.config fields below.

mysql.config Field:

FieldTypeMust existDescription
enabledBoolYesWhether to enable the normal query global connection pool.
pool_limitIntYesThe maximum number of DSN groups to retain.
min_connectionsIntYesMinimum number of connections per connection pool.
max_connectionsIntYesThe maximum number of connections per connection pool.
idle_ttl_msIntYesThe idle retention time of the connection pool, in milliseconds; 0 means that it will not be eliminated according to the idle time.
connect_timeout_msIntYesGet the connection timeout, in milliseconds.
query_timeout_msIntYesSynchronization wait timeout for a single SQL call, in milliseconds.
slow_msIntYesSlow MySQL call log threshold, in milliseconds; 0 means closed.
config_errorString/EmptyYesMySQL pool configuration error text; empty if there is no error.

Code Examples

Notes

  • BT.stats() reads statistics on demand and does not maintain heavy counts during normal VM instruction execution.
  • cache statistics only reflect the VM thread local cache of the current thread; in a Web multi-worker scenario, each worker will maintain its own cache.
  • Only mtime, length and version are checked when the file compilation cache is stably hit; recently modified files will be reviewed at low frequency for content fingerprints to avoid executing old bytecode after rapid rewriting of the same length.
  • net.event_queue_rejected greater than 0 indicates that the network event queue is overloaded, TCP/WebSocket message events will trigger the connection to be closed, and UDP messages will be discarded.
- http.bypassed growth usually indicates that the HTTP client pool is turned off, or that cookie_store(true) is requested to be enabled.

- mysql.entries, mysql.connections and transaction statistics do not contain DSN plaintext or passwords; connection failure and slow call logs also avoid printing DSN passwords.

- bytes.limit controls the maximum length of a single Bytes that scripts and I/O boundaries can create to avoid unlimited growth of the binary buffer.

  • ffi statistics only maintain open Library and Buffer resource quotas, not the cumulative number of native function call hot paths or cache hits.
- permission.denied greater than 0 indicates that the script triggered a capability that is denied by the current configuration; permission denial is an explicit runtime error and does not return empty.

- Misconfiguration of I/O environment variables will result in an error the first time the relevant I/O capability is used, without silently falling back to dangerous default values.