asp.net mvc slow response every 45 seconds - asp.net-mvc

I have an MVC 4 app which is performing a slow request roughly every 45 seconds. It's normally 200ms and all requests will be 200ms for about 45 seconds before there is one for about 4500ms. Then back to 200ms.
I have no caching set up.
I am however using a PrincipalContext to query AD.
I was wondering if anyone had any idea before I start setting up some profiling on the calls.
quick:
slow:

Thanks Pinch, but the problem was Active Domain and PrincipalContext. See the solution here, I turned off NetBIOS over TCP/IP and everything is running much better now.
Though I was displaying menu items based on the roles a user has, perhaps I'll cache these somewhere so I don't have to query AD every request.

Related

Best way to space out execution / requests (for a web crawler)

I am building a web crawler. It grabs a main page, which has about 50 links. Then I need to do 2 requests for each link. I dont want to make 101 requests within a few seconds. What is the best way to randomly space these out? I want to somewhat mimic human activity.
urls.each do |url|
# Do Something
sleep([1,2,3,4,5].sample)
end
This will work, but is this the best was to do it? Let's say this takes about 1 hour to run, will the server become slow to respond when when it's sleeping?
Mimicking human behavior is very hard. It's impossible if you're requesting literally every single link on a website anyway. I would probably just request one page per second. The server will not be impacted at all by a thread that's currently sleeping.

Why is MvcHandler.BeginProcessRequest() so slow?

I have an MVC project, and I'm looking at speeding things up. One thing I'm scratching my head over is the BeginProcesRequest() which I have no control over. Using New Relic I found that this method is, on average consuming 90% of the time required for the transaction to complete.
The code in my controller is pretty simple. It has a look for an action session for the user and redirects to their dashboard if it finds one. there isn't any database calls on the actual page. The only written is:
if (Session["UserID"] != null)
// Perform actions
The BeginProcessRequest() method takes almost 4 seconds as you can see in the screenshot
This can't be something unique to my site? I'm using a small EC2 instance for the server, and although there are other applications running on the site the CPU and memory stay pretty much at 0 throughout the request.
EDIT - Reviewed the following post:
What happens in BeginProcessRequest()?
However as my application is idle when the most time consuming requests take place I can't see how it could be related to competing threads.
I think the issue was with IIS, as after I changed the property of idle time-out in the application pool to be one day it now seems to load much faster on initial start.
I also explicitly disabled the session state on my home controller, and ensured that SQL Server's auto close parameter was set to off.

MVC - Update view after long running tasks

I would like to display results of long running tasks and still have responsive web site. I am calculating several results and each calculation takes from few seconds to more than 10 seconds. If I put everything in controller the site will be dead for 10 - 20 seconds and then results will be displayed in view.
Rather than this I would like to immediately display a view and start with calculations. After each calculation is finished, the site should be updated (or at least status should be updated and results can be displayed at the end). It would be great if all calculations could run in parallel.
How can I implement this? Is there a sample that is already available?
PS: I have seen several web sites where you search for results (for instance airplane tickets) where site is updating during the search. Maybe this is similar.
You can use asynchronous methods and controllers instead of the default synchronous ones. Assuming you're talking about asp.net mvc, you could start by looking here http://www.asp.net/mvc/tutorials/mvc-4/using-asynchronous-methods-in-aspnet-mvc-4 and here http://msdn.microsoft.com/en-us/vs11trainingcourse_aspnetmvc4_topic5.aspx
Hope that helps, lemme know if not.

Active X slow to load first time

I have an Active X control, which when first called or loaded in my asp.net application, is really slow to load. However, after the first load, it is really quick!!
My question is this, "How do I make my Active X control, when first called, load much faster? Is there away to preload the active x to the page so when it is used or called, it doesn't take so long to load?"
I have checked to see whether my active x is being called correctly by my javascript code, and it does. All my Active X does is to make a call to Outlook and to set some user properties. Not much.
Please help, but it has been doing my head in for days.
This is a known issue with the .Net Framework 1.1, 2.0, 3.0 and 3.5 You have a few options. Upgrade to the 4.0 Framework, preferably with IIS 7 which has the ability to ping your site and deep it alive. If you are not able to upgrade you could also use a ping utility to keep your site "alive". Basically what this does is it hits your site every few minutes so that you do not encounter the 20 min. default timeout period of you application domain. When you application domain times out it is reloaded on the next request, hence the slowness you are experiencing.
http://www.spikesolutions.net/ViewSolution.aspx?ID=c2b7edc0-5de1-4064-a432-05f6eded3b82

View counter in ASP.NET MVC

I'm going to create a view counter for articles. I have some questions:
Should I ignore article's author
when he opens the article?
I don't want to update database each
time. I can store in a
Dictionary<int, int> (articleId, viewCount) how many times
each article was viewed. After 100
hits I can update the database.
I should only count the hit once per
hour for each user and article. (if
the user opens one article many
times during one hour the view count
should be incremented only once).
For each question I want to know your suggestions how to do it right.
I'm especially interested how to do #3. Should I store the time when the user opened the article in a cookie? Does it mean that I should create a new cookie for each page?
I think I know the answer - they are analyzing the IIS log as Ope suggested.
Hidden image src is set to
http://stackoverflow.com/posts/3590653/ivc/[Random code]
[Random code] is needed because many people may share the same IP (in a network, for example) and the code is used to distinguish users.
Sure - I think that is a good idea
and 3. are related: The issue is where would you actually store this dictionary and logic.
An ASP.NET application or session scope are of course the easiest choice, but there you really need to understand the logic of application pools. ASP.NET applications are recycled from time to time: when there is no action on the site for a certain period or in special situations - e.g. if the process starts to take too much memory the application is shut down and a new one is started in the next request. There are events for session and application shut-down, but at least some years ago they were not really reliable: In many special cases they did not always fire. Perhaps they are better now, but it is painful to test. And 1 hour is really a long time: Usually sessions are kept alive only like 20 minutes after last request.
A reliable way would be to have a separate Windows service (a lot of work to program) or always storing to database with double-view analyses (quite a lot of overhead for such a small feature).
Do you have access to IIS logs? How about analyzing IIS logs e.g. every 30 minutes with some kind of timer process and taking the count from there? Or then just store all the hits to the database with user information and calculate the unique hits with a similar timed process.
One final question: Are you really sure none of the thousands of counter applications/services in the Internet wouldn't do the job close enough to your requirements?
Good luck!
This is the screenshot of this page in Firebug. You can see that there is a request which returns 204 status code (No Content).
This is stackoverflow's view counter. They are using a hidden image which point to a controller's action.
I have many articles. How to track which articles the user visited already?
P.S. BTW, why is this request made two times?

Resources