Application Recycling

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marios

    Application Recycling

    Hi,
    I want to have in a application i have created the feature of application
    recycling,
    similar to the aspnet_wp, and the new COM+ service.
    The reason i want to do this is because of being able to set limits to the
    memory usage my app
    can consume, and recycling it when it exceeds this limit.
    What I have done so far, is to create an application domain, in which all
    the objects i use are created,
    and by defining a certain number of method calls, or a memory threshold, i
    unload this domain and load
    it again rigtht after.
    However, because i use a number of threads in the app, i have to write code
    that unloads the application domain,
    only when all the created threads have finished their work, and pausing of
    course the creation of new ones.
    The threads i use, come from a timer
    Until no i have some satisfactory results, but i would like to here some
    more ideas, if any one has the time

    Thanks


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Application Recycling

    Marios,

    Unloading an application domain won't do anything for you in this case I
    believe. The GC and the managed heap extends across all application domains
    in the process. So even if you shut down one application domain, you won't
    reclaim the memory that you think is leaking (which it probably isn't).

    --
    - Nicholas Paldino [.NET/C# MVP]
    - nicholas.paldin o@exisconsultin g.com

    "Marios" <m.protogiros @k-netgroup.com> wrote in message
    news:e9It%23vbV DHA.2568@tk2msf tngp13.phx.gbl. ..[color=blue]
    > Hi,
    > I want to have in a application i have created the feature of application
    > recycling,
    > similar to the aspnet_wp, and the new COM+ service.
    > The reason i want to do this is because of being able to set limits to the
    > memory usage my app
    > can consume, and recycling it when it exceeds this limit.
    > What I have done so far, is to create an application domain, in which all
    > the objects i use are created,
    > and by defining a certain number of method calls, or a memory threshold, i
    > unload this domain and load
    > it again rigtht after.
    > However, because i use a number of threads in the app, i have to write[/color]
    code[color=blue]
    > that unloads the application domain,
    > only when all the created threads have finished their work, and pausing of
    > course the creation of new ones.
    > The threads i use, come from a timer
    > Until no i have some satisfactory results, but i would like to here some
    > more ideas, if any one has the time
    >
    > Thanks
    >
    >[/color]


    Comment

    • Marios

      #3
      Re: Application Recycling

      Nicholas
      thank u for your answer.
      However i have noticed that whenever i unload the custom domain i create,
      the memory the application consumes is reduced.
      Anyway, if that does not work 100% satisfactory, i am thinking of creating
      custom processes and terminating these.
      Do u have any other suggestion ?

      "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com> wrote
      in message news:e17xfvcVDH A.3332@tk2msftn gp13.phx.gbl...[color=blue]
      > Marios,
      >
      > Unloading an application domain won't do anything for you in this case[/color]
      I[color=blue]
      > believe. The GC and the managed heap extends across all application[/color]
      domains[color=blue]
      > in the process. So even if you shut down one application domain, you[/color]
      won't[color=blue]
      > reclaim the memory that you think is leaking (which it probably isn't).
      >
      > --
      > - Nicholas Paldino [.NET/C# MVP]
      > - nicholas.paldin o@exisconsultin g.com
      >
      > "Marios" <m.protogiros @k-netgroup.com> wrote in message
      > news:e9It%23vbV DHA.2568@tk2msf tngp13.phx.gbl. ..[color=green]
      > > Hi,
      > > I want to have in a application i have created the feature of[/color][/color]
      application[color=blue][color=green]
      > > recycling,
      > > similar to the aspnet_wp, and the new COM+ service.
      > > The reason i want to do this is because of being able to set limits to[/color][/color]
      the[color=blue][color=green]
      > > memory usage my app
      > > can consume, and recycling it when it exceeds this limit.
      > > What I have done so far, is to create an application domain, in which[/color][/color]
      all[color=blue][color=green]
      > > the objects i use are created,
      > > and by defining a certain number of method calls, or a memory threshold,[/color][/color]
      i[color=blue][color=green]
      > > unload this domain and load
      > > it again rigtht after.
      > > However, because i use a number of threads in the app, i have to write[/color]
      > code[color=green]
      > > that unloads the application domain,
      > > only when all the created threads have finished their work, and pausing[/color][/color]
      of[color=blue][color=green]
      > > course the creation of new ones.
      > > The threads i use, come from a timer
      > > Until no i have some satisfactory results, but i would like to here some
      > > more ideas, if any one has the time
      > >
      > > Thanks
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Nicholas Paldino [.NET/C# MVP]

        #4
        Re: Application Recycling

        Marios,

        I still don't understand why you are doing it. I would be less worried
        about the memory consumption on the machine and more concerned about whether
        or not the application is performing correctly and in a performant manner
        (the memory consumed does not indicate that it is NOT performant).

        What you are seeing is natural for a GC system.


        --
        - Nicholas Paldino [.NET/C# MVP]
        - nicholas.paldin o@exisconsultin g.com

        "Marios" <m.protogiros @k-netgroup.com> wrote in message
        news:%23RFPBBdV DHA.1692@TK2MSF TNGP11.phx.gbl. ..[color=blue]
        > Nicholas
        > thank u for your answer.
        > However i have noticed that whenever i unload the custom domain i create,
        > the memory the application consumes is reduced.
        > Anyway, if that does not work 100% satisfactory, i am thinking of creating
        > custom processes and terminating these.
        > Do u have any other suggestion ?
        >
        > "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com>[/color]
        wrote[color=blue]
        > in message news:e17xfvcVDH A.3332@tk2msftn gp13.phx.gbl...[color=green]
        > > Marios,
        > >
        > > Unloading an application domain won't do anything for you in this[/color][/color]
        case[color=blue]
        > I[color=green]
        > > believe. The GC and the managed heap extends across all application[/color]
        > domains[color=green]
        > > in the process. So even if you shut down one application domain, you[/color]
        > won't[color=green]
        > > reclaim the memory that you think is leaking (which it probably isn't).
        > >
        > > --
        > > - Nicholas Paldino [.NET/C# MVP]
        > > - nicholas.paldin o@exisconsultin g.com
        > >
        > > "Marios" <m.protogiros @k-netgroup.com> wrote in message
        > > news:e9It%23vbV DHA.2568@tk2msf tngp13.phx.gbl. ..[color=darkred]
        > > > Hi,
        > > > I want to have in a application i have created the feature of[/color][/color]
        > application[color=green][color=darkred]
        > > > recycling,
        > > > similar to the aspnet_wp, and the new COM+ service.
        > > > The reason i want to do this is because of being able to set limits to[/color][/color]
        > the[color=green][color=darkred]
        > > > memory usage my app
        > > > can consume, and recycling it when it exceeds this limit.
        > > > What I have done so far, is to create an application domain, in which[/color][/color]
        > all[color=green][color=darkred]
        > > > the objects i use are created,
        > > > and by defining a certain number of method calls, or a memory[/color][/color][/color]
        threshold,[color=blue]
        > i[color=green][color=darkred]
        > > > unload this domain and load
        > > > it again rigtht after.
        > > > However, because i use a number of threads in the app, i have to write[/color]
        > > code[color=darkred]
        > > > that unloads the application domain,
        > > > only when all the created threads have finished their work, and[/color][/color][/color]
        pausing[color=blue]
        > of[color=green][color=darkred]
        > > > course the creation of new ones.
        > > > The threads i use, come from a timer
        > > > Until no i have some satisfactory results, but i would like to here[/color][/color][/color]
        some[color=blue][color=green][color=darkred]
        > > > more ideas, if any one has the time
        > > >
        > > > Thanks
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Marios

          #5
          Re: Application Recycling

          Nicholas,
          the reason i want to do this is simple.
          I have created a windows service with a timer , and another one with a
          simple file system event watcher.
          Although i properly dispose all the objects that i use, i have even
          commented the code running inside the event,
          at every event execution an additional amount of memory is kept, and the
          thing is that the memory allocation
          is never reduced. That had a simple effect. It has finally allocated a very
          large number of megabytes in RAM, in
          a production server that made the service simply not acceptable by the
          client.
          That is why i want to be able to do this, so that it will not happen again.


          "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com> wrote
          in message news:usDrhPdVDH A.1316@TK2MSFTN GP12.phx.gbl...[color=blue]
          > Marios,
          >
          > I still don't understand why you are doing it. I would be less[/color]
          worried[color=blue]
          > about the memory consumption on the machine and more concerned about[/color]
          whether[color=blue]
          > or not the application is performing correctly and in a performant manner
          > (the memory consumed does not indicate that it is NOT performant).
          >
          > What you are seeing is natural for a GC system.
          >
          >
          > --
          > - Nicholas Paldino [.NET/C# MVP]
          > - nicholas.paldin o@exisconsultin g.com
          >
          > "Marios" <m.protogiros @k-netgroup.com> wrote in message
          > news:%23RFPBBdV DHA.1692@TK2MSF TNGP11.phx.gbl. ..[color=green]
          > > Nicholas
          > > thank u for your answer.
          > > However i have noticed that whenever i unload the custom domain i[/color][/color]
          create,[color=blue][color=green]
          > > the memory the application consumes is reduced.
          > > Anyway, if that does not work 100% satisfactory, i am thinking of[/color][/color]
          creating[color=blue][color=green]
          > > custom processes and terminating these.
          > > Do u have any other suggestion ?
          > >
          > > "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com>[/color]
          > wrote[color=green]
          > > in message news:e17xfvcVDH A.3332@tk2msftn gp13.phx.gbl...[color=darkred]
          > > > Marios,
          > > >
          > > > Unloading an application domain won't do anything for you in this[/color][/color]
          > case[color=green]
          > > I[color=darkred]
          > > > believe. The GC and the managed heap extends across all application[/color]
          > > domains[color=darkred]
          > > > in the process. So even if you shut down one application domain, you[/color]
          > > won't[color=darkred]
          > > > reclaim the memory that you think is leaking (which it probably[/color][/color][/color]
          isn't).[color=blue][color=green][color=darkred]
          > > >
          > > > --
          > > > - Nicholas Paldino [.NET/C# MVP]
          > > > - nicholas.paldin o@exisconsultin g.com
          > > >
          > > > "Marios" <m.protogiros @k-netgroup.com> wrote in message
          > > > news:e9It%23vbV DHA.2568@tk2msf tngp13.phx.gbl. ..
          > > > > Hi,
          > > > > I want to have in a application i have created the feature of[/color]
          > > application[color=darkred]
          > > > > recycling,
          > > > > similar to the aspnet_wp, and the new COM+ service.
          > > > > The reason i want to do this is because of being able to set limits[/color][/color][/color]
          to[color=blue][color=green]
          > > the[color=darkred]
          > > > > memory usage my app
          > > > > can consume, and recycling it when it exceeds this limit.
          > > > > What I have done so far, is to create an application domain, in[/color][/color][/color]
          which[color=blue][color=green]
          > > all[color=darkred]
          > > > > the objects i use are created,
          > > > > and by defining a certain number of method calls, or a memory[/color][/color]
          > threshold,[color=green]
          > > i[color=darkred]
          > > > > unload this domain and load
          > > > > it again rigtht after.
          > > > > However, because i use a number of threads in the app, i have to[/color][/color][/color]
          write[color=blue][color=green][color=darkred]
          > > > code
          > > > > that unloads the application domain,
          > > > > only when all the created threads have finished their work, and[/color][/color]
          > pausing[color=green]
          > > of[color=darkred]
          > > > > course the creation of new ones.
          > > > > The threads i use, come from a timer
          > > > > Until no i have some satisfactory results, but i would like to here[/color][/color]
          > some[color=green][color=darkred]
          > > > > more ideas, if any one has the time
          > > > >
          > > > > Thanks
          > > > >
          > > > >
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Nicholas Paldino [.NET/C# MVP]

            #6
            Re: Application Recycling

            Marios,

            That's the thing, this is SUPPOSED to happen. The CLR is going to try
            and consume resources until it deems that it should give them back. It is
            the CLR's business to manage this. This is why they call it "managed
            memory".


            --
            - Nicholas Paldino [.NET/C# MVP]
            - nicholas.paldin o@exisconsultin g.com

            "Marios" <m.protogiros @k-netgroup.com> wrote in message
            news:%230oa2hdV DHA.3220@tk2msf tngp13.phx.gbl. ..[color=blue]
            > Nicholas,
            > the reason i want to do this is simple.
            > I have created a windows service with a timer , and another one with a
            > simple file system event watcher.
            > Although i properly dispose all the objects that i use, i have even
            > commented the code running inside the event,
            > at every event execution an additional amount of memory is kept, and the
            > thing is that the memory allocation
            > is never reduced. That had a simple effect. It has finally allocated a[/color]
            very[color=blue]
            > large number of megabytes in RAM, in
            > a production server that made the service simply not acceptable by the
            > client.
            > That is why i want to be able to do this, so that it will not happen[/color]
            again.[color=blue]
            >
            >
            > "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com>[/color]
            wrote[color=blue]
            > in message news:usDrhPdVDH A.1316@TK2MSFTN GP12.phx.gbl...[color=green]
            > > Marios,
            > >
            > > I still don't understand why you are doing it. I would be less[/color]
            > worried[color=green]
            > > about the memory consumption on the machine and more concerned about[/color]
            > whether[color=green]
            > > or not the application is performing correctly and in a performant[/color][/color]
            manner[color=blue][color=green]
            > > (the memory consumed does not indicate that it is NOT performant).
            > >
            > > What you are seeing is natural for a GC system.
            > >
            > >
            > > --
            > > - Nicholas Paldino [.NET/C# MVP]
            > > - nicholas.paldin o@exisconsultin g.com
            > >
            > > "Marios" <m.protogiros @k-netgroup.com> wrote in message
            > > news:%23RFPBBdV DHA.1692@TK2MSF TNGP11.phx.gbl. ..[color=darkred]
            > > > Nicholas
            > > > thank u for your answer.
            > > > However i have noticed that whenever i unload the custom domain i[/color][/color]
            > create,[color=green][color=darkred]
            > > > the memory the application consumes is reduced.
            > > > Anyway, if that does not work 100% satisfactory, i am thinking of[/color][/color]
            > creating[color=green][color=darkred]
            > > > custom processes and terminating these.
            > > > Do u have any other suggestion ?
            > > >
            > > > "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com>[/color]
            > > wrote[color=darkred]
            > > > in message news:e17xfvcVDH A.3332@tk2msftn gp13.phx.gbl...
            > > > > Marios,
            > > > >
            > > > > Unloading an application domain won't do anything for you in[/color][/color][/color]
            this[color=blue][color=green]
            > > case[color=darkred]
            > > > I
            > > > > believe. The GC and the managed heap extends across all application
            > > > domains
            > > > > in the process. So even if you shut down one application domain,[/color][/color][/color]
            you[color=blue][color=green][color=darkred]
            > > > won't
            > > > > reclaim the memory that you think is leaking (which it probably[/color][/color]
            > isn't).[color=green][color=darkred]
            > > > >
            > > > > --
            > > > > - Nicholas Paldino [.NET/C# MVP]
            > > > > - nicholas.paldin o@exisconsultin g.com
            > > > >
            > > > > "Marios" <m.protogiros @k-netgroup.com> wrote in message
            > > > > news:e9It%23vbV DHA.2568@tk2msf tngp13.phx.gbl. ..
            > > > > > Hi,
            > > > > > I want to have in a application i have created the feature of
            > > > application
            > > > > > recycling,
            > > > > > similar to the aspnet_wp, and the new COM+ service.
            > > > > > The reason i want to do this is because of being able to set[/color][/color][/color]
            limits[color=blue]
            > to[color=green][color=darkred]
            > > > the
            > > > > > memory usage my app
            > > > > > can consume, and recycling it when it exceeds this limit.
            > > > > > What I have done so far, is to create an application domain, in[/color][/color]
            > which[color=green][color=darkred]
            > > > all
            > > > > > the objects i use are created,
            > > > > > and by defining a certain number of method calls, or a memory[/color]
            > > threshold,[color=darkred]
            > > > i
            > > > > > unload this domain and load
            > > > > > it again rigtht after.
            > > > > > However, because i use a number of threads in the app, i have to[/color][/color]
            > write[color=green][color=darkred]
            > > > > code
            > > > > > that unloads the application domain,
            > > > > > only when all the created threads have finished their work, and[/color]
            > > pausing[color=darkred]
            > > > of
            > > > > > course the creation of new ones.
            > > > > > The threads i use, come from a timer
            > > > > > Until no i have some satisfactory results, but i would like to[/color][/color][/color]
            here[color=blue][color=green]
            > > some[color=darkred]
            > > > > > more ideas, if any one has the time
            > > > > >
            > > > > > Thanks
            > > > > >
            > > > > >
            > > > >
            > > > >
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Dave

              #7
              Re: Application Recycling

              Nicholas,

              The GC does a full garbage collection when it unloads an appdomain, so the
              resources used in an appdomain should be reclaimed when it is unloaded.
              There currently is a small memory leak (about 12 bytes) per unloaded
              appdomain.

              Dave
              PS: Full disclosure - info based on Chris Brumme's most excellent blog.


              "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com> wrote
              in message news:e17xfvcVDH A.3332@tk2msftn gp13.phx.gbl...[color=blue]
              > Marios,
              >
              > Unloading an application domain won't do anything for you in this case[/color]
              I[color=blue]
              > believe. The GC and the managed heap extends across all application[/color]
              domains[color=blue]
              > in the process. So even if you shut down one application domain, you[/color]
              won't[color=blue]
              > reclaim the memory that you think is leaking (which it probably isn't).
              >
              > --
              > - Nicholas Paldino [.NET/C# MVP]
              > - nicholas.paldin o@exisconsultin g.com
              >
              > "Marios" <m.protogiros @k-netgroup.com> wrote in message
              > news:e9It%23vbV DHA.2568@tk2msf tngp13.phx.gbl. ..[color=green]
              > > Hi,
              > > I want to have in a application i have created the feature of[/color][/color]
              application[color=blue][color=green]
              > > recycling,
              > > similar to the aspnet_wp, and the new COM+ service.
              > > The reason i want to do this is because of being able to set limits to[/color][/color]
              the[color=blue][color=green]
              > > memory usage my app
              > > can consume, and recycling it when it exceeds this limit.
              > > What I have done so far, is to create an application domain, in which[/color][/color]
              all[color=blue][color=green]
              > > the objects i use are created,
              > > and by defining a certain number of method calls, or a memory threshold,[/color][/color]
              i[color=blue][color=green]
              > > unload this domain and load
              > > it again rigtht after.
              > > However, because i use a number of threads in the app, i have to write[/color]
              > code[color=green]
              > > that unloads the application domain,
              > > only when all the created threads have finished their work, and pausing[/color][/color]
              of[color=blue][color=green]
              > > course the creation of new ones.
              > > The threads i use, come from a timer
              > > Until no i have some satisfactory results, but i would like to here some
              > > more ideas, if any one has the time
              > >
              > > Thanks
              > >
              > >[/color]
              >
              >[/color]


              Comment

              Working...