VERSION

version 0.58

SYNOPSIS

    # Turn on statistics collection
    CHI->stats->enable();

    # Perform cache operations

    # Flush statistics to logs
    CHI->stats->flush();

    ...

    # Parse logged statistics
    my $results = CHI->stats->parse_stats_logs($file1, ...);

DESCRIPTION

\s-1CHI\s0 can record statistics, such as number of hits, misses and sets, on a per-namespace basis and log the results to your Log::Any logger. You can then parse the logs to get a combined summary.

A single CHI::Stats object is maintained for each \s-1CHI\s0 root class, and tallies statistics over any number of CHI::Driver objects.

Statistics are reported when you call the \*(L"flush\*(R" method. You can choose to do this once at process end, or on a periodic basis.

METHODS

enable, disable, enabled

Enable, disable, and query the current enabled status. When stats are enabled, each new cache object will collect statistics. Enabling and disabling does not affect existing cache objects. e.g. my $cache1 = CHI->new(...); CHI->stats->enable(); # $cache1 will not collect statistics my $cache2 = CHI->new(...); CHI->stats->disable(); # $cache2 will continue to collect statistics

flush

Log all statistics to Log::Any (at Info level in the CHI::Stats category), then clear statistics from memory. There is one log message for each distinct triplet of root class, cache label, and namespace. Each log message contains the string \*(L"\s-1CHI\s0 stats:\*(R" followed by a \s-1JSON\s0 encoded hash of statistics. e.g. CHI stats: {"absent_misses":1,"label":"File","end_time":1338410398, "get_time_ms":5,"namespace":"Foo","root_class":"CHI", "set_key_size":6,"set_time_ms":23,"set_value_size":20,"sets":1, "start_time":1338409391}

parse_stats_logs

Accepts one or more stats log files as parameters. Parses the logs and returns a listref of stats hashes by root class, cache label, and namespace. e.g. [ { root_class => 'CHI', label => 'File', namespace => 'Foo', absent_misses => 100, avg_compute_time_ms => 23, ... }, { root_class => 'CHI', label => 'File', namespace => 'Bar', ... }, ] Lines with the same root class, cache label, and namespace are summed together. Non-stats lines are ignored. The parser will ignore anything on the line before the \*(L"\s-1CHI\s0 stats:\*(R" string, e.g. a timestamp. Each parameter to this method may be a filename or a reference to an open filehandle.

STATISTICS

The following statistics are tracked in the logs:

  • \*(C`absent_misses\*(C' - Number of gets that failed due to item not being in the cache

  • \*(C`compute_time_ms\*(C' - Total time spent computing missed results in compute, in ms (divide by number of computes to get average). i.e. the amount of time spent in the code reference passed as the third argument to compute().

  • \*(C`computes\*(C' - Number of compute calls

  • \*(C`expired_misses\*(C' - Number of gets that failed due to item expiring

  • \*(C`get_errors\*(C' - Number of caught runtime errors during gets

  • \*(C`get_time_ms\*(C' - Total time spent in get operation, in ms (divide by number of gets to get average)

  • \*(C`hits\*(C' - Number of gets that succeeded

  • \*(C`set_key_size\*(C' - Number of bytes in set keys (divide by number of sets to get average)

  • \*(C`set_value_size\*(C' - Number of bytes in set values (divide by number of sets to get average)

  • \*(C`set_time_ms\*(C' - Total time spent in set operation, in ms (divide by number of sets to get average)

  • \*(C`sets\*(C' - Number of sets

  • \*(C`set_errors\*(C' - Number of caught runtime errors during sets

The following additional derived/aggregate statistics are computed by parse_stats_logs:

  • \*(C`misses\*(C' - \*(C`absent_misses\*(C' + \*(C`expired_misses\*(C'

  • \*(C`gets\*(C' - \*(C`hits\*(C' + \*(C`misses\*(C'

  • \*(C`avg_compute_time_ms\*(C' - \*(C`compute_time_ms\*(C' / \*(C`computes\*(C'

  • \*(C`avg_get_time_ms\*(C' - \*(C`get_time_ms\*(C' / \*(C`gets\*(C'

  • \*(C`avg_set_time_ms\*(C' - \*(C`set_time_ms\*(C' / \*(C`sets\*(C'

  • \*(C`avg_set_key_size\*(C' - \*(C`set_key_size\*(C' / \*(C`sets\*(C'

  • \*(C`avg_set_value_size\*(C' - \*(C`set_value_size\*(C' / \*(C`sets\*(C'

  • \*(C`hit_rate\*(C' - \*(C`hits\*(C' / \*(C`gets\*(C'

RELATED TO CHI::Stats…

\s-1CHI\s0

AUTHOR

Jonathan Swartz <[email protected]>

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Jonathan Swartz.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.