views:

484

answers:

2

I am in the process of writing an enterprise-level application utilizing WCF and NetTCP services. I chose NetTCP initially out of curiosity, but later determined it to be the best option for me since I can have services that are called that take 5+ hours to return results due to the amount of data crunching involved.

The way I currently spawn my services is a multi-step process. I have a configuration piece (using System.Configuration) that specifies some of the default stuff (port number, server name for clients connecting in, whether to enable HTTP as well as NetTCP, etc) and that has a collection of "services" underneath it. For example, here's what a basic one looks like:

<serverConfiguration tcpListenerPortNumber="60000" httpGetEnabled="true" httpListenerPortNumber="6000" serverName="localhost" retryEnabled="true" retryInterval="5" maxRetryAttempts="3">
    <services>
        <add virtualDirectory="Service1" applicationName="Service1" assembly="SampleService" type="SampleService.Service1" />            
    </services>
</serverConfiguration>

Basically what's happening here is my Windows service kicks off and looks at everything in the <services /> collection and spawns off a thread per service to speed startup time and each thread contains an AppDomain where the service truly lives so if a service has some kind of fault it doesn't bring the system down.

The "problem" I am running into is this application is hosting approximately 20 services and it takes a good 15-20 seconds for all the services to be up and running. I did the threading and AppDomain pieces to get it down to that value (used to take over a minute as each service was opened sequentially) but it still seems to me that this could actually go a lot faster.

Anyone have any suggestions? Google Bing has a plethora of examples for hosting one service but I'm not finding much out there for real-world applications (sadly "Hello World" just isn't appealing to end users). If you're currently hosting multiple services via a Windows Service and NetTCP, how are you doing it?

A: 

I have three suggestions:

Firstly, if a call can take 5+ hours, I would consider a queuing / call back style architecture.

Consider splitting your services into 20 windows services, where each service runs in it's own windows services. This adds complexity and increases memory usage, but an individual service may be available faster.

Lastly, check the code that is in the consructor of the service, for any unneeded code.

Shiraz Bhaiji
20 services really isn't feasible - especially from a debugging standpoint. We're still in development and I am guessing we have another 10-20 services yet to be built. The complexity of something like that could easily go off the charts from a maintenance standpoint.
digitall
Why would this be a maintenance problem, if all services were created on the same framework, used the same infrastructure, naming conventions, etc. I mean the same logging technology, configuration, etc. 40 nearly-identical services shouldn't be any harder to maintain than one or two that are not identical.
John Saunders
Well, a lot of services utilize each other (i.e. calling one can require a call to others, etc) so debugging that would really be a pain vs. a single "endpoint" if you will (not a true endpoint, but I think you get my point). Not to mention, 40 Windows Services just seems like an intense amount of overkill - especially if a core piece changes and I have to then deploy those DLLs to every location. I could GAC the core stuff, but it still just seems like a lot of overkill.
digitall
+1  A: 

I figured it out finally and it had nothing to do with WCF or my configuration pieces after all. When I was creating the AppDomain I stole the code from another project we had that was much smaller in size and found that the section creating AppDomains was using the SingleDomain option. Changing it to MultiDomain made things go to >4 seconds for total load and memory usage dropped to ~40MB from ~150MB.

Thanks for the assistance though - at least it got me reviewing the code again!

digitall