Note: 锟芥本锟斤拷锟斤拷
锟斤拷锟斤拷锟斤拷要 PECL/mysqlnd_ms 1.3.0-beta 锟斤拷锟较版本锟斤拷锟斤拷 PECL/mysqlnd_qc 1.1.0-alpha 锟斤拷锟较版本锟斤拷PECL/mysqlnd_ms 锟斤拷锟斤拷锟斤拷锟斤拷时锟斤拷支锟斤拷锟斤拷锟斤拷锟斤拷埽锟斤拷锟揭� PHP 5.4.0 锟斤拷锟较版本锟斤拷
Note: Setup: extension load order
PECL/mysqlnd_ms 锟斤拷锟斤拷锟斤拷 PECL/mysqlnd_qc 前锟斤拷装锟截★拷
Note: 锟斤拷锟斤拷锟饺讹拷锟斤拷
锟教承的伙拷锟斤拷锟结供 beta 品锟绞★拷
Note: 锟斤拷锟矫碉拷 MySQL 锟斤拷群
锟斤拷锟斤拷锟斤拷锟斤拷锟揭� MySQL 锟斤拷锟斤拷同锟斤拷锟结供支锟街o拷目前锟斤拷支锟斤拷锟斤拷锟斤拷锟斤拷 MySQL 锟斤拷群锟斤拷式锟斤拷锟斤拷锟斤拷锟斤拷锟� 锟斤拷锟斤拷突锟斤拷瞬锟窖拷锟斤拷妫拷没锟斤拷锟斤拷锟斤拷侄锟斤拷锟斤拷锟� PECL/mysqlnd_qc锟斤拷
Support for MySQL replication clusters (asynchronous primary copy) is the main focus of PECL/mysqlnd_ms. The slaves of a MySQL replication cluster may or may not reflect the latest updates from the master. Slaves are asynchronous and can lag behind the master. A read from a slave is eventual consistent from a cluster-wide perspective.
The same level of consistency is offered by a local cache using time-to-live (TTL) invalidation strategy. Current data or stale data may be served. Eventually, data searched for in the cache is not available and the source of the cache needs to be accessed.
Given that both a MySQL Replication slave (asynchronous secondary) and a local TTL-driven cache deliver the same level of service it is possible to transparently replace a remote database access with a local cache access to gain better possibility.
As of PECL/mysqlnd_ms 1.3.0-beta the plugin is capable of transparently controlling PECL/mysqlnd_ms 1.1.0-alpha or newer to cache a read-only query if explicitly allowed by setting an appropriate quality of service through mysqlnd_ms_set_qos(). Please, see the quickstart for a code example. Both plugins must be installed, PECL/mysqlnd_ms must be compiled to support the cache feature and PHP 5.4.0 or newer has to be used.
Applications have full control of cache usage and can request fresh data at any time, if need be. Thec ache usage can be enabled and disabled time during the execution of a script. The cache will be used if mysqlnd_ms_set_qos() sets the quality of service to eventual consistency and enables cache usage. Cache usage is disabled by requesting higher consistency levels, for example, session consistency (read your writes). Once the quality of service has been relaxed to eventual consistency the cache can be used again.
If caching is enabled for a read-only statement, PECL/mysqlnd_ms may inject SQL hints to control caching by PECL/mysqlnd_qc. It may modify the SQL statement it got from the application. Subsequent SQL processors are supposed to ignore the SQL hints. A SQL hint is a SQL comment. Comments must not be ignored, for example, by the database server.
The TTL of a cache entry is computed on a per statement basis. Applications set an maximum age for the data they want to retrieve using mysqlnd_ms_set_qos(). The age sets an approximate upper limit of how many seconds the data returned may lag behind the master.
The following logic is used to compute the actual TTL if caching is enabled. The logic takes the estimated slave lag into account for choosing a TTL. If, for example, there are two slaves lagging 5 and 10 seconds behind and the maximum age allowed is 60 seconds, the TTL is set to 50 seconds. Please note, the age setting is no more than an estimated guess.
The algorithm may seem expensive. SHOW SLAVE STATUS is a very fast operation. Given a sufficient number of requests and cache hits per second the cost of checking the slaves lag can easily outweight the costs of the cache decision.
Suggestions on a better algorithm are always welcome.