Thursday, 18 March 2010

wcf and iis7

There are many good posts out there on how to create a wcf service, so not going to go in any detail, suffice to say that a service contract, its implementation (I like these in there own assemblies, as it makes referencing easier) and a wcf web site with the appropriate service.svc file pointing at your implementation. Then its all config config config. although .net 4 is apparently moving away from the config dependancy i've not had chance to play.

The easiest option by far is to host an http binding service, but there are performance drawbacks, so look at the project its expected use before deciding on this. if you need to pass lots of data or you need speed go with tcp, and although you can load balance net.tcp its easier with http.

net.tcp and net.msmq are a little more involved, first make sure you have installed the non-http wcf component of .net in windows components, then check the nettcpactivator etc services are running, if you have already installed .net 4 you'll have to remove before doing the above as it causes problems. once these are running though its safe to reinstall. Now add the appropriate bindings (with port for tcp eg 9191:* and machine name with queue for msmq). all thats left is to add the protocols. you'll see many posts with command promt lines to copy edit paste and run. i think its far easier to open inetmgr, right click on the parent site, select advanced settings, then manage site and where it says http add ",net.tcp" and/or ",net.msmq" as appropriate (no spaces) then do the same for the app containing your service under the site. I also like to use the same credentials for the app pool and net activator services to avoid any possible issues.

That should be it, the activator services are the listeners and activate the service call when a request hits the server.

One quick note on msmq, you have to create the queue yourself, and unless you really need to advertise the queue on ad (and generally you don't) keep the queue private, the only difference between public and private is that public uses actve directory, if you plan to point your client endpoints at a server name or ip, public is a waste of resources and will hurt performance for no good reason. I have a theory aout load balancing msmq services in iis, and it involves using a horizontal pattern (lots of services on one machine pointing at a single queue, which works very well) with a vertical infrastructure (many machines) by pointing the nodes at a single queue on the primary server which should in theory work. I have a collegue to thank for the idea, and will post soon when i have tested it.

Tuesday, 9 March 2010

Load Underestimations

WCF services in an N-Tier service based system is very useful, but is dependant on appropriate design. Im currently in the process of re-designing a processing system. On initial deployment and for 18 months after the system could cope with the load. but not any more, and I'm faced with a full architecture change.

So a few thoughts on designing scalable systems, 1 if you have heavy critical processes in the chain consider the use of msmq with throttling to manage load on these processes. The same can be said for external system dependancies, technology like msmq can help.

Don't poll production databases to look for specific data. This is obvious i know, but I see so many ideas flawed by this approach. Try instead to use a push system to handle such requirements.

Load balancing, ideally design your architecture to allow load balancing, obviously small systems don't require this, but enterprise level applications should support it, even if its not going to be used straight away, at least its an option. Using IIS to host the services is an obvious way to do this.