Class SlowQueryLog

java.lang.Object
com.loomcache.server.query.SlowQueryLog

public class SlowQueryLog extends Object
Logs and analyzes slow queries in a bounded circular buffer. Provides query pattern analysis and performance statistics for tuning.
  • Constructor Details

    • SlowQueryLog

      public SlowQueryLog(long slowQueryThresholdMs, int maxBufferSize)
      Creates a new SlowQueryLog with configurable threshold and buffer size.
      Parameters:
      slowQueryThresholdMs - threshold in milliseconds to consider a query slow (default 100)
      maxBufferSize - maximum number of entries to keep (default 1000)
    • SlowQueryLog

      public SlowQueryLog()
      Creates a SlowQueryLog with default settings (100ms threshold, 1000 entries).
  • Method Details

    • logQueryIfSlow

      public void logQueryIfSlow(String sql, long executionTimeMs, long rowsScanned, long rowsReturned, String clientId, String mapName)
      Logs a query if its execution time exceeds the threshold.
      Parameters:
      sql - the SQL query string
      executionTimeMs - execution time in milliseconds
      rowsScanned - number of rows scanned
      rowsReturned - number of rows returned
      clientId - client identifier
      mapName - name of the map queried
    • getSlowQueries

      public List<SlowQueryLog.SlowQueryEntry> getSlowQueries(int limit)
      Returns the most recent slow queries (limit).
      Parameters:
      limit - maximum number of entries to return
      Returns:
      list of slow query entries in reverse chronological order
    • getSlowQueries

      public List<SlowQueryLog.SlowQueryEntry> getSlowQueries(long sinceTimestamp)
      Returns slow queries logged since the given timestamp.
      Parameters:
      sinceTimestamp - timestamp in milliseconds
      Returns:
      list of matching entries in reverse chronological order
    • getSlowQueryPatterns

      public SlowQueryLog.SlowQueryStats getSlowQueryPatterns()
      Returns statistics about slow queries grouped by normalized SQL pattern.
      Returns:
      SlowQueryStats with pattern analysis
    • getTotalSlowQueries

      public long getTotalSlowQueries()
      Returns the total number of slow queries logged.
    • getSlowQueryThreshold

      public long getSlowQueryThreshold()
      Returns the current threshold in milliseconds.