Resolve MVC slow loading

Home > Search
  by

If your MVC application is taking a long time to load, use the Web Inspector to determine how long it is taking for your application to load. In this example, it took 10 seconds to get www.freekb.net.


Web server

When attempting to determine the cause of latency, if the web server is on-site, it is best to first use a web browser on the same machine as the web server. Use the web inspector to spot latency. In this example, the duration of each event was in milliseconds, and the combined total of all events is about a half of a second. This shows that the web server can load the page very quickly, and the cause of the latency is not the web server.

 

If the web server is taking more than 1 second to load the site, set debug to false in the web.config file.

<compilation debug="false" targetFramework="x.x.x"/>

 

When publishing your MVC application, make the following configuraitons:

  • Tick Precompile during publishing
  • Ensure Release is selected

 

Upgrade Microsoft.AspNet.Web.Optimization beta2:

PM> Update-Package Microsoft.AspNet.Web.Optimization
Updating 'Microsoft.AspNet.Web.Optimization' from version '1.0.0-beta2' to '1.0.0' in project 'Bacp.Assess.Web'.

 

If the total duration is stil greater than 1 second, do the following:

 


LAN

Once the total duration for the website to load is less than 1 second when using a web browser on the same machine as the web server, next use a web browser on a different machine in the same subnet as the web server (in the LAN). If the total duration is greater than 1 second, you may have a congested network or your network switch may not be optimized.

Be careful to not be fooled by false positives. In this example, it may appear that interface GE8 has some issue, since this interface is 100 Mbps. However, if the server is connected to GE1 and the client is connected to GE2, GE8 would have nothing to do with the latency. 

 


Database queries

The website may only be slow whem making database queries. In this example, when loading a page that makes a database query, it took just under 8 seconds for the page to load.

 

There can be an issue where Entity Framework converts a column from varchar to nvarchar, which can cause latency. Add the following to prevent the conversion.

[Column(TypeName = "varchar")]
public string column1 { get; set; }

 


WAN

Use a PC that is not in the same subnet as the web server. For example, use a PC in the same city as the web server, but not in the same network as the web server. In this example, from a PC in the same city but not the same subnet as the web server, it took 10 seconds for the MVC application to load. This suggests the latency has something to do with the WAN.

 

Use the tracert command to determine the number of hops between the client computer and web server. In this example, there are 8 hops from the client to the web server.

PS > tracert www.freekb.net
1    2ms   2ms   1ms  192.168.0.1
2   11ms  10ms  13ms  x.x.x.x
3  867ms  29ms  29ms  x.x.x.x
4   18ms  15ms  16ms  x.x.x.x
5   25ms  26ms  23ms  x.x.x.x
6   37ms  34ms  42ms  x.x.x.x
7   22ms  20ms  20ms  x.x.x.x
8   35ms  34ms  34ms  x.x.x.x

 

One solution would be to run the application on a web server that has less hops between the client and the web server. This is a reasonable solution if we know all of the clients are isolated to a certain geographic region. For example, if the clients are in Wisconsin, we could point local.freekb.net to a web server in Wisconsin, and then use the Web Inspector to see if the latency is reduced. In this example, it is only taking 89 milliseconds to get local.freekb.net.

If you are not able to predict where the clients are located geographically, determine the geographic location of the web server. The last IP address in the tracert command should be the IP address of the web server. Use http://whatismyipaddress.com/ip-lookup to determine the geographic location of the web server. Let's say the client computer is in Wisconsin USA and the web server is in Arizona USA. In the example, the data packets must travel just under 2,000 miles from the web server to the client PC. This distance would produce some latency.


Shared server vs. Dedicated server

If it is taking a long time to get index.html, the web server being used may be a shared server hosting many different web applications. You will need to contact your hosting provider to know if you are using a shared server. If you are using a shared server, moving to a dedicated server should reduce latency. However, a dedicated server is much more expensive than a shared server. For example, a Go Daddy shared server starts at $3.99 per month, and a Go Daddy dedicated server starts at $79.99 per month (https://www.godaddy.com/pro/dedicated-server). A dedicated server would cost you nearly $1,000 per year. At that price, it would probably be more cost effective to rent a very fast ISP connection and run your own server out of your house or business.

 


ISP download speed

Determine the download speed between the client and server. Go to www.speedtest.net to determine the download speed. Let's say the download speed is 6 Mbps (Mega bits per second).



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments