How to troubleshoot performance difference between 2 web servers? - php

I have a production virtual web server that is being migrated to a new virtual web server on the same local network. The problem is that there is a performance problem on the new server.
For example, there is one page that loads in about 1 second on the original server, but takes over 25 seconds to load on the new one. I have already ruled out the database connection as the problem.
Both servers are Ubuntu Apache servers running PHP. There are slight differences in the versions of the servers, I will list as best I can here.
My main question is: is there a general way to profile the web requests on each server?
Similar to the way I can profile a python script or function and get a break-down of which parts of the program take the most time, I would like to profile the web requests on one server compared to the other.
Of course a web requests to the server are fundamentally different than programs run on a local computer, but I need to find where the bottleneck is. Any help is greatly appreciated.
Old Server Config
Ubuntu 14.04 - PHP version 5.5.9
New Server Config
Ubuntu 16.04 - PHP version 5.6.31 (also tested with version 7, same result)

I would suggest to log PHP script execution time.
If it comes from somewhere in the PHP execution, you will notice it easily.
Do a log at the start and one at the end. Then you can stress test both and see different execution time.
I seriously doubt the problem comes from PHP but if you do that you could also see differences with PHP7 which should be 30% faster.

Related

Laravel connection stays open too long

I am developing a PHP laravel application. I noticed that it is too slow and after careful debugging I realized that the processing is not slow, but the problem is that the connection takes too long to be terminated and so in this time it does not accept a new request.
The following figure shows the performance analysis of a request. Regardless of the type of request, it takes 20-30 seconds to close a connection.
The following figure shows the logs of the local run. The first request was accepted and the second only after the first one was closed, which took more than 20 seconds, although the response comes back in a few milliseconds.
Does anyone know how to fix this?
There is not a lot to go on in your question, however one thing we can see from the log messages is that you are using the PHP built-in server (or php artisan serve which uses it). This is well known to be very slow, single-threaded, and can cause PHP applications to stall:
Should I rely on "php artisan serve" for a locally based project?
PHP built-in web server running very slow
Using the PHP built-in server in production
Max concurrent connections for php's built in development server
Presumably this is your local dev environment - the PHP docs warn not to use the built-in server on the public internet:
Warning
This web server is designed to aid application development. It may also be useful for testing purposes or for application demonstrations that are run in controlled environments. It is not intended to be a full-featured web server. It should not be used on a public network.
Using nginx or Apache and PHP on your production server you should see much better performance. For local development you might be better off setting up Docker, or WAMP, or XAMPP, or the servers included with your distro if you're on some flavour of *nix.

Slow queries between servers

Good morning to everybody, I would like to ask about a problem I have and which I'm not able to solve it.
I have two servers, one is the web server (it contains a large web application) and the other one is the BD server.
The problem is that both are virtualized in a physical server with VMWare and they were running correctly until two weeks ago. In the start of this month we noticed that the web application ran very slow and we started to investigate what was the problem. We have tried a lot of things and we do not know what is the problem and, of course, how to solve it.
Both servers has an internal IP and only web server is accessible from Internet. Only web server access to BD server in order to get the results of queries. It's true that web server and BD server has an older versions of PHP and MySQL respectively.
We did the following tests:
Analyze the consumption of both servers. They are in 1% of memory, swap and al types of consumptions. Our physicial server is new from a year ago and both virtual servers does not use more than 5% of their resources.
Reboot both servers
Reboot physical server (VMWare server)
Restore a backup from 1 and 2 months ago of both servers to discard code and BD data errors
Review code (we do not touch code from before the error)
We did some queries from terminal's webserver and they were fast. We looked for the BD log and we could see that queries have been doing one by one in a "slow" velocity (0,5s for query aprox, depending on the query it can be more than a second).
We suspect that PHP is doing something bad, but we do not touch the code and we do not update PHP version or MySQL version. We want to try to update MySQL version in a new virtual machine and migrate all the data there, but we think it will not solve the problem.
The connection between servers is perfect and we think that layer 2 should not be the problem. In the same webserver we have another web application (Moodle) that connects to this BD server too, and it does not have this problem...
What can be the problem? It's very strange this change of behaviour of the web application. We were on holidays on August and we returned and we found this problem.
For more information we use PHP 5.6.40 (webserver) and MySQL Ver 14.14 Distrib 5.1.60, readline 5.1 (BD server). (yes, we know they are old versions but the web application and BD are old too)
I hope someone can help us, we are a little bit lost.
Thanks for your help!
I'd try updating your servers for one, issues like these are commonly caused by older software.
I'd also start logging or looking into loads so you can determine whatever causes the slow speeds you're getting.

How to debug a site move, for a PHP5/MySQL web application

