MySQL Performance Optimization - A Lesson MySQL Performance Optimization - Una lezione
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
Filed under Elencato sotto CMS Software CMS Software , Database Banca dati , Headline News Headline News , How To Come , Pro Blogging Pro Blogging , RDBMS , Tech Note Nota tech , Web , WordPress | |
| |
RSS 2.0 RSS 2,0 | |
Email this Article Invia questo articolo
You may also like to read Si può anche leggere come |





May 10th, 2006 at 2:22 am 10 maggio 2006 alle 2:22 am
Hello, Ciao,
My wordpress just crashied my semi-dedicated server due to high CPU load.. Il mio wordpress solo crashied mio semi-server dedicato a causa di elevato carico della CPU ..
So I just installed the WP-Cache plugin and found this blog.. Così ho appena installato il WP-Cache plugin e trovato questo blog .. I asked my webhosting admin to do this optimization and here’s what he wrote me: Ho chiesto a mia webhosting admin di fare questa ottimizzazione e ecco ciò che ha scritto di me:
I checked all of your files for the text “SELECT distinct cat_ID”, and couldn’t find a match. Ho controllato tutti i file per il testo "SELECT cat_ID distinti", e non poteva trovare una corrispondenza.
I also checked for “SELECT cat_ID, cat_name AS Category, count(” and couldn’t find a match either. Ho anche controllate per "SELECT cat_ID, cat_name come categoria, count (" e non poteva trovare una corrispondenza.
I also checked for “st_post2cat” and couldn’t find it, so they may be running a different version of the code. Ho anche controllate per "st_post2cat" e non poteva trovare, in modo tale che essi possono essere in esecuzione una versione diversa del codice.
I was just wondering if you could help me regarding this matter. Mi è stato solo chiedendo se potesse aiutarmi per quanto riguarda questa materia. BTW, I’m running wordpress 2.0.2 BTW, sono in esecuzione wordpress 2.0.2
Thank you for your time…you can just reply this to my e-mail.. Grazie per il vostro tempo… si può semplicemente rispondere a questa mia e-mail ..
Regards, Saluti,
Paulus
May 10th, 2006 at 6:20 am 10 maggio 2006 alle 6:20 am
The code was specified only as an example. Il codice è stato specificato solo come un esempio. It is in a plugin I wrote for this blog. E 'in un plugin che ho scritto per questo blog. You will not find it in generic wordpress installation. Non troverete in generici wordpress installazione. However if you have a highly commented blog you may benefit from this Tuttavia, se avete un blog molto commentati si può beneficiare di questo wp-cache optimization technique WP-cache di ottimizzazione tecnica .
June 23rd, 2006 at 4:08 pm 23 giugno 2006 alle 4:08 pm
I too am on Westhost and have been working with people like Jonny to find a solution to my blog problems. Anch'io sono a Westhost e hanno lavorato con persone come Jonny per trovare una soluzione al mio blog problemi. I too am using WP-Cache, but now my blog is consuming 4.52% of the entire server from my VPS. Anch'io sto usando WP-Cache, ma ora il mio blog è che consumano 4,52% di tutto il server dal mio VPS. Ia m not as technical as you, so we have slow-going, but I will post any solution I find. M ia non come tecnico, come voi, perché abbiamo lento corso, ma mi post qualsiasi soluzione trovare.
Tks! TKS!