The MySQL database supporting this blog was consuming massive amount of CPU, which effectively lead to site going down 3-4 times this week. Il database MySQL sostenere questo blog è stato enorme consumo di CPU, che effettivamente portare a sito che scende 3-4 volte questa settimana. I knew an obvious culprit. Sapevo un evidente colpevole. However reality differed. Tuttavia realtà diversa.

I knew for sometime I had a jumbo query, which was not cached, and is likely to contribute to MySQL server load: Sapevo per qualche volta ho avuto un jumbo della query, che non è stato memorizzato nella cache, e può contribuire a carico del server MySQL:
SELECT cat_ID, cat_name AS Category, count( * ) AS ‘Count’ SELECT cat_ID, cat_name come categoria, count (*): 'Conte'
FROM $wpdb->categories, $wpdb->post2cat, $wpdb->posts Da $ wpdb-> categorie, $ wpdb-> post2cat, $ wpdb-> post
WHERE cat_ID = category_id and DOVE cat_ID e category_id =
category_nicename != ‘headline’ and ID = post_id and category_nicename! = 'intestazione' e ID = post_id e
post_status = ‘publish’ post_status = 'pubblicare'
GROUP BY cat_name GROUP BY cat_name
HAVING count( * ) > 10 CON count (*)> 10
ORDER BY ‘Count’ DESC ORDINA PER 'Conte' DESC
LIMIT 0 , 10 LIMIT 0, 10

I couldn’t see an obvious way to optimize this without curbing the functionality. Non riuscivo a vedere un evidente modo di ottimizzare questo senza frenare la funzionalità. In case you are wondeering substituting category_nicename != ‘headline’ with cat_ID = 37 doesn’t help. Nel caso in cui si sono wondeering sostituire il category_nicename! = 'Headline' con cat_ID = 37 non aiuta.

I also thought about using Ho anche pensato di usare slow query log query lente di log to pinpoint the problem. di individuare il problema. Fortunately none of them was required. Fortunatamente nessuno di loro è stato richiesto. I got an email from friendly Ho ottenuto una email da amichevole WestHost High Load support. Elevato carico di sostegno. Jonny found out by repeatedly running ‘SHOW FULL PROCESSLIST;’ that the culprit was: Jonny scoperto ripetutamente in esecuzione di 'Mostra COMPLETA PROCESSLIST;' che il colpevole è stato:

SELECT distinct cat_ID, cat_name SELECT cat_ID distinti, cat_name
FROM st_categories, st_post2cat DA st_categories, st_post2cat
ORDER BY category_nicename; ORDINA PER category_nicename;

This took me by surprise. Questo mi ha colto di sorpresa. Th query takes anywhere between 3-5 seconds. ° ricerca prende ovunque tra 3-5 secondi. In high loads with multiple simultaneous requests that is good enough to overload the server. In alto con carichi più richieste simultanee che è abbastanza buono sovraccaricare il server. The solution was deceptively simple: La soluzione è stata semplice:

SELECT distinct cat_ID, cat_name SELECT cat_ID distinti, cat_name
FROM st_categories DA st_categories
ORDER BY category_nicename; ORDINA PER category_nicename;

The original query was redundant and wasteful. La query originale è stato ridondante e sprechi. Originally I intended to display only categories with one or more posts in them. I originariamente destinato a visualizzare solo le categorie con uno o più posti in loro. However somewhere down the line I forgot to add the WHERE clause. Tuttavia da qualche parte in giù la linea mi sono dimenticato di aggiungere la clausola WHERE. Today all my categories have posts. Oggi tutti i miei categorie sono posti. So simply removing st_post2cat from the FROM list is good enough to bring down the execution time to 0.01 seconds. In modo semplice eliminazione dal st_post2cat dalla lista è sufficiente per ridurre il tempo di esecuzione di 0,01 secondi.

The take home lessons are: Il portare a casa le lezioni sono:

  • Never guess bottleneck queries; find it. Mai indovinare strozzatura richieste; trovarlo.
  • Simple tool like “SHOW FULL PROCESS LIST” is often as good as definitive, yet harder to analyze tool like slow query log. Semplice strumento come "SHOW PROCESSO ELENCO COMPLETO" è spesso buono come definitivo, ancora più difficile da analizzare come strumento di query lente di log.
  • Having good support from your Avendo un buon supporto dal tuo web hosting provider Web Hosting Provider doesn’t hurt either non sia male