Melbourne Silverlight Code Camp Thoughts

February 1, 2010

Over the weekend I attended the Silverlight Code Camp held at the NAB training facilities in Docklands, Melbourne. It was fantastic that a bank showed an interest in a developer event, in particular Silverlight. The NAB has a flagship product built in Silverlight with future software projects planned. NAB are on the lookout for developers so if you’re interested in Silverlight, they have a large budget for development and have been spending big according to their who welcomed us before the keynote, so contact them if interested. Also thanks to the other sponsors such as Readify.

I’m a day late in the game for my thoughts, I was exhausted Sunday afternoon after 2 very early mornings and lot of sessions. For a comprehensive review of the event check out Alex Mackey’s blog Silverlight Code Camp Review. He makes a lot of great points that I agree with, in particular a little bit of polish missing on a few of the advanced topic sessions weakened the experience for those on the advanced track. As a first time event and being free, I give it an A- (minus).

I enjoyed the keynote presented by former Silverlight product manager Scott Barnes, even tho as all keynotes go was a bit flashy (silverlighty?) with a bit of marketing spin. What was nice to hear was in fact Microsoft are really backing Silverlight, and it’s one of if not the fastest iterating units inside Microsoft, with a very short release cycle. Other notes included the push (through demonstrating Silverlight’s usefulness, not by mandate) inside Microsoft for other business units to adopt using Silverlight on their public facing sites.

The experts panel was great, we do see these kinds of sessions for example at TechEd. Panel sessions are always great where experts are fielding questions from the audience and just carrying on a formalised discussion. This session was very entertaining and informative, the discussion on HTML5 was great with the key take-away being standards are slow to propagate (adopt) where-as Silverlight is iterating fast to accomplish rich web experiences right now. Other recommendations from the panel, make use if WCF RIA where possible. Also the need to be in a different mindset when building Silverlight applications; which by nature function asynchronous with the back-end (this message was repeated in several presentations).

My top 5 sessions were:

One thing that topped off the event personally for me was winning a licence to some Silverlight controls from Component One, looking forward to getting that soon. Should help get me motivated into constructing more complex Silverlight side projects, which if #SLCC ‘11 goes ahead I can present. If you have the opportunity to attend any future Silverlight code camp in Melbourne, don’t hesitate to sign up.

Check out the sessions schedule on my previous post.

Finally the Silverlight community in Australia links are:


Melbourne Silverlight Code Camp – January 2010

January 29, 2010

The final weekend in January 2010 is the Melbourne Silverlight Code Camp.

I will have a summary post of my take on the event and topics covered, but this is a very quick post to have a plain text schedule up on the web (in particular for iPhone access).

View here as 46kb PDF (wordpress doesn’t allow for .txt uploads!).

Schedule:
Day 1
9:00 – 10:00
Keynote

10:15 – 11:15
s – Navigation Framework
a – MEF In Silverlight

11:30 – 12:30
s – Expression blend for dummies
a – Silverlight & IronRuby

12:30 – 1:15
BBQ Lunch

1:15 – 2:15
Q&A Experts

2:15 – 3:15
Lightning Talks

3:15 – 3:45
Coffee break

3:45 : 4-45
s – Developer Meets Designer
a – Automated UI Testing from simple to deep dive

5:00 – 6:00
s – Sketchflow
a – RIA Services / SQL Azure

Day 2
9:00 – 10:00
s – Sharepoint 2010 – Overview
a – Bing Maps

10:15 – 11:15
s – Creating Silverlight Controls
a – From object to MEF

11:30 – 12:30
s – Security in Silverlight
a – Sharepoint 2010 – Implementing SL controls as web parts

12:30
Lunch

1:15 – 2:00
Lightning talks

2:15 – 3:15
s – Common pitfalls in enterprise apps
a – Smooth Streaming

3:15 – 3:30
Locknote


Thinking Differently About System Architecture

January 19, 2010

It’s great when a presentation/discussion gets an audience riled up. As some of the audience begin to understand the general ideas, another portion are very eager to challenge and debate each point being made. This of course makes an interestingly heated session but does slow down the intended pace of a presentation. Tonight was such a session at the Melbourne .NET user group, where Udi Dahan had a very thought provoking presentation about system architecture titled: Command Query Responsibility Segregation (CQRS).

