How to measure mySQL bottlenecks? -
what mysql server variables should looking @ , thresholds significant following problem scenarios:
- cpu bound
- disk read bound
- disk write bound
and each scenario, solutions recommended improve them, short of getting better hardware or scaling database multiple servers?
this complicated area. "thresholds" affect each of 3 categories overlap quite bit.
if having problems operations being cpu bound, need at: (a) structure of database - normalized. bad db structure leads complex queries hit processor. (b) indexes - needed queries sufficiently indexed. lack of indexes can hit both processor , memory hard. check indexes, "explain ...your query". row in resulting explanation says isn't using index, need @ closely , if possible, add index. (c) use prepared statements wherever possible. these can save cpu doing quite bit of crunching. (d) use better compiler optimizations appropriate cpu. 1 dedicated types, can glean odd percent here , there.
if having problems operations being read bound (a) ensure caching possible. check configuration variables query_cache_limit , query_cache_size. isn't magic fix, raising these can help. (b) above, check indexes. indexes reduce amount of data needs read.
if having problems operations being write bound (a) see if need indexes have. indexes good, trade-off them improving query time, maintaining indexes can impact time spent writing data , keeping them date. want indexes if in doubt, you're more interested in rapidly writing table in reading it. (b) make possible use of insert delayed "queue" writes database. note, not magic fix , inappropriate, in right circumstances can of help. (c) check tables heavily read , written @ same time, e.g. access list update's visitor's session data , read much. it's easy optimize table reading from, , writing to, not possible design table @ both. if have such case , it's bottleneck, consider whether it's possible split functions or move complex operations using table temporary table can update block periodically.
note, stuff in above has major effect, query design / indexing. beyond that, want start considering @ better hardware. in particular, can lot of benefit out of raid-0 array doesn't lot writing bound problems, can wonders read-bound problems. , can pretty cheap solution big boost.
you missed 2 items off list.
memory bound. if hitting memory problems must check can usefully indexed indexed. can @ greater connection pooling if reason you're using lot of discrete connections db.
network bound. if hitting network bound problems... aren't, if are, need network card or better network.
note, convenient way analyze db performance turn on log_slow_queries option , set long_query_time either 0 everything, or 0.3 or similar catch might holding database up. can turn on log-queries-not-using-indexes see if interesting shows up. note, sort of logging can kill busy live server. try on development box start.
hope that's of help. i'd interested in anyone's comments on above.
Comments
Post a Comment