Let's suppose I have an ASP.Net web application hosted by IIS. In addition to the functionality serving requests I added an action executed periodically on specified interval, e.g. every 30 minutes. This action is not related to external web requests, for example, its purpose is deleting useless log files.
The question is: if nobody comes to my web site for long period of time (day, week) will IIS still keep my application alive and the above action will be executed every 30 min. Or IIS will shut down/suspend activity of the application if there are no requests for long time?
Perhaps it is a lame question but I failed to find the definite answer.
IIS doesn't shut down, but IIS will recycle your app after a certain period of time of unuse.
So if your app is responsible for firing off the event, then no it won't run if your app is not running (recycled).
Either have a service hit your website once in awhile or setup a scheduled task on the server if you have access to the machine.
If you're on shared hosting you'll have to check their features to see if they have something like that.
Also, if you're just trying to delete log files or something trivial and not time sensitive (since you won't have logs unless someone is hitting your site), you could just perform your action in Application_Start. This even will fire whenever IIS restarts your application.
Related
I have a ASP.Net MVC Website Hosted on IIS on couple of servers with load balancers, it a very simple page when it opens it logs user details in DB and show the view.
Issue is: It becomes unreachable sometime and pages are never opened. I have to restart APP Pool to get back on track and then it happens again.
What I have tried:
Made sure all DB connection are properly handled, any connection that gets opened are surely closed
Have put Recycle of APP Pool based on volume of RAM
Went through IIS logs and checked that request have reached there or not
There are other application also running on Server but the problem is isolated to this website
There are global users, issue persist of different global area
What I think it can be:
Might be possible that Load Balancer is never diverting my request
My request getting lost in between networks and layer
This is Production environment and we are not facing this issue in ACC or Dev.
What else I can go ahead and check?
My requirement is to send emails within the web application from an external server that takes around 4 to 5 seconds on average to process and send the confirmation email. I do not want the user to wait for this, so i trigger a console application with Process().StartInfo.Start() and it does it in background. The question is how much i can rely on this as during normal days the application sends around 10 thousand emails daily and in high traffic days it may surpass 80 thousand. What possible issues/problems the application or server may run into? Is there any better solution for this?
You can use following method to achieve this:
Create a .aspx page and write you business code here (e.g. email
send)
Where required, call this page using Javascript along with parameters in querystring. You can create an image element and set its source to that page.
var img = new Image();
img.scr = "perform-operation.aspx?[parametervalues]";
Thank you
Console application has drawback, if you plan to invoke console application for each email separately, any new process takes long to load and clean up, this is too much overhead on cpu. Instead, the best alternative is to host another website in IIS, this new website will have its own Application Pool, which will create and host process. IIS will shutdown the process if no request is served. You can setup Web Farm by running more worker process per application.
Other alternative is to run console or windows service all the time, let it be in the memory but has a web service host listening for email requests, if a request is received from your web application, this background service will send email on new thread and go back on waiting state. Basically it is a self hosted WCF service. This is quite same as hosting another website on IIS.
I prefer IIS based hosting as it is easy to setup, does not require any extra permissions and in future, to scale horizontally, you can easily move this mail service to other server.
I have a task that I want to be run 8am daily and am considering this solution: https://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/
But I'm not understanding the mechanics of how it works.
Say user X visits the site on Friday at 4pm and then closes his browser and turns his computer off. Will the cache expiration still fire on Saturday at 8am? If no users visit the site, will my process still fire every day?
Basically, my question boils down to, is this method reliable? Or is it dependent on users visiting the site?
ASP.NET Application When hosted (started) on IIS fires few Events, of Which Application_Start is one of the foremost. Setting a Background task then keeps running untill the Application is stopped/unloaded from IIS, or IIS service itself is stopped. IIS is a host process for all ASP.NET Websites.
Since the Cache is maintained on the Web Server, it has nothing to do with the active user(s).
This is analogous to a console aplpication, where the first line of code is adding something to a cache with a timer. runs as long as your console application is up and running.
Hope this helps you!
The server side cache is different to the browser cache. Users closing their browsers won't effect Jeff's code at all. However, if your application pool shuts down (and it may if there aren't any users hitting the site) then your code won't run at all until someone browses to the site, the app pool spins up again, and then it's 8am the next day (assuming the app pool is still up).
Can I objectively determine if my production ASP.NET web application is resetting its application pool? It could be for whatever reason (for example, an error occurred or memory topped off). I don't have direct access to my production servers, so when I want something on the server, I have ask specifically for it like PerfMon counters to run. It is a running IIS 6.0.
I understand that I could use PerfMon to catch ASP.NET Application Restarts. If I was not monitoring that PerfMon, is there anything that can tell me the application restarted sometime in the past?
You'll need access to the Event Logs.
Depending on your IIS version you might have to enable the worker processing recycling events.
For IIS 6: http://technet.microsoft.com/en-us/library/cc756146(WS.10).aspx
For IIS 7: http://www.iis.net/ConfigReference/system.applicationHost/applicationPools/add/recycling
For more info, ask again on serverfault.com
If all you really care about is if the application resets, you can just add some sort of Email alert, or logging, in the Application_Start of your global.asax.
This would tell you when, and how often, the application starts up, but wouldn't give you any details as to why it happened.
This would at least give you the information you needed to look at specific times for when your application is resetting.
My application is running in a shared hosting environment. I do have a dedicated App Pool for my app. I've been doing some testing with 1st visits and precompile performance and have been tracking when my application starts up and shuts down.
In my Global.asax I have some logging code in Application_Start and Application_End. I can see from my logs generally when the application is idle and shuts down, then someone visits and it starts back up.
But, I also see cases where a shutdown is logged and then followed by another shutdown about 13 minutes later; without a startup in the middle.
I also see instances where there are two Startups in a row. I'm guessing these might be a recycle, but why wouldn't there be a shutdown log entry?
What I'd really like to know if there is a better way to track when my application starts, when it shuts down and if it is shutdown due to an idle pool, or from a recycle. I don't have access to the Windows Event Log so I need to do this from my app if possible.
Application_Start and Application_End should only be called once per lifetime in your application, MSDN confirms this.
Without knowing your hosting environment it is possible that your web host is running your website over multiple worker pools or IIS instances. Your application pool could also be unexpectedly crashing due to other apps in the pool.
Without access to the Event Log or anything other than a basic web host control panel your best way of logging is what you're doing now, using Global.ASAX