According to Udi it takes Udi about 3 days to cover in detail what CQRS is truly about, so in the brief 2 hours he was talking to us and explosion of questions the audience had through-out, the details of the concept in particular how one would implement it are a bit of a blur to me right now. But luckily Udi has a post Clarified CQRS that summaries this concept, that will be well worth the read even though it’s 3000 words.

I would like to go on discussion my perception of the audience reaction, as I myself at first found I was at least initially quick to dismiss with a thought like:

But I like my current process; I don’t want to even consider a drastic change right now.

&

I like using the current tool-set/framework, don’t you dare try and take that away from me.

When we’re not completely sure what the alternative is, we fear it and fall back to a defensive position (developers in general it seems).

This was made clear by concerns some members of the audience voiced that ranged from; loyalty of software such as SQL Server, to not wanting step on the toes of Business Analysts, to even not wanting to offer customers any additional options for improved software solutions. Reaching a peak of almost faith in current practices “Data is King” – don’t try and make us do it any other way than we currently are.

As the presentation went forward and more of the ideas were beginning to resonate truth with some of us, a select few of the audience were jumping to wild conclusions about abandoning current practices, concerns over changes from “the current way we do things”, and even business loosing customers with alternate approaches in software operation.

At this point I would like to make it clear; I’m not attacking individuals who were vocal in their debating against what was being presented, only to suggest be a bit more receptive of alternatives. Debate is often good, and in particular in user groups it is productive and welcomed, as we’re not “on the clock” on a behind schedule project.

I for one will be taking a closer look at the suggested alternative architecture, and if the smallest part of it can help me improve even a single screen in a web application for the better, then that’s just fantastic!

The lesson is; don’t be either to quick to accept but more so even worse to quick to dismiss. There’s always alternatives so be on the lookout for clever minds suggesting new and improved approaches that can quite well be improvements on current practices.


Victoria.NET January 2010 Session

January 19, 2010

I just got home from a slightly longer than usual Melbourne Vic.NET session, it was a very intense night, so intense I’ve got a second post lined up just to cover the second presentation. But first there were a few announcements:

  • David Burela reminded us of the April Cloud Camp.
  • Mahesh reminded us of the Silverlight Code Camp weekend end of January. I’m confirmed to be attending this.
  • Also that the User Group is looking for company sponsorship, as the current budget is shrinking

The two topics of the evening were:

  1. An overview and walk-through of some of the features in ASP.NET MVC 2, presented by Malcolm Sheridan and
  2. Command Query Responsibility Segregation, presented by Udi Dahan that I discuss in greater detail here [link coming soon].

The ASP.NET MVC 2 talk was a quick walk through with tips:
The take-away notes were:

  • Areas are useful in particular the ability to have them in a separate project (though that’s currently not functional in the RC). MSDN Link.
  • When using areas be careful on how your routes are impacted
  • Improved validation and custom validation options, through the use of ValidationAttribute interface
  • Validation re-use, in conjunction with Dynamic Data.
  • Other miscellanous improvements, such as shorter AcceptVerbs; Get/Post.

Overclocking PLINQ

January 10, 2010

Today I finally got around to tweaking my new PCs settings to achieve a small CPU overclock. I have an Intel Core i7 920, that by default runs at 2.66 Ghz, it’s now running at just over 3.00 Ghz, what’s this got to do with .NET you ask?

Well I thought I would post a simple follow up to my Sep 2009 entry about PLINQ and the Stack Overflow data-dump where at the time I was using a Core 2 Duo at 2.53 Ghz to run PLINQ vs LINQ speed-up tests.

So before the Core i7 speed up took place I ran the PLINQ queries and took down the results, now after the overclock I have some even more improved times.

Note: The standard LINQ queries also take advantage of a faster CPU even when using only a single core.

As an up front summary the speed-up on the PLINQ query over the LINQ query for the 4 physical cores on the Core i7 is averaging out to 3.79 factor speed-up.

This is a great value, since it’s reasonably close to 4, with some overheads not letting it reach any closer to 4. The overheads obviously prevent us from obtaining a pure number-of-cores performance multiplier.

The key experiment of data processing I’m performing here is on approximately 265,000 rows of Stack Overflow question data. After being extracted out and stored in memory some kind of data manipulation is being run (one that ideally can benefit from being distributed across several cores). Referring back to the original post it’s really just a trivial calculation of number of tags on the question that are also listed in the question body text.

