|
StatisticsUsing Statistical Data MySQL Native Driver contains support for gathering statistics on the communication between the client and the server. The statistics gathered are of three main types:
If you are using the mysqli extension, these statistics can be obtained through three API calls:
Accessing Client Statistics To access client statistics, you need to call mysqli_get_client_stats(). The function call does not require any parameters. The function returns an associative array that contains the name of the statistic as the key and the statistical data as the value. Client statistics can also be accessed by calling the phpinfo() function. Accessing Connection Statistics To access connection statistics call mysqli_get_connection_stats(). This takes the database connection handle as the parameter. The function returns an associative array that contains the name of the statistic as the key and the statistical data as the value. Accessing Zval Cache Statistics The MySQL Native Driver also collects statistics from its internal Zval cache. These statistics can be accessed by calling mysqli_get_cache_stats(). The Zval cache statistics obtained may lead to a tweaking of php.ini settings related to the Zval cache, resulting in better performance. Buffered and Unbuffered Result Sets Result sets can be buffered or unbuffered. Using default settings, ext/mysql and ext/mysqli work with buffered result sets for normal (non prepared statement) queries. Buffered result sets are cached on the client. After the query execution all results are fetched from the MySQL Server and stored in a cache on the client. The big advantage of buffered result sets is that they allow the server to free all resources allocated to a result set, once the results have been fetched by the client. Unbuffered result sets on the other hand are kept much longer on the server. If you want to reduce memory consumption on the client, but increase load on the server, use unbuffered results. If you experience a high server load and the figures for unbuffered result sets are high, you should consider moving the load to the clients. Clients typically scale better than servers. "Load" does not only refer to memory buffers - the server also needs to keep other resources open, for example file handles and threads, before a result set can be freed. Prepared Statements use unbuffered result sets by default. However, you can use mysqli_stmt_store_result() to enable buffered result sets. Statistics returned by MySQL Native Driver The following tables show a list of statistics returned by the mysqli_get_client_stats(), mysqli_get_connection_stats() and mysqli_get_cache_stats() functions. Network
Result Set
Connection
COM_* Commands
Miscellaneous
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||