0

I have 2 servesr both on a LAMP stack. Two servers running almost the same PHP code. And on the second server i have troubles with loading time, where ttfb is too high, sometimes it is up to 17 sec. The second one has more recent version of PHP, MySql and Apache also it has 3 times better specs, the database is 17 times smaller.

However it works much slover than first one ttfb 0.5 vs 17 sec. I'm 100% sure I'm the only visitor on the site. I've tried to track php exeecution time and it's on avarage 5 sec

<?php
$GLOBALS["start"]= microtime(true);

//mycode

$GLOBALS["end"]= microtime(true);
$execution_time = ($GLOBALS["end"] - $GLOBALS["start"]);
echo '<b>Total Execution Time:</b> '.$execution_time.' sec';

When i track CPU usage it always show that mysql process uses the most resources.htop screenshot

I've tried to repair and optimize my db but no improvements. Slow query log doesn't show me queries that current script executes. How can i fix this?

  • 1
    What is MySQL doing then? Use a tool like innotop to find out. – Michael Hampton Jun 26 at 18:23
  • Or SHOW FULL PROCESSLIST; – Rick James Jun 26 at 22:39
  • Decrease long_query_time to 1; it could be a lot of quick queries chewing up the CPU. But it smells more like a big ALTER or something. Do SHOW FULL PROCESSLIST;. Note: a long query does not get written to the slowlog until it finishes. Also: Pepper your code with more microtime and echo -- this can help you pin down what part of the code is slow. – Rick James Jun 26 at 22:43
  • Additional information request from your SLOW server. Post on pastebin.com and share the links. Text results of: B) SHOW GLOBAL STATUS; after minimum 24 hours UPTIME C) SHOW GLOBAL VARIABLES; D) SHOW FULL PROCESSLIST; E) complete MySQLTuner report AND Optional very helpful information, if available includes - ulimit -a for a linux/unix list of limits, iostat -xm 5 3 for IOPS by device and core/cpu count, for server workload tuning analysis. – Wilson Hauck Jul 5 at 21:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.