So I ran LINQ then the PLINQ queries on the approximately 265,000 rows of data and averaged the results. Mind you the results are fairly consistent, almost always under 500 millisecond variations. I quickly whipped up an Excel chart to visual sumarise the time taken to complete the LINQ and PLINQ queries.

Core i7 PLINQ Timings

Core i7 PLINQ Timings (times are in Seconds)

To summarise; what was already known before we began (based on my dual core tests in September 2009)

  • More cores = better PLINQ execution time.
  • And higher core speed = better execution time.
  • Combining the two is even better.

Contractual Obligations

December 3, 2009

Last night Wednesday 2nd of December I attended a presentation at the Melbourne Patterns & Practices User Group. After the Gang of Four pattern discussion (which was Chain of Responsibility) was a presentation on .NET Code Contracts.

Code Contracts are a Microsoft Labs Research project, that now has a beta release.

Code Contracts provide a language-agnostic way to express coding assumptions in .NET programs. The contracts take the form of preconditions, postconditions, and object invariants.

At their simplest level of application in a code base Code Contracts will help group guard conditions for functions, and also easily support exit guard conditions when a public method completes.

public List<Markers> ExtractGeneticMarkers(List<BioSample> samples)
{
   //Pre conditions use:
   Contract.Requires(samples != null);
   //a lambda expression to perform the contract check on all elements
   Contract.Requires(samples.All(s => s.geneticData != null));

   //Post conditions use:
   Contract.Ensures(Contract.Result<Markers>() != null)

  var markers = new List<Makers>();
  //function logic
  return makers;
}

A summary of some of the benefits:

  • Compile time contract validation and error(/warning) output.
  • Runtime contract validation and exceptions thrown.
  • Toggling the contracts per assembly [Full / Pre & Post / Pre / ReleaseRequires / None].
  • Inheritance of contracts, even from interfaces.
  • Outputting documentation from the contracts, for accurate reflection of the state of the code.

It’s quite an extensive discussion for all it’s potential applications and what can be achieved, so for More Info check out some other posts on the topic too:


SDDN October: Silverlight with RIA and using MVVM

October 29, 2009

I just got home from the attending the October Silverlight Designer and Designer Network (SDDN) meeting. It was a trillogy presentation from the Readify guys, Jordan Knight, David Burela and Philip Beadle.

Who respectively presented on:

  • Connecting Silverlight to RIA,
  • Binding data to Bing Maps and
  • A testable Silverlight architecture and development approach walk-through

There was also an announcement for the 2010 Melbourne Silverlight CodeCamp, with registrations now open at the SilverlightCodeCamp.com.au. The schedule is still open for volunteers to offer up presentations. It will be run at the new NAB training facilities. The registration site was mentioned with the footnote of “it’s not tested yet” which at the time of this post seems to be the case, my registration isn’t being processed correctly or at least there’s no feedback of success.

First up Jordan ran through the basics of using .NET RIA Services to produce a simple data-bound Silverlight website log-in component. It included demonstrating how to use attributes to decorate the RIA based entities to assist with validation that can be shared server side and client side. The benefit being a visually well designed Silverlight application can benefit from robust validation logic, and make use of it through field level bindings to easily display validation feedback to the user.

Next up was a quick presentation from David showing us data binding capabilities of data collections to Bing Maps, to produce overlays and interactive features on a map view. He should be posting the material up soon on his blog, including some code snippets that will make achieving what he demonstrated quick and easy.

The final presentation from Phil, which was nicely presented using Prezi.com was all about putting together a collection of tools and concepts to develop a robust and testable Silverlight based application. It focused around using the Model-View-ViewModel (MVVM) architecture/design pattern. It included examples of regular unit tests, automated UI tests, and integration tests, making use of an Inversion of Control (IoC) framework called Unity a Microsoft Application Block up on CodePlex and the Visual Studio 2008 Test Edition. There’s a bit of a discussion going on at StackOverflow about Unity.

Some key things that Phil pointed out to stay up to date with Silverlight and of course to assist with building more testable Silverlight applications include:

All up, a good round of presentations.


Exceptions in (my) LINQ (presentation)

October 8, 2009

Last night I presented to the Melbourne Patterns & Practices group, thanks to my audience for paying attention, having great input and asking interesting questions. I would like to clarify some things I glossed over in the powerpoint slides, and explain why some of the simple extension methods didn’t execute in the live code demos. I also have posted the pptx file here.

