Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yac is only faster on apc in some special cases #7

Closed
AnonSphere opened this Issue Mar 24, 2013 · 7 comments

Comments

Projects
None yet
3 participants
@AnonSphere
Copy link

commented Mar 24, 2013

Hi, I've taken your example from http://www.laruence.com/2013/03/18/2846.html and you are right Yac seems to be quite faster as apc is. So I moved it to a real case program, where some results from the database are cached, but found out, that Yac is a little slower (not much, but 10 %). After playing around with your example, I found out, that apc is slower only in cases, where the key is longer than a certain length. Your example with 10000 rounds gives me:

Yac:

$yac = new Yac();

$start = microtime(true);
for ($i = 0; $i<10000; $i++) {
    $key =  "xxx" . rand(1, 10000);
    $value = str_repeat("x", rand(1, 10000));

    if (!$yac->set($key, $value)) {
        var_dump("write " . $i);
    }

    if ($value != ($new = $yac->get($key))) {
        var_dump("read " . $i);
    }
}
echo (microtime(true)-$start).'<br />';

$start = microtime(true);
for ($i = 0; $i<10000; $i++) {
    $key =  "xxx" . rand(1, 10000);
    $value = str_repeat("x", rand(1, 10000));

    if (!apc_store($key, $value)) {
        var_dump("write " . $i);
    }

    if ($value != ($new = apc_fetch($key))) {
        var_dump("read " . $i);
    }
}
echo (microtime(true)-$start).'<br />';

Yac:
0.11415910720825 <- Yac faster
APC:
0.12692189216614


$yac = new Yac();

$start = microtime(true);
for ($i = 0; $i<10000; $i++) {
    $key =  md5("y" . rand(1, 100)); // <- the key length is the only difference!
    $value = str_repeat("x", rand(1, 10000));

    if (!$yac->set($key, $value)) {
        var_dump("write " . $i);
    }

    if ($value != ($new = $yac->get($key))) {
        var_dump("read " . $i);
    }
}
echo (microtime(true)-$start).'<br />';
?>
APC:
<?php

$start = microtime(true);
for ($i = 0; $i<10000; $i++) {
    $key =  md5("y" . rand(1, 100)); // <- the key length is the only difference!
    $value = str_repeat("x", rand(1, 10000));

    if (!apc_store($key, $value)) {
        var_dump("write " . $i);
    }

    if ($value != ($new = apc_fetch($key))) {
        var_dump("read " . $i);
    }
}
echo (microtime(true)-$start).'<br />';

Yac:
0.11087489128113
APC:
0.094645977020264 <- APC is faster

In most cases this will be no problem, as Yac is on very constant speed, but in the cases I testet over a longer period, apc seems to be a better choice so far. Maybe my investigation will help you to improve Yac. 👍

@laruence

This comment has been minimized.

Copy link
Owner

commented Mar 24, 2013

hey, so you are running the test script in a single process?

@AnonSphere

This comment has been minimized.

Copy link
Author

commented Mar 24, 2013

My yac.ini:

extension=yac.so
yac.enable = 1
yac.keys_memory_size = 4M
yac.values_memory_size = 64M
yac.compress_threshold = -1

So maybe yes. :-)

@laruence

This comment has been minimized.

Copy link
Owner

commented Mar 24, 2013

yac is no lock cache, that means, if you run the test scripts in multi-processes(which is the common usage, like ab -n 1000 -c 50 ) then the performance advantage will show up.. :)

and thanks for the info about shorter key length. I will look into it.

thanks

@AnonSphere

This comment has been minimized.

Copy link
Author

commented Mar 24, 2013

Ah, sorry - you meant if I make a benchmark on the script, I will see the difference? That might be correct. Currently I just tried with a single process on a smaller project, where the values does not change often. But I will try this out. Thank you! 👍

@laruence

This comment has been minimized.

Copy link
Owner

commented Mar 24, 2013

you are welcome, any feedback is appreciated :)

@laruence laruence closed this Mar 24, 2013

@benbender

This comment has been minimized.

Copy link

commented Mar 24, 2013

Is there any real explanation why apc should be faster with longer keys or is this only statistical variation on those tests? For me it sounds quite strange that apc should be percentually so much faster only by using longer keys... could you rerun your tests f.e. 1000 times and build median values too proof your results?

@AnonSphere

This comment has been minimized.

Copy link
Author

commented Mar 24, 2013

@benbender I can't tell you why, but the key length has an effect on the benchmark results in apc. See

apc_clear_cache();

$start = microtime(true);
for ($i = 0; $i<10000; $i++) {
$key = "xxx".rand(1,100);
$value = str_repeat("x", rand(1, 1000));

if (!apc_store($key, $value)) {
    var_dump("write " . $i);
}

if ($value != ($new = apc_fetch($key))) {
    var_dump("read " . $i);
}
}
echo (microtime(true)-$start).'<br />';

apc_clear_cache();

$start = microtime(true);
for ($i = 0; $i<10000; $i++) {
$key = "xxx".rand(1,1000);
$value = str_repeat("x", rand(1, 1000));

if (!apc_store($key, $value)) {
    var_dump("write " . $i);
}

if ($value != ($new = apc_fetch($key))) {
    var_dump("read " . $i);
}
}
echo (microtime(true)-$start).'<br />';

apc_clear_cache();

$start = microtime(true);
for ($i = 0; $i<10000; $i++) {
$key = "xxx".rand(1,10000);
$value = str_repeat("x", rand(1, 1000));

if (!apc_store($key, $value)) {
    var_dump("write " . $i);
}

if ($value != ($new = apc_fetch($key))) {
    var_dump("read " . $i);
}
}
echo (microtime(true)-$start).'<br />';

Results:

0.038509845733643
0.039151906967163
0.041460990905762

0.037004947662354
0.038368940353394
0.040554046630859

0.037173986434937
0.038563966751099
0.040863037109375

It has no effect with yac.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.