0

I am making a chat application like facebook using PHP, MySql and Node.js( socket.io for real time chat) . The problem is my server load goes upto 10-15 when 20 people starts chatting. I am just inserting message on sender side and sending message id to receiver and receiver retrieve message info from DB. I am having a centos server having 4 physical and 4 logical cores(total 8 cores) and 16GB Ram. My website is built in zencart and there is also another problem when I press f5 for 1 minute on a static page the server load goes upto 10. Can anyone tell me what is the issue?

1 Answers1

0

Try logging what happens on the database with the general query log: http://dev.mysql.com/doc/refman/5.7/en/query-log.html

If you have a busy site with lots of users you might want to check out other solutions for your message system. Redis for instance has a pub/sub-system which you can use for sending out messages to multiple listeners.

Arno
  • 161
  • 10
  • thanks for answering. I have used query log and capture the queries that takes more time. The queries shown in the query log file takes less time in normal situation when I run them on my MySql – Muhammad Yaseen Mar 15 '16 at 14:03
  • Its possible that the query is cached when you run it separately. Try using explain on the queries that took the most time and see if indexes are used. If not, read about how to create useful indexes and add where necessary. – Arno Mar 15 '16 at 18:49
  • I can't make much indexes for my messages table because the more the indexes are it slows down the insertion and I got about 5000 messages to insert daily – Muhammad Yaseen Mar 17 '16 at 06:43
  • You are right about more indexes slowing down insertion, thats why you need to add only the right indexes. 5000 messages is not a whole lot btw. If your database servers has problemes processing that amount of queries you should try tuning your database or server. – Arno Mar 17 '16 at 08:12
  • Please have a look on the picture. There are multiple php-cgi processes and they are consuming too much cpu. https://drive.google.com/file/d/0B5oml0q1E5dHamVWZUctRnlHVEE/view?usp=sharing – Muhammad Yaseen Mar 17 '16 at 13:07
  • Withour further information it is impossible to pinpoint the problem of this high load. Your PHP processes consume a lot of CPU, but your database does as well. This can be related to slow storage for example, but this is just a wild guess. Try debugging your code with tools like xhprof to see what is happening on your server. – Arno Mar 17 '16 at 13:17
  • I am trying to install xhprof but getting error. Please have a look at this link and tell me if you know the solution. http://stackoverflow.com/questions/36078930/xhprof-not-working-wamp-2-2 – Muhammad Yaseen Mar 18 '16 at 08:19