I have been running a PHP site for years on my own servers. I recently purchased a dedicated server package and am trying to move my site to the dedicated server. I recently upgraded to PHP 5, and my current server is running PHP 5.6.16. I moved the files and the database, and put it in a live test domain, but the site is not functioning properly on the new dedicated server. Several key scripts are non-functional. I made sure that the dedicated server is running a version of 5.6. I have configured it to the same settings I have on the old server. I can see that the site is talking to the MySQL database. I turned on error reporting and I see no significant errors suggesting why these important scripts are now non-functional. I made sure the include path is there, and if it wasn't nothing would work. What am I overlooking? What could be different between one server and the other that might impact PHP functionality? I'm basically at my wits end here, so if these seems stupid please forgive me, but I don't know where to look next.
Start with the basics.
Does your web server respond to static page requests?
Is your web server configured to use PHP?
Can your web server execute and/or connect to PHP?
If you have a simple script with <?php phpinfo(); in it, does it work?
Are all the expected modules there in your phpinfo() output?
Do you have rewrite rules that need to be reconfigured? (Check your web server error log. Check your response status codes.)
Assuming PHP is all good, move into your application.
Are you absolutely sure error logging is on? (Again, check phpinfo() output. Try to force an error, maybe a syntax error or something and see if you see the error.)
How do you know your application is connecting to MySQL?
Start with a basic script that just echos some things.
Comment out large swaths of code and see if you can narrow down the problem that way, re-enabling chunks as you go. (You want to bi-sect the problem, cutting in half and in half and in half until you figure out exactly what the issue is.)
Other system-level things to check...
File system permissions? (See also https://serverfault.com/questions/48587/is-there-a-linux-log-for-when-a-user-is-denied-access-to-files-due-to-permission, for Linux.)
Firewalls? (Are you sure you can actually access MySQL over the network?)
Disk? (Are you out of space? Are your partitions set up correct? Is /tmp full?)
Once you figure out the problem, some advice:
Do this sort of thing regularly. Write a provisioning script to build yourself a new machine from one command, and do it regularly. These days with cloud providers (physical hardware or not) there's no reason you can't blow away your application servers on a regular basis, and re-provision them. Consider making this your system upgrade strategy. (Why reboot to get a new kernel when you can just have a whole new server with the new kernel and other patches, that you can cut over to?)
Ensure your development environment closely matches your production environment. (Consider Vagrant for this.)
You're using version control, right? If not, start using version control so that you can hack on your code for things like this and easily roll back when done.

Apache deflate and progressive HTTP response

I work on an e-commerce website and we have important performances difference between our production server and our test server.
Both are VM running on Windows Server 2008 R2 64bits with WampServer 2.5 (Apache 2.4.9 / PHP 5.5.12).
(Note : I know that WampServer is not for production uses, but at this time it's still the best solution for us as we highly depend on Windows environment for our databases and other stuff. We tried to optimize Apache & PHP configuration for production, and we replicated that conf on our test server, so we have the same environment on both machines.)
Everything was running okay from there, until today. We were attempting to improve Apache files compression configuration (disabling it on images, enabling on html files, etc) when we noticed a major difference between the two servers.
On the same page (for test needs : an huge products list with a lot of content and images to display), same request, same user, same browser :
The production server seems to "prepare" the whole document before sending it. During several seconds I've to wait and watch a blank browser, then all shows up instantly. In Chrome Dev Tools, Waiting time is around 7 sec and Receiving time around 50 msec.
The test server seems to do just the opposite : no blank page during seconds, the header is displaying very quickly and the rest of the content comes step by step while I can already browse the page. Waiting time is around 200 msec and Receiving time around 11 sec.
On my own development machine, I can observe both situations when I toggle Apache's configuration for mod_deflate.
So after several attempts, we just disabled the mod_deflate on the production server, and then on the test server. Both have the exact same configuration, and still there is this big difference.
I also looked on php.ini files, thinking about cache issues or something like that, but same deal here : both configuration files are matching but the two servers are still working differently.
We spent hours searching answers on the web, but nothing seems to work...
Please, can somebody help us on that ?

MongoDB connectivity with PHP dropping after idle time

I'm building a webapp with MongoDB/PHP, and everything's going great... except one thing.
My database connection is flaky. After X amount of time, when I refresh the page I get errors because queries are failing. I check mongod.exe and what I see is "Connection accepted from 127.0.0.1" - then I go back, refresh again, and everything's running all well and good.
What could be causing this? Database connectivity issues are something I never had to deal with in MySQL - but that's a whole different beast.
I would highly recommend you do your development with mongodb in a unix environment as they update the code the most often and you won't have to worry about strange bugs. Long ago i decided that doing dev in windows was much too inconvenient and moved my work environment to linux. If this sounds daunting, you might look into running a virtual machine with a local mount via samba such that you can run directly on a linux server on your local machine. Then you will have an environment similar to your production env. Hope this is helpful.

Categories