Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

APC serialization slow?

Example:

$arr = array();

for($i = 5; $i < 300000; $i++)
    $arr[$i] = 'foo';

apc_store('data', $arr);

It takes like 15 seconds. To get the data it takes around 0.7s.

But if I serialize the data with php and store it like that with apc_store('data', serialize($arr)); it takes only 1 second.

To get the serialized data and then unserialize it, it takes a little more than 0.6s

Why is APC so slow?

like image 976
Alex Avatar asked Oct 14 '12 22:10

Alex


1 Answers

apc_sma_info() provides one interesting information which, maybe, could explain why happens.

Executing apc_store() with a non-serialized data produces to me, in block_lists index the following values:

Array
(
    [0] => Array
        (
            [size] => 608
            [offset] => 33152
        )

    [1] => Array
        (
            [size] => 5589032
            [offset] => 11211992
        )

    [2] => Array
        (
            [size] => 2175976
            [offset] => 31378408
        )
)

While serializing them manually produces:

Array
    (
        [0] => Array
            (
                [size] => 11178232
                [offset] => 33760
            )

        [1] => Array
            (
                [size] => 1210040
                [offset] => 16801024
            )

        [2] => Array
            (
                [size] => 15542104
                [offset] => 18012280
            )
    )

It's curious, but seems that with a manual serialization, APC splits the first and last pieces of data in a larger blocks, doing a better disposition of content.

Doesn't seem to be something trivial because I ran this test a couple times and I got similar results everytime.

like image 110
Bruno Augusto Avatar answered Oct 09 '22 21:10

Bruno Augusto