Live and learn?

Well, I typically hate IIS when dealing with other people's computers so I was trying to find a way around deploying the server component as a Web Service. I thought "lets search for Hosting a WCF in a Windows Service". Voila, tons of examples. Not very good examples, but enough to piece together what I needed. Now, I have to blame myself for not stopping and thinking over what the evidence indicated, because after the fact I can see that where I was going to end up was clear based on some of the steps required, but in the end I have discovered that a WCF service is ultimately hosted in a web service.

I guess we all have a different idea of what the word "hosted" means. I would say that IIS is "hosting" my service, while the windows service merely acts as a proxy allowing me to communicate with it as a service. To my mind, that isn't actually hosting anything. It is a wrapper or a proxy. But that is just my opinion. Anyway, if you can't tell, that approach failed.

But I did ultimately get the web service working properly via IIS. Thing about SQLite is that it is a flat file and IIS likes to lock down the file system. Completely understandable, while continuing to be completely irritating as well. Once I had that in place I also had a chance to run some smoke tests against this in the actual sort of configuration it would be running. As expected, things weren't 100% the same as they were in my dev environment. I hit far more collisions and delays.

This prompted me to do something I should have done ages ago. Refactor how I am communicating with NHibernate. I made a few quick attempts on my own which resulted in better performance, but with MUCH worse results. I got errors every other service call. I did a quick search and found the solution. Creating a session factory is a "long" process and it is thread safe, whereas sessions themselves take little to no time to create. My existing code was creating EVERYTHING (mappings, configurations, session factory and session) from scratch every single time a method was called. My new code simply gets a new session (for most methods at least).

Again, we come back to value of writing good code. Everything is much more stable now... but also, where things could take a second or so in the past (not irritating or slow by any means but definitely not lightning fast) they are now instantaneous.

I almost need to slap myself because the performance is so staggeringly different.

Comments

Popular Posts