1

I'm currently writing an application that will automate several management items for our web-server. My question is simple but I can't find any documentation on it; when calling our ServerManager through using Microsoft.Web.Administration will it have any performance hindrance if the server object connection is periodically open and closed(disposed)?

I know in a SQL Database frequent connection calls can drain performance in a lot of cases; so I don't want to run into a similar problem.

I'm trying to avoid having to create an Instance that will be Persisted in a manner where outgoing task are queued then performed.

If anyone can let me know, and point me to any documentation on it that would be great. But like I said I can't find any at the moment.

An example on a small scale:

public void AddSite()
{
    ServerManager defaultManager = new ServerManager();

    // Perform Task
    defaultManager.CommitChanges();
    defaultManager.Dispose();
}

public void RemoveSite()
{
    ServerManager defaultManager = new ServerManager();

    // Perform Task
    defaultManager.CommitChanges();
    defaultManager.Dispose();
}

By essentially building the object based on each method; then closing it impact performance?


Update:

The example is a very basic and even primitive example. There will be some refactoring to adhere to good practice, like the implementation of a IDisposable. However the main dilemma is I can not accurately depict the same variation like in SQL.

In SQL with excessive opening and closing, you see all the services gradually eat away performance especially as the database grows in complexity.

That is my goal with IIS, currently I can not obtain an accurate representation. The performance is indeed altering; I know most of the services it loads are also serializing and deserializing XML files that interpret the configuration.

Knowing how complex IIS is, with me automating it but trying to do the simplest path. I want to know if that simplistic approach may require a more complex approach or refactoring. As those services and process it does create do eat resources away.

I'm trying to accurately depict those possible hindrances, but I can't find any documentation or even details to Performance Gains for IIS.

Plus every time I do a test the results appear sporadic, inconsistent, and ultimately unreliable.

Greg
  • 11,302
  • 2
  • 48
  • 79

1 Answers1

2

Are you looking for something like this?

   private ServerManager _defaultManager = new ServerManager();

   public void AddSite()
   {
        // perform task
        _defaultManager.CommitChanges();            
    }

    public void RemoveSite()
    {
        // perform task
        _defaultManager.CommitChanges();
    }

    public void Dispose() {
       _defaultManager.Dispose();
    }

You should be able to run a couple of tests to determine if the above does in fact perform better. I've seen it go both ways with things like this. I do recommend that you implement IDisposable interface, since ServerManager implements IDisposable and my code would have your class owning a "managed IDisposable resource"

http://blog.stephencleary.com/2009/08/how-to-implement-idisposable-and.html

mikey
  • 5,090
  • 3
  • 24
  • 27
  • I ran a few test but I can't get anything truly concrete, they look quick. Then look like it is going slower. The IDisposable Interface I'll implement, but for the example I just tried to be quick. – Greg Mar 02 '13 at 00:29
  • Not quite, though Disposing will obviously free the resources it doesn't accurately depict the time iteration from the creation of the server object till it's disposed. That is why I'm trying to gauge it, but I can't find anything. In SQL you can see the connection eating up resources as SQL services start and stop, I'm trying to do the same for all of the IIS Services that I start and stop by automating. – Greg Mar 02 '13 at 19:06
  • Greg, I imagine you'd like to ensure you have good running code with no memory leaks. You may be able to test this easily by putting the code you're worried about in a loop and watching the process in Task Manager. You can also use a profiler http://stackoverflow.com/questions/1312493/net-code-profiling-tools – mikey Mar 04 '13 at 02:37