From e2a6404c3c816311aedaa9c06ffef71f0405309a Mon Sep 17 00:00:00 2001 From: Ulf Wendel Date: Wed, 11 Jan 2012 21:59:45 +0000 Subject: [PATCH] Slam defense description. Still a good number of undocumented features. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@322100 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/mysqlnd_qc/quickstart.xml | 87 ++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 9 deletions(-) diff --git a/reference/mysqlnd_qc/quickstart.xml b/reference/mysqlnd_qc/quickstart.xml index 110d349a44..2447237855 100644 --- a/reference/mysqlnd_qc/quickstart.xml +++ b/reference/mysqlnd_qc/quickstart.xml @@ -69,21 +69,31 @@ entries among clients. - - - default (built-in): process memory, scope: process, one or more web requests depending on PHP deployment model used + + + + default (built-in): process memory, scope: process, one or more web requests depending on PHP deployment model used + - APC: shared memory, scope: single server, multiple web requests + + APC: shared memory, scope: single server, multiple web requests + - SQLite: memory or file, scope: single server, multiple web requests + + SQLite: memory or file, scope: single server, multiple web requests + - MEMCACHE: main memory, scope: single or multiple server, multiple web requests + + MEMCACHE: main memory, scope: single or multiple server, multiple web requests + - user (built-in): user-defined - any, scope: user-defined - any + + user (built-in): user-defined - any, scope: user-defined - any + @@ -95,7 +105,7 @@ However, it is recommended to pick one storage handler and use it for all cache entries. - Built-in slam defence to avoid overloading + Built-in slam defense to avoid overloading To avoid overload situations the cache plugin has a built-in slam defense mechanism. @@ -104,7 +114,7 @@ access the database server concurrently. In the worst case, the database server becomes overloaded and it takes more and more time to refresh the cache entry, which in turn lets more and more clients try to refresh the cache entry. To prevent - this from happening the plugin has a slam defence mechanism. If slam defense is + this from happening the plugin has a slam defense mechanism. If slam defense is enabled and the plugin detects an expired cache entry it extends the life time of the cache entry before it refreshes the cache entry. This way other concurrent accesses to the expired cache entry are still served from the cache for a certain @@ -651,6 +661,65 @@ Script runtime : 3 seconds +
+ Slam defense + + A badly designed cache can do more harm than good. In the worst case a cache + can increase database server load instead of minimizing it. An overload situation + can occur if a highly shared cache entry expires. + + + Cache entries are shared and reused to a different degree depending on + the storage used. The default storage handler stores cache entries in process memory. + Thus, a cache entry can be reused for the life-span of a process. Other PHP + processes cannot access it. If Memcache is used, a cache entry can be shared + among multiple PHP processes and even among multiple machines, depending on the + set up being used. + + + If a highly shared cache entry stored, for example, in Memcache expires, many + clients gets a cache miss. Many client requests can no longer be served from + the cache but try to run the underlying query on the database server. Until + the cache entry is refreshed, more and more clients contact the database server. + In the worst case, a total lost of service is the result. + + + The overload can be avoided using a storage handler which limits the reuse of cache + entries to few clients. Then, at the average, its likely that only a limited number + of clients will try to refresh a cache entry concurrently. + + + Additionally, the built-in slam defense mechanism can and should be used. If + slam defense is activated an expired cache entry is given an extended life time. + The first client getting a cache miss for the expired cache entry tries to + refresh the cache entry within the extended life time. All other clients requesting + the cache entry are temporarily served from the cache although the original + TTL of the cache entry has expired. The other clients will + not experience a cache miss before the extended life time is over. + + + + + + + + + + The slam defense mechanism is enabled with the PHP configuration directive + mysqlnd_qc.slam_defense. + The extended life time of a cache entry is set with + mysqlnd_qc.slam_defense_ttl. + + + It is not possible to give a one-fits-all recommendation on the slam defense + configuration. Users are advised to monitor and test their setup and derive + settings accordingly. + +
+
Procedural user-defined storage handler