Performance Pipeline
Introduction
Section titled “Introduction”The Performance Pipeline measures how long commands and queries take to execute and logs a warning when their execution time exceeds the configured threshold.
You enable it by passing withPerformance() to XenoAppBuilder.addPipeline().
The pipeline supports two levels of configuration:
thresholdMs: global threshold used for all intents.intentThresholdMs: optional thresholds for specific intents.
When an intent has a specific threshold configured, that value takes precedence over the global threshold.
Enable the Performance Pipeline
Section titled “Enable the Performance Pipeline”Add the pipeline when configuring your application:
import { XenoAppBuilder, withPerformance } from '@xeno-js/core'
const app = new XenoAppBuilder() .addPipeline(withPerformance()) .build()withPerformance() adds the Performance Pipeline to the common pipeline behaviors used by commands and queries.
Configure the Global Threshold
Section titled “Configure the Global Threshold”Use the thresholdMs option to define the default threshold for commands and queries.
import { XenoAppBuilder, withPerformance } from '@xeno-js/core'
const app = new XenoAppBuilder() .addPipeline(withPerformance((options) => { options.thresholdMs = 500 })) .build()The default value is:
500The value is expressed in milliseconds.
The global threshold is used whenever the current request intent does not have a specific threshold configured.
Configure Thresholds by Intent
Section titled “Configure Thresholds by Intent”Use intentThresholdMs as a registry of per-intent threshold overrides. Each key must match the request’s intent; each value is an object containing a thresholdMs property.
An intent-specific threshold takes precedence over the global thresholdMs option.
import { XenoAppBuilder, withPerformance } from '@xeno-js/core'
const app = new XenoAppBuilder() .addPipeline(withPerformance((options) => { options.thresholdMs = 500 options.intentThresholdMs = { CREATE_USER_HANDLER: { thresholdMs: 300 }, } })) .build()In this example:
- all requests use
500msby default; - requests with intent
CREATE_USER_HANDLERuse300ms; - the specific
CREATE_USER_HANDLERthreshold overrides the global threshold.
This is useful when different application operations have different expected execution times.
Global and Intent-Registry Thresholds
Section titled “Global and Intent-Registry Thresholds”You can configure multiple intents independently in the intentThresholdMs registry:
import { XenoAppBuilder, withPerformance } from '@xeno-js/core'
const app = new XenoAppBuilder() .addPipeline(withPerformance((options) => { options.thresholdMs = 500 options.intentThresholdMs = { CREATE_USER_HANDLER: { thresholdMs: 300 }, UPDATE_USER_HANDLER: { thresholdMs: 400 }, DELETE_USER_HANDLER: { thresholdMs: 250 }, GET_USER_HANDLER: { thresholdMs: 100 }, } })) .build()The effective threshold for a request is selected in this order:
options.intentThresholdMs[request.intent].thresholdMsoptions.thresholdMs- the default global threshold of
500ms
For example, with:
options.thresholdMs = 500options.intentThresholdMs = { CREATE_USER_HANDLER: { thresholdMs: 300 },}the behavior is:
| Intent | Effective threshold |
|---|---|
CREATE_USER_HANDLER |
300ms |
UPDATE_USER_HANDLER |
500ms |
DELETE_USER_HANDLER |
500ms |
| Any unconfigured intent | 500ms |
An intent-specific threshold is therefore an override, not an additional threshold.
Configure Only Specific Intents
Section titled “Configure Only Specific Intents”You can keep the global threshold and override only the operations that require different limits:
import { XenoAppBuilder, withPerformance } from '@xeno-js/core'
const app = new XenoAppBuilder() .addPipeline(withPerformance((options) => { options.thresholdMs = 1000 options.intentThresholdMs = { CREATE_USER_HANDLER: { thresholdMs: 300 }, CHECKOUT_HANDLER: { thresholdMs: 800 }, } })) .build()Here:
CREATE_USER_HANDLERuses300ms;CHECKOUT_HANDLERuses800ms;- every other intent uses
1000ms.
Performance Warnings
Section titled “Performance Warnings”When execution exceeds the effective threshold, the pipeline logs a warning:
Performance warning: CREATE_USER_HANDLER took 342.17msThe warning contains:
- the request intent;
- the measured execution time in milliseconds.
A warning is logged only when the execution time is greater than the effective threshold.
For example, with a threshold of 300ms:
299ms→ no warning;300ms→ no warning;301ms→ warning.
Threshold Validation
Section titled “Threshold Validation”The global thresholdMs must be greater than zero. Intent-specific thresholdMs values must be positive integers.
For example, this configuration is invalid:
import { XenoAppBuilder, withPerformance } from '@xeno-js/core'
const app = new XenoAppBuilder() .addPipeline(withPerformance((options) => { options.thresholdMs = 0 options.intentThresholdMs = { CREATE_USER_HANDLER: { thresholdMs: -100 }, } })) .build()The global threshold rejects negative values and zero, but is not checked for integer precision. The pipeline validates each intent-specific threshold as a positive integer.
Each configured intent threshold is validated independently.
Complete Example
Section titled “Complete Example”The following example configures a global threshold together with different thresholds for selected handlers:
import { XenoAppBuilder, withPerformance } from '@xeno-js/core'
const app = new XenoAppBuilder() .addPipeline(withPerformance((options) => { // Fallback threshold for all intents. options.thresholdMs = 500
// Overrides for selected intents. options.intentThresholdMs = { CREATE_USER_HANDLER: { thresholdMs: 300 }, UPDATE_USER_HANDLER: { thresholdMs: 400 }, CHECKOUT_HANDLER: { thresholdMs: 1000 }, } })) .build()The resulting behavior is:
CREATE_USER_HANDLER → 300msUPDATE_USER_HANDLER → 400msCHECKOUT_HANDLER → 1000msEverything else → 500msCommands and Queries
Section titled “Commands and Queries”The Performance Pipeline applies to both commands and queries executed through the configured CQRS pipeline.
The intent-specific configuration works the same way for both:
withPerformance((options) => { options.intentThresholdMs = { CREATE_USER_HANDLER: { thresholdMs: 300 }, GET_USER_HANDLER: { thresholdMs: 100 }, }})The intent identifies the operation being executed, regardless of whether it is a command or query.
Troubleshooting
Section titled “Troubleshooting”My intent-specific threshold is ignored
Section titled “My intent-specific threshold is ignored”Check that the registry key in intentThresholdMs exactly matches the request intent, and that its value contains thresholdMs:
options.intentThresholdMs = { CREATE_USER_HANDLER: { thresholdMs: 300 },}The pipeline compares the key directly with request.intent.
If the intent does not match, Xeno.JS falls back to:
options.thresholdMsI expected a warning at exactly the threshold
Section titled “I expected a warning at exactly the threshold”The pipeline logs a warning only when execution time is greater than the threshold.
With:
options.thresholdMs = 500an execution time of exactly 500ms does not generate a warning.
My threshold value is rejected
Section titled “My threshold value is rejected”Check that the global value is greater than zero. Intent-specific values must be positive integers.
Valid:
3005001000Invalid global values:
0-100An intent-specific value such as 250.5 is also invalid because intent thresholds must be integers.
Related Documentation
Section titled “Related Documentation”Support Us
Section titled “Support Us”Xeno.JS is an MIT-licensed open source project. It can grow thanks to the support of these awesome people. If you’d like to join them, please read more at support section
