Adding cache measurement metric points

You can add measurement points to retrieve metrics that are not measured by default with the Performance Measurement tool. Before you can measure and analyze the potential cache impact for a process, you must retrieve the metrics to be analyzed.

To retrieve new metrics, you must implement an operation that creates measurement points and retrieves and logs the metrics for these points. As an example, you can add measurement points to retrieve metrics to analyze the cache impact of your outbound calls to an application integrated with HCL Commerce.

The following code is a sample for how to gather a metric for use in cache measurement.
/**
* Perform an operation and capture the metrics required for cache potential
* analysis.
* 
* This implementation uses a standard Java Logger.
*/

private static final Level MEASURE_RESULT_SIZE_LEVEL = Level.FINER;
private static final Logger LOGGER = Logger.getLogger(SamplePerformanceLoggingFilter.class.getName());
private static final LogMetricGatherer LOG_GATHERER = new LogMetricGatherer(LOGGER);

@SuppressWarnings("null")
public void performOperationUsingLogger() {
  OperationMetric metric = null;
  
  // only log cache metrics if we log them to minimize overhead
  // if the metrics aren't actively used.
  boolean logOperationMetric = LOG_GATHERER.isLoggable();
  if (logOperationMetric) {
    metric = new OperationMetric();
    String operationName = "performOperation";
    boolean isOperationCacheEnabled = true;
    
    // all the parameters name-value pairs, converted to a string
    // format.
    String[] keyValuePairs = new String[] { "parameter1", "value1",
    "parameter2", "value2" };
    metric.startOperation(operationName, isOperationCacheEnabled,
    keyValuePairs);
  }
  
  // run the operation
  
  if (logOperationMetric) {
    // use the logger level to determine if we should perform
    // an expensive size measurement.
    boolean logSize = LOG_GATHERER.getLogger().isLoggable(
    MEASURE_RESULT_SIZE_LEVEL);
    int resultSize = 1;
    if (logSize) {
      // perform a more expensive result size measurement
    }
    boolean isResultFetchedFromCache = false;
    metric.stopOperation(resultSize, isResultFetchedFromCache);
    
    LOG_GATHERER.gatherMetric(metric);
  }
}
  • The request unique ID and parent unique ID are automatically calculated with the startOperation and stopOperation method by using a thread-local variable. This automatic calculation means that operation IDs must be propagated through threads if an operation ever creates multiple threads.
  • The request start time, end time, and duration are automatically calculated with the startOperation and stopOperation method by using nanosecond precision as provided by the JVM.
  • The logger infrastructure is used to determine whether you should measure a request or not, to minimize the impact on the system when measurements are not required. The recommendation is to use the following three levels
    • Level.INFO and above - no measurement is performed.
    • Level.FINE - request metrics are measured, but not the response size.
    • Level.FINER - request metrics are measured, including the response size.
  • The reason multiple level of loggers are used is to allow the measurement of metrics to occur in a production system and minimize the resource usage of the measurement process.