0

I am trying to work out what part of a website is causing a CPU spike. What I have noticed is that when a javascript button is clicked to add an item to a cart it causes the CPU to spike to 30/40% and if there are 3 people doing this the CPU hits 100% and the site responds very slowly.

I am a bit stuck on how to debug this issue and to find what exactly is causing the issue.

Can anyone advise on any tools to use please?

Thanks in advance for any replies!

Tony
  • 775
  • 2
  • 8
  • 20
  • Can you show us the code that gets executed when that Ajax call is made ? – teeyo Dec 01 '17 at 09:36
  • 1
    With a "javascript button" Im guessing you are referring to a button creating a AJAX-request to your server. So the best place to start looking, is at the script that is being called when that ajax call is placed. If you need more details, you should look into xdebug to get insight on the performance – Ole Haugset Dec 01 '17 at 09:37
  • post ajax code here .. – K.B Dec 01 '17 at 09:37
  • You can always use https://github.com/gperftools/gperftools to perform a very low level profiling of things. – apokryfos Dec 01 '17 at 09:37
  • This can depend on many issues like slow system, not optimized javascript and/or php, slow internet connection, slow database server (assuming that you use one). You should try t check the execution time in [PHP](https://stackoverflow.com/questions/535020/tracking-the-script-execution-time-in-php) and [JS](https://stackoverflow.com/questions/313893/how-to-measure-time-taken-by-a-function-to-execute) – Filnor Dec 01 '17 at 09:38
  • 2
    How is not optimized javascript going to affect the cpu load on the server? Javascript is frontend, and will thus only affect the cpu load for the clients computer (with the exception of node.js). – Ole Haugset Dec 01 '17 at 09:48
  • So I have check PHP, looks good, DB is optimised and there are no slow queries etc. Also I am not sure how the javascript can cause this as its frontend, the only thing I can think of is its interaction with the PHP code causing some problems, just not really sure how to check performance for it etc – Tony Dec 01 '17 at 09:59
  • Do you have the code for the event handler? – ptts Dec 01 '17 at 10:17
  • @Tony you say you have checked PHP code and DB and you claim that it's optimized, however the fact still remains that there's **server** CPU spikes caused by users interacting with your page. Those two claims are contradicting. – apokryfos Dec 01 '17 at 10:25
  • @apokryfos I dont claim the code is optimized :) It was written a few years ago by someone else. Ive cast my eye over the PHP and it looks like old code, but ok to me. Also I have optimized the db and that seems to be running fine, no slow queries etc. Javascript on the other hand i do not know in any great depth. I guess what I am looking for is an app or a method to monitor how the javascript runs and interacts to see if this is where the problem is. – Tony Dec 02 '17 at 11:09
  • 1
    Here's how this works. If you have a code specific question you need to show us your code. If you just want us to recommend tools or libraries for debugging or performance then that is off-topic here. There's google for that. – apokryfos Dec 02 '17 at 12:14

0 Answers0