-2

I'm puzzled; I assume a slow query.

Note: all my queries are tested and run great when there`s less people using my app/website (less then 0.01sec each).

So I've some high cpu usage with my current setup and I was wondering why? Is it possible it's an index issue?

Our possible solution: we thought we could use an XML cache file to store the informations each hour, and then reduce the load on our MySQL query? (update files each hour).

Will it be good for us to do such things? Since we have an SSD drive? Or will it be slower then before?

Currently in high traffic time, our website/app can take up to 30 seconds before return the first byte. My website is running under a Plesk 12 server.

UPDATE Here's more informations about my mysql setup.. http://pastebin.com/KqvFYy8y

cloud1250000
  • 45
  • 1
  • 8
  • 3
    How can anything take 300% of the CPU? What does high traffic constitute? How many people? We don't even know what your queries look like to tell you if something is wrong or not... Please post something more. – Muhammad Abdul-Rahim May 01 '15 at 20:48
  • You need to provide much more information about your setup here. Even then this might be an opinion based question with solutions that may or may not work for specific case. – Maximus2012 May 01 '15 at 20:49
  • I checked my cpu usage with top -s command and it does bust the 100% cpu, I guess it`s the load on different core ( 3 core means 300%)? Anyway.. as for my queries, I have already worked here to optimise them the best I could, Even paid someone to take a look at it... – cloud1250000 May 01 '15 at 21:01
  • I usually get around 3500 visitors a day, this shouldn`t be too hard for my current server.. my bandwidth isn`t used at all.. and the only thing I can think of is my query are slowing things down.. – cloud1250000 May 01 '15 at 21:04
  • 1
    Number of records? table schema? query? All there are needed to answer this. That is IF the query is the culprit. – Misunderstood May 01 '15 at 21:16
  • 1
    You posted your question 11 hours ago already. You should have gathered more technical metrics and information since then. Please update your question. Especially with the information you've been asked for in comments. – hakre May 02 '15 at 08:40
  • Hello, I've added the output of mysqltuner – cloud1250000 May 03 '15 at 20:50

2 Answers2

2

Is it possible it's an index issue?

Perhaps but not necessarily. You need first to identify which query is slow. You find that in the slow query log. Then analyze the query. This is explained in literature or you can contact a consultant / tutor for that.

We thought we could use an xml cache file to store the informations each hour.. and then reduce the load on our mysql query?

Well, cache invalidation is not the easiest thing to do, but with a fixed rythm every hour this seems easy enough. But take care that it will only help if the actual query you cache was slow. Mysql normally has a query cache built in, check if it is enabled or not first.

Will it be good for us to do such things?

Normally if the things to do are good, the results will be good, too. Sometimes even bad things will result in good results, so such a general question is hard to answer. Instead I suggest you gain more concrete information first before you continue to ask around. Sounds more like guessing. Stop guessing. Really, that's only for the first two minutes, after that, just stop guessing.

Since we have an ssd drive? Or will it be slower then before?

You can try to throw hardware on it. Again lierature and a consultant / tutor can help you greatly with that. But just stop guessing. Really.

hakre
  • 193,403
  • 52
  • 435
  • 836
1

I assume the query is not slow all the time. If this is true, the query is not very likely the problem.

You need to know what is using the CPU. Likely a runaway script with an infinite loop.

Try this:

<?php
header('Content-Type: text/plain; charset=utf-8');
echo system('ps auxww');
?>

This should return a list in this format:

USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND

Scan down the %CPU column and look for your user name in the USER column

If you see a process taking 100% CPU, you may want to get the PID number and:

system('kill 1234');  

Where 1234 is the PID

The mysql processes running at 441% and 218% seems very problematic.

Assuming this is a shared server, there may be another user running queries that is hogging the CPU. you may need to take that up with your provider.

I've been watching on one of my shared servers and the CPU for the mysql process has not gone over 16%.

MySQLTuner

From the link it appears you have heavy traffic.

  • The Tuner was running 23.5 minutes
  • Joins performed without indexes: 69863

69863 in 23.5 min. comes out to almost 50 queries per second.

Does this sound correct? Running a query with a JOIN 150 times per second.

Index JOIN Table

You have a query with a JOIN.

The tables are joined by column(s).

On the joined table add an index to the column that joins the two table together.

Misunderstood
  • 5,534
  • 1
  • 18
  • 25
  • Nothing under my username is using more then 10% of my cpu.. Here's the reason why I think its my queries... http://puu.sh/hxWsS/cfb665737d.png notice the 411, it`s the cpu usage... here`s another one http://puu.sh/hxWAN/415bb02da0.png – cloud1250000 May 01 '15 at 21:35
  • 1
    That is the mysql server running. A query would look more like: `USER 312967 0.0 0.0 197108 3368 pts/0 S+ Apr24 0:00 mysql` – Misunderstood May 01 '15 at 21:40
  • This is not on a shared server unfortunately.. This is running on a pretty fine vps server... I've updated my post with the output of mysqltuner.pl – cloud1250000 May 03 '15 at 20:52
  • Look at my post: Section titled: MySQLTuner – Misunderstood May 03 '15 at 21:31
  • I see... but is it possible to cache the query?? Isn't some caching possible to reduce the load? – cloud1250000 May 03 '15 at 22:00
  • My question is do the numbers sound correct???? 50 queries per second?? The BIG problem is the tables are not indexed properly. Everything is already cached. – Misunderstood May 03 '15 at 22:11
  • Well.. my app has more then 50000 downloads.. it may be correct?? Anyhow, i'll take a look again at my queries... Since I was sure they were okay, im clearly not in a position for that ahah – cloud1250000 May 03 '15 at 23:04
  • OK it's possible. That would account for the high CPU by the mysql process. Without knowing anything about your SQL query I cannot be very specific. See new update – Misunderstood May 03 '15 at 23:15
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/76838/discussion-between-cloud1250000-and-misunderstood). – cloud1250000 May 03 '15 at 23:50