1

I have one php file which is getting called very often for a session check of an external application. I don't know how many calls there are every second, but I think it may be like 20-100 calls every second.

However this .php file includes one SQL query which updates a single row. Once I don't outcomment these lines the whole database slows down a lot and in the end my forum is not reachable anymore. I think it is something like a server issue (for example to many IOPS?). Unfortunately I don't know how I can locate the exact reason for the slowdown, nor I don't know how I can determine how many calls I get every second for the php file.

This is the very simple SQL query (the where clause contains only the primary key):

UPDATE bot_sessions SET ip_address = :ip_address, renewal_count = renewal_count + 1
       WHERE username = :username AND session_token = :session_token

So two questions:

  1. How can I find out how often my specifc php-file is being called every second?
  2. How can I locate the reason that my whole database slows down once I use this Update Query?
3
  • If you observe high CPU in your SQL node, verify that the username and session_token fields are properly indexed. If your issue is disk IO related, you have few weapons apart from upgrading and resizing your system.
    – ma.tome
    Aug 23, 2015 at 21:56
  • The CPU usage in total is fine (5%), but for the mysql proccess it shows 135%. How can I verify that this is a disk io problem or not?
    – kentor
    Aug 23, 2015 at 22:00
  • Well, first you must know your system IO capacity to have some kind of baseline. Then, using the iostat command you can monitor your IO usage and check if your IO capacity is sufficient (or not). I would recommend you to deploy some kind of monitoring system like Munin, Ganglia, etc.. And gather some data for a couple of days. I'm pretty sure that having the graphed statistics will reveal your bottleneck quite easily.
    – ma.tome
    Aug 23, 2015 at 22:05

1 Answer 1

2

You should be able to find out how often a specific PHP file is being called by looking through the web server logs. There are a couple of other hacks - for example Using Google Analytics (which will be less accurate), or updating a file / counter (more resource intensive).

As @ma.tome said, monitoring your utilisation gives you a good place to start, and is generally useful. A Mysql process running at 135% means its using more then 1 CPU. (If you have 4 CPUs the total is 400%). Running vmstat will give you IO information.

Another thing to do might be to start logging query times in your database. Also, check your indexes - depending on your application, if its not already indexed you could get huge performance increases by creating an index for username in bot_sessions. (Not sure if username or session_token is the primary key you are specifying, may want to look at creating an index on the one which is not a primary key) - either way, the where clause contains more then just the primary key.

Also, your system may simply be running out of RAM. look at how much swap you are using - and, if required, throw more RAM at the problem or decrease vm.swappiness.

2
  • By checking the server logs it would be hard to see how many calls per seconds I have, because of course I also have tons of normal users browsing through the forum. Google Analytics is also hard because its just a php script running through once and especially external applications (= no browser) wont be shown in analytics. session_token and username together is a composited primary key. This should be fine or? This is what my RAM is showing: i.imgur.com/Y2nabBR.png
    – kentor
    Aug 24, 2015 at 0:28
  • Looks like your system is not swapping. Can't comment more on diagnosing the problem without further detail - is this code executed in a conditional loop ? What language is it in ? Why can't you pick out the relevant hits from the log file ? You probably need to look into your databases equivalent of the MYSQL "explain query". If you are using MySQL look at dev.mysql.com/doc/refman/5.0/en/explain.html
    – davidgo
    Aug 24, 2015 at 4:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .