Azure web app slow server response time

2019-08-04 12:56发布

问题:

I have Basic (Small) tier Azure Web App hosted in West Europe with a Basic SQL Database in the same region. Always On is turned on. Note that my website's target audience is in Europe.

Note that the website is CodeIgniter based and runs on php 5.6.

The page loads really slowly, even though on local environment everything is fast. After running PageSpeed Insights on my site I get the following assessment:

Reduce server response time In our test, your server responded in 1.7 seconds. There are many factors that can slow down your server response time. Please read our recommendations to learn how you can monitor and measure where your server is spending the most time.

When inspecting the site from developer toolsI get a similar picture:

As you can see the initial response is really bad. What could be the problem?

UPDATE/SOLUTION

Taking the advice of Gary Liu - MSFT's from the comments, namely enabling pconnect in the database.php the load time of the page went down to 0.23 seconds, that is an ~8x improvement.

回答1:

In CI framework, if you are running a prod application, we can set pconnect to true in config/database.php to use a persistent connection to database. Which can reduce latency on initial connection.

By the way, if you are running a test or dev application, we need to treat carefully with this setting, because it may cause several unexpected issues. You can refer to the answer of Advantages / Disadvantages of pconnect option in CodeIgniter to get more info.



回答2:

I have found the Entity Framework to be the culprit for long initial(cold start) responses. Disabling IIS from timing out has not helped, I think there must be some kind of EF pooling\memory timeout that is not advertised.

You can turn off some of the EF checks for DB versioning and try to use precompiled view that help a bit. I am still quite displeased with EF startup times when running in Azure connecting to on prem DB. Startup times on prem are about 1 second but nothing I have done can get my cloud on prem startup times under about 10-12 seconds. I have concluded that there is a lot of networking overhead for on prem and I would suspect using Azure SQL also presents a lot of networking overhead as well since it is public facing.