Ciao a tutti,
mi sto arrovellando negli ultimi tempi con un mio sito. Soffre infatti di down momentanei, che credo che sia il server che si riavvia o cose del genere (è un vps managed, perchè non me ne intendo troppo di questo aspetto). Questo sito fa dalle 7.000 alle 20.000 visite al giorno, ma i down arrivano anche di notte o in momenti di scarsissimo traffico, mentre magari regge quando dentro ci sono 250-300 utenti contemporaneamente.
Ho scritto all'assistenza che mi ha risposto in questo modo (per altro dicendomi che non risolverei il problema facendo un upgrade di ram o altro). Ho capito che c'è questa query che mi succhia un sacco di risorse e fa sballare il server. Quello che non saprei fare è risolvere il problema! :p Suggerimenti?
Hello,
I have checked the server in detail. I could find that the httpd was creating large number of semaphore arrays. Please see the results below.
--
root@host [~]# ipcs -s | head
------ Semaphore Arrays --------
key semid owner perms nsems
0x00000000 41025536 nobody 600 1
0x00000000 41058305 nobody 600 1
0x00000000 41091074 nobody 600 1
0x00000000 41123843 nobody 600 1
0x00000000 62029828 nobody 600 1
0x00000000 62062597 nobody 600 1
0x00000000 62095366 nobody 600 1
root@host [~]# ipcs -s | wc -l
56
--
I have removed the semaphores and restarted the Apache now. Please see the results below.
--
root@host [~]# ipcs
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
------ Semaphore Arrays --------
key semid owner perms nsems
0x00000000 112099328 nobody 600 1
0x00000000 112132097 nobody 600 1
0x00000000 112164866 nobody 600 1
0x00000000 112197635 nobody 600 1
------ Message Queues --------
key msqid owner perms used-bytes message
--
On further checking the server, I could see that the MySQL queries associated with the database "zonawres_zwdb" is causing the issue. Please see the results below.
--
root@host [~]# mysqladmin proc stat
+----------+---------------+-----------+---------------+---------+------+----------------------+------------------------------------------------------------------------------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----------+---------------+-----------+---------------+---------+------+----------------------+------------------------------------------------------------------------------------------------------+
| 12700853 | zonawres_zwus | localhost | zonawres_zwdb | Query | 0 | Copying to tmp table | SELECT jg.id,
jg.catid,
jg.imgthumbname,
jg |
| 12700854 | zonawres_zwus | localhost | zonawres_zwdb | Sleep | 3 | | |
| 12700855 | zonawres_zwus | localhost | zonawres_zwdb | Query | 0 | Copying to tmp table | SELECT jg.id,
jg.catid,
jg.imgthumbname,
jg |
| 12700856 | zonawres_zwus | localhost | zonawres_zwdb | Sleep | 3 | | |
| 12700857 | zonawres_zwus | localhost | zonawres_zwdb | Sleep | 3 | | |
| 12700858 | zonawres_zwus | localhost | zonawres_zwdb | Sleep | 3 | | |
| 12700859 | zonawres_zwus | localhost | zonawres_zwdb | Query | 0 | Copying to tmp table | SELECT jg.id,
jg.catid,
jg.imgthumbname,
jg |
| 12700863 | zonawres_zwus | localhost | zonawres_zwdb | Query | 0 | Copying to tmp table | SELECT jg.id,
jg.catid,
jg.imgthumbname,
jg |
| 12700864 | zonawres_zwus | localhost | zonawres_zwdb | Sleep | 1 | | |
| 12700865 | zonawres_zwus | localhost | zonawres_zwdb | Sleep | 0 | | |
| 12700879 | zonawres_zwus | localhost | zonawres_zwdb | Sleep | 0 | | |
| 12700882 | zonawres_zwus | localhost | zonawres_zwdb | Sleep | 0 | | |
| 12700883 | root | localhost | | Query | 0 | | show processlist |
+----------+---------------+-----------+---------------+---------+------+----------------------+------------------------------------------------------------------------------------------------------+
Uptime: 8125841 Threads: 13 Questions: 262269011 Slow queries: 2970 Opens: 272680 Flush tables: 1 Open tables: 64 Queries per second avg: 32.276
--
At the end of this query, you can see that the MySQL function "ORDER BY rand() ASC LIMIT" is executed. This query will cause performance overheads and this query can be optimized.
Please visit the following links to know more about this.
Please contact a database programmer to optimize this query so that it will use minimum amount of server resources.
Please let us know if you have any further concerns.