views:

335

answers:

5

Hi

Here the problem.

I have my site hosted on a shared hosting for asp.net mvc. I login and say and fill in one of my forms in and want to submit it. The submit is done using jquery ajax request.

Now all of a sudden it will hang and won't do something for like 20 seconds then all of a sudden it will finish my request of saving the form.

Now here is the thing. I could do the same request 10 times and the other 9 times might take like 200-500 milliseconds to finish. So why is there such a time difference?

It also seems if I do a request then do some other request both request will be go fast but if I stop and come back a couple mins the first request might take a while to complete(seems to range from 5 to 20 seconds).

But really it just seems to happen whenever it feels like. Some times I can almost go an entire session without seeing it. Some times I get multiple ones in a row and have to refresh the page and then it will go fast again.

So what causes this?

  • Could it be the code I written and that is why it goes slow?
  • Is it my hosting site?
  • Is it my connection at home?

Like I have no clue what causes this or how to test this so I can't even begin to fix it.

+4  A: 

You need to use a profiler (like ANTS Profiler) to determine the cause of the slowness. There are so many possible causes for the loss of performance that it will be impossible to tell without some data about how your application is running.

Andrew Hare
Any free ones????
chobo2
+2  A: 

The first place to start is with a network analyzer like Fiddler or Firebug. You should be able to tell pretty easily if the problem is from network lag or if it's actually just waiting on a response from the server. Likely it's the server.

The next step is to be able to see what is going on with the CPU and memory when you encounter a slow request, and if it's accessing a database, you need to be able to see what's going on there. Perhaps there is a transaction that is being blocked.

Ideally you should be looking at several of the built-in system performance counters that relate to the hardware and to .Net itself, such as the request queue and the GC stats.

womp
How do I tell if it is network lag with firebug? I use firebug currently but not sure where to check network lag. I don't know if I can see the cpu and memory as it is shared hosting.
chobo2
Firebug has the "Net" tab. You have to switch to it to enable it. It will then break down the components of the request time into DNS Lookup, Connecting, Queuing, Waiting for Response, and Receiving Data. If all the components are small except for Waiting for Response, then you know it's the server code taking the time. If "receiving data" is the biggest component for small files, then you might suspect there is something wrong with the network.
womp
Ok cool I will have to wait till I see that slow down again and check.
chobo2
A: 

I'd be curious if you have tested this at different times throughout the day, or if you just deployed and noticed the lag. It could be that there are backups running on the server or other administration jobs that cause the behavior. The problem is that on a shared host you have very few options for identifying the cause of performance issues. If the lag happens all the time, it is likely one of the following things:

  • the server has too many shared accounts and not enough resources (your host will not admit that)
  • you are sharing hardware with a very busy site (your host will not readily admit that, but you can find out yourself)
  • other accounts are running very resource-intensive apps (your host will help you with that)

You could do a reverse DNS lookup for your IP and see what else is running. You could ping the server while you are waiting for a response and see if the network latency goes up, or if the response comes uniformely fast. And finally, you could ask a support person to take a look.

cdonner
Hmm maybe your sort of right. I came back 2 hours later and did the same thing I did(creating 6 accounts and doing the same amount of actions) and I only had a hang up once. How do I do this reverse lookup? Also the part I am testing is under authentication. Do I have to take off the authentication in order to ping it or is there away around it?
chobo2
There are websites that do that (just google Reverse DNS). Alternatively, ping your site to get the IP address, then run nslookup -d xx.xx.xx.xx with your IP, and you will get a list of all domains that have dns records for the ip.
cdonner
A: 

Have you added logging into your application so that you can identify lags in your server code?

As well as Fiddler and Firebug, I'd be implementing stacks of logging. It may be that a particular request, on the server, is being held up.

Logging will narrow down the possibilities of where it is.

griegs
I have elmah as my logging but I guess this is a different type of logging?
chobo2
not sure but I'd put in place something like log4net and then log everything with a severity setting of say debug. then once you have solved it you can turn logging on and off again via the config file which is handy.
griegs
+1  A: 

i've also noticed on shared hosting that the app can drop out of global memory and require a recompile on the 1st revisit to the site. this process (recompilation) obviously is related to the size of your codebase, but 15-20 seconds doesn't sound unreasonable for a small-medium sized site to be recompiled.

to get around this, make sure that all your views are compiled and not just your core DLL code.

jim
How do I make sure my views are compiled?
chobo2
chobo2,there's a copule of references here on SO. try these out:http://stackoverflow.com/questions/959859/compiling-views-when-publishing-asp-net-mvc-projecthttp://stackoverflow.com/questions/383192/compile-views-in-asp-net-mvcjimi
jim