Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

fCache with APC: Entries with same key continuously created

posted by mblarsen 8 years ago

I'm using APC cache as the cache of fCache. I have enabled ORM caching using this cache.

I've noticed that on a clean cache the same keys are inserted several times like this:

            [0] => Array
                (
                    [info] => fSchema::mysql::fORM::default::/Users/mbl/Documents/Projects/mcs_ibob/core/trunk/public_html/::::keys
                    [ttl] => 0
                    [type] => user
                    [num_hits] => 0
                    [mtime] => 1293519640
                    [creation_time] => 1293519640
                    [deletion_time] => 0
                    [access_time] => 1293519640
                    [ref_count] => 0
                    [mem_size] => 12968
                )

            [1] => Array
                (
                    [info] => fSchema::mysql::fORM::default::/Users/mbl/Documents/Projects/mcs_ibob/core/trunk/public_html/::::tables
                    [ttl] => 0
                    [type] => user
                    [num_hits] => 0
                    [mtime] => 1293519640
                    [creation_time] => 1293519640
                    [deletion_time] => 0
                    [access_time] => 1293519640
                    [ref_count] => 0
                    [mem_size] => 1704
                )

            [2] => Array
                (
                    [info] => fSchema::mysql::fORM::default::/Users/mbl/Documents/Projects/mcs_ibob/core/trunk/public_html/::::column_info
                    [ttl] => 0
                    [type] => user
                    [num_hits] => 0
                    [mtime] => 1293519640
                    [creation_time] => 1293519640
                    [deletion_time] => 0
                    [access_time] => 1293519640
                    [ref_count] => 0
                    [mem_size] => 12456
                )

            [3] => Array
                (
                    [info] => fSchema::mysql::fORM::default::/Users/mbl/Documents/Projects/mcs_ibob/core/trunk/public_html/::::column_info
                    [ttl] => 0
                    [type] => user
                    [num_hits] => 0
                    [mtime] => 1293519640
                    [creation_time] => 1293519640
                    [deletion_time] => 0
                    [access_time] => 1293519640
                    [ref_count] => 0
                    [mem_size] => 10408
                )

            [4] => Array
                (
                    [info] => fSchema::mysql::fORM::default::/Users/mbl/Documents/Projects/mcs_ibob/core/trunk/public_html/::::column_info
                    [ttl] => 0
                    [type] => user
                    [num_hits] => 0
                    [mtime] => 1293519640
                    [creation_time] => 1293519640
                    [deletion_time] => 0
                    [access_time] => 1293519640
                    [ref_count] => 0
                    [mem_size] => 9384
                )

            [5] => Array
                (
                    [info] => fSchema::mysql::fORM::default::/Users/mbl/Documents/Projects/mcs_ibob/core/trunk/public_html/::::column_info
                    [ttl] => 0
                    [type] => user
                    [num_hits] => 0
                    [mtime] => 1293519640
                    [creation_time] => 1293519640
                    [deletion_time] => 0
                    [access_time] => 1293519640
                    [ref_count] => 0
                    [mem_size] => 7336
                )

            [6] => Array
                (
                    [info] => fSchema::mysql::fORM::default::/Users/mbl/Documents/Projects/mcs_ibob/core/trunk/public_html/::::column_info
                    [ttl] => 0
                    [type] => user
                    [num_hits] => 0
                    [mtime] => 1293519640
                    [creation_time] => 1293519640
                    [deletion_time] => 0
                    [access_time] => 1293519640
                    [ref_count] => 0
                    [mem_size] => 5800
                )

            [7] => Array
                (
                    [info] => fSchema::mysql::fORM::default::/Users/mbl/Documents/Projects/mcs_ibob/core/trunk/public_html/::::column_info
                    [ttl] => 0
                    [type] => user
                    [num_hits] => 0
                    [mtime] => 1293519640
                    [creation_time] => 1293519640
                    [deletion_time] => 0
                    [access_time] => 1293519640
                    [ref_count] => 0
                    [mem_size] => 4776
                )

            [8] => Array
                (
                    [info] => fSchema::mysql::fORM::default::/Users/mbl/Documents/Projects/mcs_ibob/core/trunk/public_html/::::relationships
                    [ttl] => 0
                    [type] => user
                    [num_hits] => 0
                    [mtime] => 1293519640
                    [creation_time] => 1293519640
                    [deletion_time] => 0
                    [access_time] => 1293519640
                    [ref_count] => 0
                    [mem_size] => 20648
                )

            [9] => Array
                (
                    [info] => fSchema::mysql::fORM::default::/Users/mbl/Documents/Projects/mcs_ibob/core/trunk/public_html/::::merged_keys
                    [ttl] => 0
                    [type] => user
                    [num_hits] => 0
                    [mtime] => 1293519640
                    [creation_time] => 1293519640
                    [deletion_time] => 0
                    [access_time] => 1293519640
                    [ref_count] => 0
                    [mem_size] => 12968
                )

            [10] => Array
                (
                    [info] => fSchema::mysql::fORM::default::/Users/mbl/Documents/Projects/mcs_ibob/core/trunk/public_html/::::merged_column_info
                    [ttl] => 0
                    [type] => user
                    [num_hits] => 0
                    [mtime] => 1293519640
                    [creation_time] => 1293519640
                    [deletion_time] => 0
                    [access_time] => 1293519640
                    [ref_count] => 0
                    [mem_size] => 23720
                )

            [11] => Array
                (
                    [info] => fSchema::mysql::fORM::default::/Users/mbl/Documents/Projects/mcs_ibob/core/trunk/public_html/::::merged_column_info
                    [ttl] => 0
                    [type] => user
                    [num_hits] => 0
                    [mtime] => 1293519640
                    [creation_time] => 1293519640
                    [deletion_time] => 0
                    [access_time] => 1293519640
                    [ref_count] => 0
                    [mem_size] => 22184
                )

            [12] => Array
                (
                    [info] => fSchema::mysql::fORM::default::/Users/mbl/Documents/Projects/mcs_ibob/core/trunk/public_html/::::merged_column_info
                    [ttl] => 0
                    [type] => user
                    [num_hits] => 0
                    [mtime] => 1293519640
                    [creation_time] => 1293519640
                    [deletion_time] => 0
                    [access_time] => 1293519640
                    [ref_count] => 0
                    [mem_size] => 20136
                )

            [13] => Array
                (
                    [info] => fSchema::mysql::fORM::default::/Users/mbl/Documents/Projects/mcs_ibob/core/trunk/public_html/::::merged_column_info
                    [ttl] => 0
                    [type] => user
                    [num_hits] => 0
                    [mtime] => 1293519640
                    [creation_time] => 1293519640
                    [deletion_time] => 0
                    [access_time] => 1293519640
                    [ref_count] => 0
                    [mem_size] => 13480
                )

            [14] => Array
                (
                    [info] => fSchema::mysql::fORM::default::/Users/mbl/Documents/Projects/mcs_ibob/core/trunk/public_html/::::merged_column_info
                    [ttl] => 0
                    [type] => user
                    [num_hits] => 0
                    [mtime] => 1293519640
                    [creation_time] => 1293519640
                    [deletion_time] => 0
                    [access_time] => 1293519640
                    [ref_count] => 0
                    [mem_size] => 4776
                )

            [15] => Array
                (
                    [info] => fSchema::mysql::fORM::default::/Users/mbl/Documents/Projects/mcs_ibob/core/trunk/public_html/::::merged_column_info
                    [ttl] => 0
                    [type] => user
                    [num_hits] => 0
                    [mtime] => 1293519640
                    [creation_time] => 1293519640
                    [deletion_time] => 0
                    [access_time] => 1293519640
                    [ref_count] => 0
                    [mem_size] => 2216
                )

It appears to be mainly the merged_column_info key.

As refresh the page every time at least two 'inserts' occur. And many of these merged_column_info cache entries is created with 0 hits of course. The other ORM cache entries seems to hit quite good.

fSchema and fDatabase are using apc_store and not apc_add is there a reason for this. Also the ttl of cache values appears to be all set to zero.

These are my APC cache settings:

apc.slam_defense=0
apc.write_lock=0
apc.gc_ttl=0
apc.ttl = 3000
apc.user_ttl = 3600

I'll have to do some debugging to see why exactly multiple calls are being made.

Looking at the code, it appears that when column info is requested from fSchema, the database it inspected just for the table requested. Then any overrides are laid over the real schema, and the result is saved to the merged column info, which is stored in APC. So theoretically fCache::set() would be called once for every table that has any customization. It seems I made fSchema to not load the merged column info from the database if overridden table schemas exist, however I should probably add the same check before bothering with storing it in the cache.

I believe apc_store() is used to ensure that the value is stored, even if it already exists with a different value. For the schema information, a TTL doesn't really seem to make sense. The schema info doesn't decay, it is perfectly valid until it changes.

posted by wbond 8 years ago

APC is somewhat hard to figure out sometime. I recently had a clash with it - also check my answer http://stackoverflow.com/questions/4468805

I think you are right to use apc_store() - if you hit the cache to often/fast or the apc settings are not just right (no documentation) you will see that cache starting to fill up.

posted by mblarsen 8 years ago