0

We have a production nginx web server with php FPM. We ran a php script which updates a particular field in mysql database and mails some content using php mail function. This php script was executed from the command line. There were around 900 records, i.e, 900 times db was updated and php mail function was called. It took around 15 minutes to finish this script.

Problem: The problem was the nginx web server went unresponsive during these 15 minutes. I was under the impression that executing the php script in command line will not affect the http server, but for some reason server just hanged. Normally, our server throws a 502 bad gateway. But this time, the site showed the loading symbol and was just unresponsive. When we stopped the script, the site was up again.

  • What is the relation between the nginx http server and the script that was run on the command line which caused the server to go down ?
  • Is there any other system configurations like RAM etc a reason behind this downtime problem ?

Any pointers to this problem is greatly appreciated.

UPDATE: The script was using mysql persistent connections which lead to flooding of connections of mysql server reaching the max limit. Thanks for people in pointing me in the right direction.

palerdot
  • 113
  • 5
  • 3
    Not enough information. Wild guess: your php script locked DB, so website PHP connections to DB hands on waited – Alexey Ten Jul 11 '14 at 12:33
  • 1
    just nice/ionice the script and check for locks on the db, as Alexey Ten already mentioned. – Dennis Nolte Jul 11 '14 at 13:17
  • +1 to the above comments. – Alex Berry Jul 11 '14 at 13:24
  • @DennisNolte: can you explain a bit more on how to use `nice` for checking the locks on the db ? – palerdot Jul 11 '14 at 13:30
  • @palerdot nice is not for checking the locks, its for having the CPU load not blocking other cpu intensive tasks. so if you dont care how long the php script takes (make transactions, do some other cpu stuff, make some more transactions..) then you could "limit" the amount of CPU power available to the php script to be "all CPU - the one used by mysql) ionice does a similiar thing for IO. however: you should check first the DB locks when the script is running, and compare them to the locks when the php script is not running. Next step could be checking what your php code does with the DB. – Dennis Nolte Jul 11 '14 at 13:34
  • If your database is MySQL, you should also check the storage engine it uses. MyISAM locks the whole table, while InnoDB has row-level locking. So, if possible, the storage engine should be InnoDB. – Tero Kilkanen Jul 11 '14 at 14:04
  • @AlexeyTen I figured out that the script uses persistent connections leading to db locks. Thanks for pointing it out. – palerdot Jul 16 '14 at 14:08

0 Answers0