cvs: pecl /apc INSTALL apc_cache.c apc_cache.h apc_globals.h apc_main.c php_apc.c

From: Date: Thu, 12 Aug 2004 17:35:00 +0000
Subject: cvs: pecl /apc INSTALL apc_cache.c apc_cache.h apc_globals.h apc_main.c php_apc.c
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-1637@lists.php.net to get a copy of this message
rasmus Thu Aug 12 13:35:00 2004 EDT Modified files: /pecl/apc INSTALL apc_cache.c apc_cache.h apc_globals.h apc_main.c php_apc.c Log: TTL patch The tree was tagged with BEFORE_TTL to make this easier to back out in case we need to. Because sapi_get_request_time() is not available yet, in order to build apc you now need to have httpd.h on your include path. Set your CPPFLAGS to -I/path before running configure to have it find it. I added a note on this to the INSTALL file. I don't have the energy to do a proper config.m4 rule for this since it is a temporary thing.

http://cvs.php.net/diff.php/pecl/apc/INSTALL?r1=3.36&r2=3.37&ty=u Index: pecl/apc/INSTALL diff -u pecl/apc/INSTALL:3.36 pecl/apc/INSTALL:3.37 --- pecl/apc/INSTALL:3.36 Thu Aug 12 12:50:17 2004 +++ pecl/apc/INSTALL Thu Aug 12 13:35:00 2004 @@ -3,7 +3,7 @@ APC has been successfully compiled on the following platforms: - o Linux (RH 6.2/7.2/7.3/8) + o Linux (RH 6.2/7.2/7.3/8, Debian) o FreeBSD o OpenBSD o MacOS 10.2 (statically compiled) @@ -12,12 +12,22 @@ o 4.2.2 o 4.2.3 - o 4.3.0 - o 4.3.2 - + o 4.3.0 - 4.3.9 + Versions prior to 4.2.2 have been officially deprecated by the PHP group, and therefore aren't supported by APC either. +Temporary Apache httpd.h problem +-------------------------------- +A better solution is on the way for this, but for now if you get an error +about not being able to find httpd.h, figure out where it is on your system +(if you don't have it, install the apache_dev package for your OS) and do: + export CPPFLAGS=-I/usr/include/apache-1.3 (for bash on Debian) + setenv CPPFLAGS -I/usr/include/apache-1.3 (for tsch on Debian) +and then re-run your configure script. + +This dependency of APC on httpd.h will disappear in a future version of PHP + +---------------------+ | QUICK INSTALL (DSO) | +---------------------+ @@ -221,6 +231,14 @@ this setting is mainly useful for sites that have many thousands of source files. (Default: 1000) + + apc.ttl The number of seconds a cache entry is allowed to + idle in a slot in case this cache entry slot is + needed by another entry. Leaving this at zero + means that your cache could potentially fill up + with stale entries while newer entries won't be + cached. + (Default: 0) apc.gc_ttl The number of seconds that a cache entry may remain on the garbage-collection list. This value http://cvs.php.net/diff.php/pecl/apc/apc_cache.c?r1=3.57&r2=3.58&ty=u Index: pecl/apc/apc_cache.c diff -u pecl/apc/apc_cache.c:3.57 pecl/apc/apc_cache.c:3.58 --- pecl/apc/apc_cache.c:3.57 Thu Aug 12 12:50:17 2004 +++ pecl/apc/apc_cache.c Thu Aug 12 13:35:00 2004 @@ -14,12 +14,16 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_cache.c,v 3.57 2004/08/12 16:50:17 rasmus Exp $ */ +/* $Id: apc_cache.c,v 3.58 2004/08/12 17:35:00 rasmus Exp $ */ #include "apc_cache.h" #include "apc_lock.h" #include "apc_sma.h" #include "SAPI.h" +#if HAVE_APACHE +#include "httpd.h" +#endif + /* TODO: rehash when load factor exceeds threshold */ @@ -39,6 +43,7 @@ int num_hits; /* number of hits to this bucket */ time_t creation_time; /* time slot was initialized */ time_t deletion_time; /* time slot was removed from cache */ + time_t access_time; /* time slot was last accessed */ }; /* }}} */ @@ -59,6 +64,7 @@ slot_t** slots; /* array of cache slots (stored in SHM) */ int num_slots; /* number of slots in cache */ int gc_ttl; /* maximum time on GC list for a slot */ + int ttl; /* if slot is needed and entry's mtime is older than this ttl, remove it */ int lock; /* global semaphore lock */ }; /* }}} */ @@ -77,13 +83,22 @@ /* {{{ make_slot */ slot_t* make_slot(apc_cache_key_t key, apc_cache_entry_t* value, slot_t* next) { + time_t t; slot_t* p = apc_sma_malloc(sizeof(slot_t)); if (!p) return NULL; +#if HAVE_APACHE + /* Save a syscall here under Apache. This should actually be a SAPI call instead + * but we don't have that yet. Once that is introduced in PHP this can be cleaned up -Rasmus */ + t = ((request_rec *)SG(server_context))->request_time; +#else + t = time(0); +#endif p->key = key; p->value = value; p->next = next; p->num_hits = 0; - p->creation_time = time(0); + p->creation_time = t; + p->access_time = t; p->deletion_time = 0; return p; } @@ -180,7 +195,7 @@ /* }}} */ /* {{{ apc_cache_create */ -apc_cache_t* apc_cache_create(int size_hint, int gc_ttl) +apc_cache_t* apc_cache_create(int size_hint, int gc_ttl, int ttl) { apc_cache_t* cache; int cache_size; @@ -203,6 +218,7 @@ cache->slots = (slot_t**) (((char*) cache->shmaddr) + sizeof(header_t)); cache->num_slots = num_slots; cache->gc_ttl = gc_ttl; + cache->ttl = ttl; cache->lock = CREATE_LOCK; for (i = 0; i < num_slots; i++) { @@ -249,6 +265,7 @@ apc_cache_entry_t* value) { slot_t** slot; + time_t t; if (!value) { return 0; @@ -258,6 +275,15 @@ process_pending_removals(cache); slot = &cache->slots[hash(key) % cache->num_slots]; + if(*slot) { +#if HAVE_APACHE + /* Save a syscall here under Apache. This should actually be a SAPI call instead + * but we don't have that yet. Once that is introduced in PHP this can be cleaned up -Rasmus */ + t = ((request_rec *)SG(server_context))->request_time; +#else + t = time(0); +#endif + } while (*slot) { if (key_equals((*slot)->key, key)) { if ((*slot)->key.mtime < key.mtime) { @@ -266,6 +292,9 @@ } UNLOCK(cache); return 0; + } else if(cache->ttl && (*slot)->access_time < (t - cache->ttl)) { + remove_slot(cache, slot); + continue; } slot = &(*slot)->next; } @@ -284,10 +313,20 @@ apc_cache_entry_t* apc_cache_find(apc_cache_t* cache, apc_cache_key_t key) { slot_t** slot; + time_t t; LOCK(cache); slot = &cache->slots[hash(key) % cache->num_slots]; + if(*slot) { +#if HAVE_APACHE + /* Save a syscall here under Apache. This should actually be a SAPI call instead + * but we don't have that yet. Once that is introduced this can be cleaned up -Rasmus */ + t = ((request_rec *)SG(server_context))->request_time; +#else + t = time(0); +#endif + } while (*slot) { if (key_equals((*slot)->key, key)) { if ((*slot)->key.mtime < key.mtime) { @@ -297,6 +336,7 @@ (*slot)->num_hits++; (*slot)->value->ref_count++; + (*slot)->access_time = t; prevent_garbage_collection((*slot)->value); cache->header->num_hits++; @@ -395,6 +435,7 @@ info = (apc_cache_info_t*) apc_emalloc(sizeof(apc_cache_info_t)); info->num_slots = cache->num_slots; + info->ttl = cache->ttl; info->num_hits = cache->header->num_hits; info->num_misses = cache->header->num_misses; info->list = NULL; @@ -414,6 +455,7 @@ link->mtime = p->key.mtime; link->creation_time = p->creation_time; link->deletion_time = p->deletion_time; + link->access_time = p->access_time; link->ref_count = p->value->ref_count; link->next = info->list; info->list = link; @@ -432,6 +474,7 @@ link->mtime = p->key.mtime; link->creation_time = p->creation_time; link->deletion_time = p->deletion_time; + link->access_time = p->access_time; link->ref_count = p->value->ref_count; link->next = info->deleted_list; info->deleted_list = link; http://cvs.php.net/diff.php/pecl/apc/apc_cache.h?r1=3.16&r2=3.17&ty=u Index: pecl/apc/apc_cache.h diff -u pecl/apc/apc_cache.h:3.16 pecl/apc/apc_cache.h:3.17 --- pecl/apc/apc_cache.h:3.16 Thu Aug 12 12:50:17 2004 +++ pecl/apc/apc_cache.h Thu Aug 12 13:35:00 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_cache.h,v 3.16 2004/08/12 16:50:17 rasmus Exp $ */ +/* $Id: apc_cache.h,v 3.17 2004/08/12 17:35:00 rasmus Exp $ */ #ifndef APC_CACHE_H #define APC_CACHE_H @@ -63,8 +63,12 @@ * gc_ttl is the maximum time a cache entry may speed on the garbage * collection list. This is basically a work around for the inherent * unreliability of our reference counting mechanism (see apc_cache_release). + * + * ttl is the maximum time a cache entry can idle in a slot in case the slot + * is needed. This helps in cleaning up the cache and ensuring that entries + * hit frequently stay cached and ones not hit very often eventually disappear. */ -extern T apc_cache_create(int size_hint, int gc_ttl); +extern T apc_cache_create(int size_hint, int gc_ttl, int ttl); /* * apc_cache_destroy releases any OS resources associated with a cache object. @@ -156,6 +160,7 @@ time_t mtime; time_t creation_time; time_t deletion_time; + time_t access_time; int ref_count; apc_cache_link_t* next; }; @@ -167,6 +172,7 @@ int num_slots; int num_hits; int num_misses; + int ttl; apc_cache_link_t* list; apc_cache_link_t* deleted_list; }; http://cvs.php.net/diff.php/pecl/apc/apc_globals.h?r1=3.7&r2=3.8&ty=u Index: pecl/apc/apc_globals.h diff -u pecl/apc/apc_globals.h:3.7 pecl/apc/apc_globals.h:3.8 --- pecl/apc/apc_globals.h:3.7 Thu Aug 12 12:50:17 2004 +++ pecl/apc/apc_globals.h Thu Aug 12 13:35:00 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_globals.h,v 3.7 2004/08/12 16:50:17 rasmus Exp $ */ +/* $Id: apc_globals.h,v 3.8 2004/08/12 17:35:00 rasmus Exp $ */ #ifndef APC_GLOBALS_H #define APC_GLOBALS_H @@ -31,6 +31,7 @@ int optimization; /* optimizer level (higher = more aggressive) */ int num_files_hint; /* parameter to apc_cache_create */ int gc_ttl; /* parameter to apc_cache_create */ + int ttl; /* parameter to apc_cache_create */ #if APC_MMAP char *mmap_file_mask; /* mktemp-style file-mask to pass to mmap */ #endif http://cvs.php.net/diff.php/pecl/apc/apc_main.c?r1=3.14&r2=3.15&ty=u Index: pecl/apc/apc_main.c diff -u pecl/apc/apc_main.c:3.14 pecl/apc/apc_main.c:3.15 --- pecl/apc/apc_main.c:3.14 Thu Aug 12 12:50:17 2004 +++ pecl/apc/apc_main.c Thu Aug 12 13:35:00 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_main.c,v 3.14 2004/08/12 16:50:17 rasmus Exp $ */ +/* $Id: apc_main.c,v 3.15 2004/08/12 17:35:00 rasmus Exp $ */ #include "apc_php.h" #include "apc_main.h" @@ -237,7 +237,7 @@ #else apc_sma_init(APCG(shm_segments), APCG(shm_size)*1024*1024); #endif - APCG(cache) = apc_cache_create(APCG(num_files_hint), APCG(gc_ttl)); + APCG(cache) = apc_cache_create(APCG(num_files_hint), APCG(gc_ttl), APCG(ttl)); APCG(cache_stack) = apc_stack_create(0); APCG(compiled_filters) = apc_regex_compile_array(APCG(filters)); http://cvs.php.net/diff.php/pecl/apc/php_apc.c?r1=3.30&r2=3.31&ty=u Index: pecl/apc/php_apc.c diff -u pecl/apc/php_apc.c:3.30 pecl/apc/php_apc.c:3.31 --- pecl/apc/php_apc.c:3.30 Thu Aug 12 12:50:17 2004 +++ pecl/apc/php_apc.c Thu Aug 12 13:35:00 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_apc.c,v 3.30 2004/08/12 16:50:17 rasmus Exp $ */ +/* $Id: php_apc.c,v 3.31 2004/08/12 17:35:00 rasmus Exp $ */ #ifdef PHP_WIN32 /* XXX lame hack, for some reason, the ini entries are all messed @@ -86,6 +86,7 @@ STD_PHP_INI_ENTRY("apc.optimization", "0", PHP_INI_SYSTEM, OnUpdateInt, optimization, zend_apc_globals, apc_globals) STD_PHP_INI_ENTRY("apc.num_files_hint", "1000", PHP_INI_SYSTEM, OnUpdateInt, num_files_hint, zend_apc_globals, apc_globals) STD_PHP_INI_ENTRY("apc.gc_ttl", "3600", PHP_INI_SYSTEM, OnUpdateInt, gc_ttl, zend_apc_globals, apc_globals) +STD_PHP_INI_ENTRY("apc.ttl", "0", PHP_INI_SYSTEM, OnUpdateInt, ttl, zend_apc_globals, apc_globals) #if APC_MMAP STD_PHP_INI_ENTRY("apc.mmap_file_mask", NULL, PHP_INI_SYSTEM, OnUpdateString, mmap_file_mask, zend_apc_globals, apc_globals) #endif @@ -107,7 +108,7 @@ #else php_info_print_table_row(2, "MMAP Support", "Disabled"); #endif - php_info_print_table_row(2, "Revision", "$Revision: 3.30 $"); + php_info_print_table_row(2, "Revision", "$Revision: 3.31 $"); php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__); DISPLAY_INI_ENTRIES(); php_info_print_table_end(); @@ -172,6 +173,7 @@ array_init(return_value); add_assoc_long(return_value, "num_slots", info->num_slots); + add_assoc_long(return_value, "ttl", info->ttl); add_assoc_long(return_value, "num_hits", info->num_hits); add_assoc_long(return_value, "num_misses", info->num_misses); @@ -191,6 +193,7 @@ add_assoc_long(link, "mtime", p->mtime); add_assoc_long(link, "creation_time", p->creation_time); add_assoc_long(link, "deletion_time", p->deletion_time); + add_assoc_long(link, "access_time", p->access_time); add_assoc_long(link, "ref_count", p->ref_count); add_next_index_zval(list, link); } @@ -212,6 +215,7 @@ add_assoc_long(link, "mtime", p->mtime); add_assoc_long(link, "creation_time", p->creation_time); add_assoc_long(link, "deletion_time", p->deletion_time); + add_assoc_long(link, "access_time", p->access_time); add_assoc_long(link, "ref_count", p->ref_count); add_next_index_zval(list, link); }
« previous php.pecl.cvs (#1637) next »