Skip to content

firstrow/feature-science

Repository files navigation

FeatureScience!

Build Status

A PHP 5.4 library for refactoring, performance and issue testing new/old code in your production projects.

How to use it?

For example, let's pretend you're changing caching backend. The following code example will help you to test and compare performance of new code under load.

$experiment = new \FeatureScience\Test('cacher.save', [
    'control'   => function() { $this->filecache->save() }, // old code
    'candidate' => function() { $this->memcached->save() }, // new code
]);

$experiment->run();

How does it work?

$experiment->run() will randomly select one of the testing subjects from array, run it and return result. Behind the scenes Test::run will collect duration, memory usage, exceptions of both behaviors and save it to the storage.
To not load server by writing files each request, FeatureScience will store temporary data in APC storage and after experiment has been run 100 times, will save its results to the specified directory. You can change this limit by calling $experiment->setPayloadLimit(number).

Configuring

By default payload.saver saves results into system temp dir. But you can configure your own path.

Note: Remember to make that path writable by the web server.

use FeatureScience\PayloadSaver;

\FeatureScience\DI::set('payload.saver', new PayloadSaver('/path/to/save/results'));

Viewing results

You can view with your favorite editor or by typing command:

vendor/bin/feature-science /path/to/feature.name.json

It will look like:

{
    "name":"array.performance",
    "control":{
        "duration":0.01359,
        "exception":null
    },
    "candidate":{
        "duration":0.00261,
        "exception":{
            "message": "Ooops! Something went wrong",
            "code": "503",
            "file": "test.php",
            "line": "27"
        }
    }
}

Installation via Composer

Add FeatureScience to composer.json and run installation.

{
    "require": {
        "firstrow/feature-science": "dev-master"
    }
}

Overhead

Each benchmark runs test code 1000 times.

php benchmarks/clean.php       13.37s
php benchmarks/experiment.php  13.80s

So, its around +0.4s total execution time for each 1000 requests or 0.0004ms per one request.

Todo

  • Track memory usage
  • Save min, avg, max duration

Links

Inspired by ruby gem dat-science
Also, you may find useful athletic

About

Library helps to test new feature performance in production. Written in PHP 5.4 and tested with phpspec

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages