Tobias Tacke

NAME

Cache::Benchmark - Tests the quality and speed of a cache module to compare cachemodules and algorithms.

VERSION

Version 0.011

SYNOPSIS

 use Cache::Benchmark();
 use Cache::MemoryCache();
 use Cache::SizeAwareMemoryCache();
 
 my $cache_1 = new Cache::MemoryCache({
        namespace => 'my',
        default_expires_in => 1,
 });
 my $cache_2 = new Cache::SizeAwareMemoryCache({
        namespace => 'my',
        default_expires_in => 1,
        max_size => 400,
 });
 
 my $test = new Cache::Benchmark();
 $test->init( access_counter => 10_000 );
 
 $test->run($cache_1);
 print $test->get_printable_result();
 
 $test->run($cache_2);
 print $test->get_printable_result();

EXPORT

-

CONSTRUCTOR

new()

    No parameter. You have to "init()" the object

    return: __PACKAGE__

    parameter: -

METHODS

init( [ "keys" => INT, "min_key_length" => INT, "access_counter" => INT, "value" => SCALAR, "test_type" => ENUM, "weighted_key_config" => HASHREF, "sleep_time" => FLOAT, "access_list" => ARRAYREF ] )

    Initialises and configures the benchmark-test. Without that, no other method will work. All parameters are optional.

    return: BOOLEAN

    parameter:

    keys: INT [default: 1_000]

    how many cache keys are used

    min_key_length: INT [default: 30]

    the minimal length of any key in the cache. The standard-keys are integers (from 0 till defined "keys"), if you define some min-length, the keys will be filled with initial zeros until reaching the given length.

    access_counter: INT [default: 100_000]

    how many times will a cache key be get() or set() to the cache-module

    value: SCALAR [default: STRING, 500 bytes long]

    what the cache-value should be (can be anything except UNDEF, only to stress the memory usage)

    test_type: ENUM [default: weighted]

    types of test. These can be:

    plain:

    not a real test. This will only call all keys one after another. No random, no peaks.

    random:

    only for access-speed tests. The key is randomly generated. No peaks.

    weighted:

    keys are randomly generated and weighted. Some keys have a high chance of being used, others have less chances

    sleep_time: FLOAT [default: 0]

    the waiting time between each access in seconds. For example use 0.001 to wait a millisecond between each access.

    weighted_key_config: [default: this example-config]

    an own config for the test_type "weighted". It's a simple hashref with the following structure:

       $config = {
        1.5 => 15, 
        10  => 10, 
        35  => 7, 
        50  => 5,
        65  => 3,
        85  => 2,
        99  => 1,
       };

    Example:

    1.5 => 15

    means: the first 1.5% of all keys have a 15 times higher chance to hit

    10 => 10

    means: from 1.5% till 10% the keys will have a 10 times higher chance...

    35 => 7

    means: from 10% till 35% ... 7 times higher ... ...etc

    the key (percent) can be a FLOAT, value (weight) has to be an INT

    accesslist: ARRAYREF [default: undef]

    sets the list of keys the benchmark-test will use in run(). (an ARRAYREF of INT) Usable to repeat exactly the same test which was stored via "get_generated_keylist()" or to define your own list. If you give an access list, all other parameters, except "sleep_time", are senseless.

    Attention: the arrayref is not dereferenced!

run( "cacheObject", [ "auto_purge" ] )

    Runs the benchmark-test with the given cache-object.

    return: BOOLEAN

    parameter:

    cacheObject: OBJECT

    every cache-object with an interface like the "Cache" Module. Only the following part of the interface is needed:

    set(key, value)

    sets a cache

    get(key)

    reads a cache

    purge()

    cleans up all overhanging caches (on sized cache modules)

    auto_purge: BOOLEAN [default: 0]

    should purge() called after any set() or get()? Useful for some SizeAware... Cache modules.

get_accesslist( )

    get the list of all accessed keys, which the benchmark-test will set() / get(). Usable to store this list and repeat the test with exactly the same environment.

    Attention: the arrayref is not dereferenced!

    return: ARRAYREF of INT

    parameter: -

get_raw_result( )

    returns all benchmark-data in a plain hash for further usage. Have a look at some "get_printable_result()" to understand the data.

    return: HASHREF

    parameter: -

get_printable_result( )

    returns all benchmark-data as a readable string. Quality (cached access divided by uncached access) and runtime (for all get() / set() / purge() operations) are the most important results to compare caches.

    return: STRING

    parameter: -

AUTHOR

Tobias Tacke, <cpan at tobias-tacke.de>

BUGS

Please report any bugs or feature requests to bug-cache-benchmark at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Cache-Benchmark. I will be notified, and then you'll automatically be notified of any progress on your bug as I make changes.

SUPPORT

You can find the documentation of this module with the perldoc command.

    perldoc Cache::Benchmark

You can also look for information at:

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

Copyright 2007 Tobias Tacke, all rights reserved.

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