Using Utilization Subsystem to Monitor Slow Execution of Services
When you enable the Utilization Subsystem, it gets detailed metrics about the duration of service execution. The following details are retrieved using the services in this subsystem:
Time a service takes to compete execution (minimum, maximum, and mean time)
Number of times a service is executed
Statistics are recorded in milliseconds from the time that the server was last restarted, but can be persisted by enabling the Enable Statistics Persistence option. Use the WriteStatisticsReport service to create a CSV file that contains these statistics. The CSV file is created in the ThingworxStorage folder.
The metrics are collected only after a service is complete. If a service executes in an infinite loop that eventually brings the server down, the time for that service is not recorded.
It is recommended to export and analyze data from the Utilization Subsystem to identify long-running services. If you have identified a slow service, update the services to print logging lines. These logs can retrieve the duration of operations. Sometimes, a specific set of parameters or a specific query is responsible for the slow behavior. Logging the parameters in the script is an easy and reliable way to capture this data. The following script can be expanded to print detailed information about the operations that take more than 30 seconds. The script can be further updated to print service parameters or other data as required:
var startTime= new Date();
// potentially slow operation
var endTime = new Date();

//calculate difference in seconds and print details only if operation takes over 30 seconds
var diff = (endTime.getTime() - startTime.getTime) / 1000 % 60;
if (diff > 30) logger.error("+++Slow operation: " + diff + "seconds "); // add any parameters or queries
Was this helpful?