After February’s incursion into Wednesday’s territory it was good to see NxtGenUG Oxford back on the normal Tuesday slot and so, despite the noted absence of Barry & his box of swag, it was shaping up to be a good one.
Steven Wilmot kicked off the evening with his extended nugget on “Code Generation - Reflection, the CodeDOM & Dynamic Code”. He started off with a simple hard-coded method that copied an object which he then ran a benchmark on to count the number of times it could be run in one second & displayed the results of this. Although it ran at blistering speed he mentioned that it would need maintenance if changes were made to the class or one of its parents, something most of us have faced at some point in time.
Steven looked at using Reflection as the first means to tackle the issue but it became apparent that this does not come without performance penalties; in fact using it to walk the properties of the object each time was very inefficient in comparison to the hard-coded technique.
To improve the efficiency whilst keeping the code dynamic it would be necessary to optimise it to use Reflection only once, which Steven demonstrated a couple of ways of doing using the CodeDOM. After reflecting over an object once it was possible to build code with the CodeDOM which would stand up to the performance of the first demo, only suffering from the relatively slow start-up cost incurred by using Reflection during the initial code generation.
In Steven’s last topic he looked at using a technique to build a separate C# project dynamically by reflecting over the object once & generating a bunch of .cs files. The resultant code was semantically identical to the code from the first demo so the performance was great, but since it was generated code any maintenance concerns were negated.
To top it off (sorry I couldn’t resist) the pizza arrived at the perfect time and it gave us an opportunity to digest (ok I promise no more) the different approaches we’d just seen.
Once we’d polished off the pizza it was time for seasoned speaker Phil Pursglove of VBUG to take the podium to deliver his talk on “How to Write Scalable ASP.NET” something of an oxymoron in many people’s eyes. The three scaling topics on the agenda were improving server performance, reducing network load & load balancing, with promise of a light sprinkling of demonstration pages with code behind all written in (yes you guessed it) Visual Basic.
Improving server performance revolved around using different caching techniques to reduce the amount of work the server had to undertake for each request. Output caching allowed a large number of requests to be serviced using the same HTML output and since it’s cheaper to return pages from cache than generating new ones each time it reduced server CPU loading quite a lot.
Object caching demonstrated retrieving data from a database once and generating only the required content for each request, improving the overall performance of the server by reducing waiting time inherent to data access.
For output & object caching Phil demonstrated a number of techniques that could be employed to ensure the data in the cache remained valid. Unfortunately he had some issues when demonstrating SqlCacheDependancy but the intent had been made clear so it was easy to understand what should have happened.
Next up was Velocity distributed caching engine which Phil assured us would revolutionise the scalability of any web application however since it wasn’t released yet he could only describe what could and couldn’t be done in the imminent CTP 3. He then showed how donut (or doughnut?) caching could be used to provide a rich personalised user experience whilst caching certain page content for all users with another effective demo. Concluding the first portion of his talk we looked into paging of grid-based data with some handy dos and don’ts, and some of the gotchas that come with caching.
Reducing network load, the second bit of the talk, looked at ways to minimise the amount of data travelling between the server and its clients. Firstly this could be achieved by reducing the size of the ViewState using a number of different methods such as disabling it where it is not needed, by compressing it or by storing it on the server. Secondly he touched on compression, minimisation (JS or CSS) and leveraging external caching of static resources such as images.
To finish off the evening Phil shone a light on load balancing looking at ways to allow a client request to be serviced by any one of a number of servers using some form of distributed caching such as SQL Session State, the ASP.NET State Service or Velocity.
Since Barry was AWOL there were only water bottles available for swag but I’m sure he’ll make it up to us next time.