More than one instance of HttpApplication present. Why?

Discussion in 'ASP .Net' started by miha.valencic@gmail.com, Nov 8, 2005.

  1. Guest

    Hi!

    A while ago, I noticed that there are usually two instances of
    HttpApplication created within IIS (observed on WinXPPro). Why is that?
    Especially, since Application_Start handler is called on only one
    instance (the one that was created first).

    Anyone has an idea?

    How to test:
    I created my own class, which extended HttpApplication. In
    Application_Start/End handlers I added some logging code and observed
    the situation. The code is below (sorry for the messy code. Can one
    format it somehow?).

    Regards,
    Miha

    using System;
    using System.Web;

    [assembly:log4net.Config.XmlConfigurator()]


    public class MyHttpApp : HttpApplication {
    private static readonly log4net.ILog log =
    log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

    public MyHttpApp() {
    log.InfoFormat("MyHttpApp constructor called! - Hashcode = {0}",
    this.GetHashCode());
    }


    protected void Application_Start(Object sender, EventArgs e)
    {
    log.InfoFormat("MyHttpApp->Application_Start called! - Hashcode =
    {0}", this.GetHashCode());
    }

    protected void Application_End(Object sender, EventArgs e)
    {
    log.Info("Application ending...");
    }
    }
     
    , Nov 8, 2005
    #1
    1. Advertising

  2. Scott Allen Guest

    On 8 Nov 2005 03:33:05 -0800, wrote:

    >Hi!
    >
    >A while ago, I noticed that there are usually two instances of
    >HttpApplication created within IIS (observed on WinXPPro). Why is that?
    >Especially, since Application_Start handler is called on only one
    >instance (the one that was created first).
    >


    I think the class name is misleading, personally.
    http://odetocode.com/Articles/89.aspx

    --
    Scott
    http://www.OdeToCode.com/blogs/scott/
     
    Scott Allen, Nov 8, 2005
    #2
    1. Advertising

  3. Bruce Barker Guest

    requests are handled by a HttpApplication instance. there is a pool of
    these, so if you have simultaneous requests there will be more than one.
    this is done so that there is a place to hold instance data during a
    request.

    the start/end handlers are only called once as that's the design. the
    constructor/destructor is called on every instance create/destory.

    -- bruce (sqlwork.com)



    <> wrote in message
    news:...
    > Hi!
    >
    > A while ago, I noticed that there are usually two instances of
    > HttpApplication created within IIS (observed on WinXPPro). Why is that?
    > Especially, since Application_Start handler is called on only one
    > instance (the one that was created first).
    >
    > Anyone has an idea?
    >
    > How to test:
    > I created my own class, which extended HttpApplication. In
    > Application_Start/End handlers I added some logging code and observed
    > the situation. The code is below (sorry for the messy code. Can one
    > format it somehow?).
    >
    > Regards,
    > Miha
    >
    > using System;
    > using System.Web;
    >
    > [assembly:log4net.Config.XmlConfigurator()]
    >
    >
    > public class MyHttpApp : HttpApplication {
    > private static readonly log4net.ILog log =
    > log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    >
    > public MyHttpApp() {
    > log.InfoFormat("MyHttpApp constructor called! - Hashcode = {0}",
    > this.GetHashCode());
    > }
    >
    >
    > protected void Application_Start(Object sender, EventArgs e)
    > {
    > log.InfoFormat("MyHttpApp->Application_Start called! - Hashcode =
    > {0}", this.GetHashCode());
    > }
    >
    > protected void Application_End(Object sender, EventArgs e)
    > {
    > log.Info("Application ending...");
    > }
    > }
    >
     
    Bruce Barker, Nov 8, 2005
    #3
  4. Guest

    Scott,

    thanks for the pointers. Very helpful for better understanding,
    although not in-depth. What is missing still is how many objects there
    are (how this object pooling works), (because there are not as many as
    there are threads -- which are configured in macihne.config) but it is
    not important. What is important is knowing that there is not just one.

    I am basically storing some state in this App object and since it is
    stored in the private static variable which is read only, it does not
    matter if there are many instances of this object.

    Thanks,
    Miha.
     
    , Nov 8, 2005
    #4
  5. Scott Allen Guest

    There should be an application object for each request thread. An
    application object is associated with each request thread as it works
    it's way through the pipeline. Have you done any experiments that
    indicate anything to the contrary?

    Note that the objects may be lazily created, so it might not ramp up
    to the number of threads configured in web.config unless it is
    required.

    --
    Scott
    http://www.OdeToCode.com/blogs/scott/

    On 8 Nov 2005 12:30:58 -0800, wrote:

    >Scott,
    >
    >thanks for the pointers. Very helpful for better understanding,
    >although not in-depth. What is missing still is how many objects there
    >are (how this object pooling works), (because there are not as many as
    >there are threads -- which are configured in macihne.config) but it is
    >not important. What is important is knowing that there is not just one.
    >
    >I am basically storing some state in this App object and since it is
    >stored in the private static variable which is read only, it does not
    >matter if there are many instances of this object.
    >
    >Thanks,
    > Miha.
     
    Scott Allen, Nov 9, 2005
    #5
  6. Guest

    I have observed the contrary. Not too radically, though. What I have
    found through testing is, that, as you say, this pool gets lazily
    created. Meaning, that it has some sort of algorithm and it starts with
    fewer threads in the begining and if the contention happens, the
    threadpool grows. In my case, there were 9 HttpApplication instances,
    although the threads configured were at 10. Even though I got more than
    half 403.9 ERRORs back from the application (too many requests). I
    wonder why, since there is supposed to be a default value of 500 for
    the queue size.

    But, from experience (and web resources) WinXP/2000 is limited in that
    way to max 10 connections, but obviously 0 length queue. :( But this is
    another discussion...

    rgds,
    Miha.
     
    , Nov 9, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ralf Wahner
    Replies:
    5
    Views:
    655
    Bob Foster
    Dec 24, 2003
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,234
    Smokey Grindel
    Dec 2, 2006
  3. Merciadri Luca
    Replies:
    4
    Views:
    851
  4. Steven D'Aprano
    Replies:
    0
    Views:
    143
    Steven D'Aprano
    Dec 23, 2013
  5. Replies:
    3
    Views:
    116
    Gary Herron
    Dec 23, 2013
Loading...

Share This Page