views:

65

answers:

3

Hi,

I currently have a Windows Service which continually runs throughout the day. It has multiple threads which kick off:

  • tasks daily to update cache
  • tasks weekly to do cleanup
  • 24/7 task to import XML into SQL Server
  • tasks which run for around 12 hours per day kicking off a console application to manage ETL

The tasks are not the important part of this question but it gives you the idea that this Windows service has grown to be a monster. It manages the imports of somewhere in the region of 300 million records per day.

It is hectic, but it works.

This iteration of development is giving me a chance to review the service and possibly break it down so that it is more manageable. It is thought that this could be multiple services with one manager service - ideal if a component needs to be updated then the whole thing does not need to grind to a hault.

Does anyone have any experience with this? I am keen to hear about your approach because it is new territory for me.

I have read this SO post which touches on the topic.

Cheers.

+2  A: 

Your description sounds a lot like the thing I wrote about 2 years ago. A windows service which hosts addins and runs them in multithreaded environment. The architecture used is the .NET addin pipeline introduced in .NET 3.5 (System.AddIn-namespace). It works like a charm as I also integrated live/hot updates. It's so easy to implement new addins and just plug them in whenever I like. So I really recommend using this addin stuff.

See http://msdn.microsoft.com/en-us/library/cc175292.aspx for a quickstart.

Scoregraphic
Would the new MEF stuff be a better fit these days?
Doobi
I haven't used MEF yet. Maybe some other guy already has? Feedback welcome
Scoregraphic
Hi - cheers for the response. I asked the question hoping to provoke thoughts to leverage some of the newer .NET features. I have managed to convince the project to go with VS 2010 but .NET 4.0 is still not on the "approved" list. Going with your suggestion might be the only way forward for the Windows service.I will also check out the MEF.
youwhut
+1  A: 

Why a service? Pretty much none of the things you do- except the 24/7 task for imports - are something I would do as a service.

I would use:

  • Either command line programs that get regularly scheduled, especially on the daily / weekly tasks
  • Or use SSIS and SQL Scheduler to schedule something.

The only thing that may justify a service is the 24/7 XML import - unless you can get away starting it, for example, every 5 minutes.

TomTom
And what "thing" starts scheduled tasks? A service! So why not write your own? Resources?
Scoregraphic
Becasue there IS ALREADY ONE RUNNING. It is called Task Scheduler and has been part of windows for some time now. Why reinvent the wheel when you arledy have an API to schedule tasks? Less work reinvented = less work to maintain = cheaper solution.
TomTom
And what if your task should be triggered by a filesystem event for example? The task scheduler only allows "polling" stuff to work. No push mechanism available.
Scoregraphic
You will note that I said this is the only valid case of them. I would definitely not keep a service around for something that starts every hour / day / week. Imports by file system cna often also be handled by a program running all 5 minutes.
TomTom
Cheers for the response. As I was reading through I instantly identified several of my tasks which could be put into several small console apps and scheduled. It has suddenly struck me that there is a dependency (ut oh). Currently, I will stop the 24/7 XML import activity whilst the more hefty weekly tasks occur. What do you think? Simply create a flag (small text file) from the small console app which the Windows service can read...?
youwhut
Possible. There are various ways - this is a "relatively hard" requirement. Whatever you do, make it a standard ;)
TomTom
+1  A: 

I've done something similar for our background services, there's basically a ServiceHost and "Servlets" which are loaded via appdomains so they don't impact each other.

Doobi