The first thing that I did not give a detailed enough explanation about was the Exception Handling slide where I was using the ‘let’ keyword in a LINQ statement. The question was along the lines of the benefit of the exception handling offered up by making use of let in a LINQ query. To clarify this, the let keyword is used to create a contextual keyword as part of the LINQ query (a Range Variable). This range variable can then be used to create an anonymous type using projection. I incorrectly tied the explanation of let to the point I was trying to make about handling exceptions. The key take-away is that because the query is a deferred execution any exception handling needs to be wrapped around the code that performs the execution. So have the Try {} Catch (E ex) {} surround the processing code not the query definition.

There’s a great post about using ‘Let’ in a LINQ Query by Greg Beech that goes into greater detail. This topic lead to a question about what would happen to processing when an exception did occur.

Another issue that came up during live code tweaking was making use of certain extensions, in particular .Reverse() didn’t seem to compile. I am unable to recreate the issue quite possible some weird state in Visual Studio 2010 Beta 1, if that was the case then the clean and rebuild was the solution.

But here is the final very simple code that reads a directory and outputs the file names in a reverse order:

var xmlFilesQuery =
      from fileInfo in
           System.IO.Directory.GetFiles(@"D:\soExportData\")
      where fileInfo.Contains(".xml")
      select fileInfo;

foreach (var fileName in xmlFilesQuery.Reverse())
{
    Console.WriteLine(fileName);
}

The last clarification point was a scenario where the PLINQ execution of a task compared to it’s LINQ execution offered up a speed up of 2.18 times. Not sure what state the application was in to allow that. I’ll do some investigation and based on how complex the cause was either update here or create a new post.

Greater Than 2x Speed Up (On Dual Core Machine)

Greater Than 2x Speed Up (On Dual Core Machine)


How much memory are you currently using?

September 25, 2009

Following on from my previous post about a demo PLINQ application, I had some small discoveries about memory usage and wanted to blog them.

As I was loading large chunks of data into memory and started monitoring my little demo applications RAM footprint, I discovered that even tho the garbage collection system had already cleaned up my now out-of-scope variables, the RAM utilisation as reported to windows did not necessarily drop.

This actually turns out is quite a logical thing to have happen and works this way for good reason, I just hadn’t thought about it. I was simply expecting an action of explicit free-up of memory to instantly translate into free’d memory in Windows.

The process was just holding onto a reserved amount of memory the .NET runtime assuming I would soon need that space again, and it was correct in its assumptions; I did need that memory very soon.

Use More Memory!

Use More Memory!

To prove this: subsequent button clicks to load more data (roughly the same size volume), didn’t make the application’s memory footprint grow even larger. Another interesting thing I noted with the task manager window open all the time, was when I loaded additional applications and my demo app didn’t need the memory, it would free up the few hundred mb it had a hold of but wasn’t currently making use of.

Demo Application Memory Usage

Demo Application Memory Usage


Playing with PLINQ Performance using the StackOverflow Data Dump

September 25, 2009

Not having made use of PLINQ in an actual product yet, I decided to have a play with how it works, and to try and obtain my own small metrics on it’s performance benefits. PLINQ is part of a larger push from the .NET teams at Microsoft to get concurrent/parallel processing out of the box in your C# and VB.NET code. As for performance analysis there are already some great posts out there, not just from the Parallel Team at MS but also from great breakdowns with nice charts such as this.

Right off the bat, I’d like to stress that adding a .AsParallel() to your code won’t magically speed it up. Knowing this I still had unrealistic expectations when I began creating a demo to specifically show performance improvements. Often enough the level of processing I was performing (even on larger sets of data), did not benefit from being made concurrent across 2 cores. A level of variation in my results, leads me to believe part of the issue is also the ability to obtain enough resources to make effective use of 2+ cores. For example running out of the 4GB ram I have available, interference from other processes on the machine (Firefox, TweetDeck, virus scanner).

In my attempts at re-creating the “Baby Names” demo Scott Hanselman previewed at the 2009 NDC Conference in his great presentation: “Whirlwind Tour of .NET 4“. I first got a hold of the preview code samples back from 2008 for PLINQ that were part of the Parallel Extenstions CTP.

I then went on to from scratch create my own simple PLINQ – Windows Presentation Foundation (WPF) application.

I chose WPF to test a small feature I hadn’t made use of yet only because I happened to stumble upon it on that day; Routed Events see this StackOverflow question.

Once I completed my take on a LINQ processing demo based on 2 minutes of video showing the operation of ‘Baby Names’, I discovered (by accident*) the Visual Studio 2010 and .NET Framework 4 Training Kit – May Preview, which contains the demo code for what I was trying to re-create.

*The accident in which I discovered the Training Kit, was I actually performed a google image search on the term ‘PLINQ’ to see what came up for ideas for a graphic to add to this post. The 11th image (centre screen) was the baby name graph displayed in theWhirlwind Tour of .NET 4 presentation. The post that had the image was from Bruno Terkaly, the post was about the tool kit, great!

VS 2010 Training Kit May Preview

VS 2010 Training Kit May Preview

None the less, my not-as polished demo application, makes use of the StackOverflow creative commons data dump (actually the Sep 09 drop).

Some background: I grabbed the StackOverflow data dump via the LegalTorrents link, then I followed this great post from Brent Ozar, where he supplies code for 5 stored procedures to create a table schema and import the XML data into SQL Server. It was as simple as running them, and then writing 5 exec statements and waiting the ~1 hour to load the data (resulting for me in a 2.5 gig DB).

The way I structured a lengthy processing task that can benefit from parallel processing, is by making use of the Posts data (questions and answers), in particular questions with an accepted answer. I make an attempt through a repetitive simple string comparison process to determine how valid the tags on the question are, by scanning the question text for the tags, and counting frequency. Then timing the processing of sequential operation vs the parallel operation as I pipe varying levels of data into the function.

First I extract the data into memory from SQL Server (using LINQ to SQL Entities). Just a note on the specifics of the SO Data Dump structure; ‘Score’ is a nullable int so just to keep the data set down in volume I select posts that have some score and greater than a selected input (usually 10+ at least 1 person liked it), same with a reasonable amount of views (on average 200+).

private IEnumerable<Post> GetPosts(int score, int views)
{
   var posts = from p in db.Posts
           where (p.Score ?? 0) > score
           && p.ViewCount > views
           select p;

   return posts.ToList();
}

The next step was to create a function that would take some time to process, and of course potentially benefit from being run in parallel. Each post and it’s tags are operated in isolation, so this is clearly prime for separation over multiple cores. Sadly my development laptop only has 2 cores.

private bool IsDescriptive(Post p)
{
   //lengthy boring code
   //pseudocode instead:

   var words = extract_all_unique_words_from_the_post();
     //excluding punctuation
     //and other formatting details (markup).

   var tags = extract_tags_from_post();

   return were_the_tags_used_enough_in_post(words, tags);
}

Note: A more sophisticated algorithm here could help actually determine (and recommend) more appropriate tags based on word frequencies, but that’s beyond what I have time to implement for performance testing purposes. It would need to know to avoid common used words such as ‘the’, ‘code’, ‘error’, ‘problem’, ‘unsure’, etc (you get the point). It would then need to go further and know what words actually make sense to describe the technology (language/environment) the stack overflow question is about.

The Parallel operation is applied to a ‘Where’ filtering of data and this is where the timing and the reporting of the performance is based on. Making use of System.Diagnostics.StopWatch.


//running sequentially:
posts.Where(p => IsDescriptive(p));

// vs making use of parallel processing:
posts.AsParallel().Where(p => IsDescriptive(p));

On average this function making use of .AsParallel(), for varying records quantities from 100k to 300k would result in a 1.75 times speed up over the function operating sequentially on a single core. Which is what I was hoping to see.

All this was performed on a boot from VHD instance of Windows 7 (a great setup guide by Scott Hanselman here) with Visual Studio 2010 Beta 1 and SQL Server 2008, so I do understand there was some performance hit (both running as a VHD and having SQL on the same machine) but on average for effective PLINQ setup functions there was at least a 1.6 times factor speed up.

It’s that simple; it doesn’t do much yet, but there is potential for improved/more-interesting data analysis and performance measuring of it too. I will make time to clean up the demo application and post the solution files in a future post, so stay tuned for that. When I get a chance I’ll also try to investigate more of the data manipulations people are performing via data mining techniques and attempt to re-create them just for more performance tests. When I do I’ll be starting here.

That’s it, I’ll have a follow up post with some more details in particular the types of queries I had that did not benefit from PLINQ once I get a chance to determine how they were flawed or if they simply just run better on a single thread/core.