Mysqlnd query result cache plugin (
mysqlnd_qc
)
2668
is_select( CREATE TABLE test(id INT)): do not cache
is_select( INSERT INTO test(id) VALUES (1), (2), (3)): do not cache
is_select( SELECT id FROM test WHERE id = 1): cache
is_select( SELECT id FROM test WHERE id = 1): cache
is_select( SELECT * FROM test): cache
Cache put: 2
Cache hit: 1
The examples callback tests if a statement string matches a pattern. If this is the case, it either returns
TRUE
to cache the statement using the global default TTL or an alternative TTL.
To minimize application changes the callback can put into and registered in an auto prepend file.
20.7.7.4.6. Slam defense
Copyright 1997-2012 the PHP Documentation Group. [2230]
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 stampeding).
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.
Example 20.312. Enabling the slam defense mechanism
mysqlnd_qc.slam_defense=1
mysqlnd_qc.slam_defense_ttl=1
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
.
The function
mysqlnd_qc_get_core_stats
returns an array of statistics. The statistics
slam_stale_refresh
and
slam_stale_hit
are incremented if slam defense takes place.
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.
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...