.Net Design for Performance

The sunday of PDC is traditionally focussed around a few session that delve a little bit deeper into the subject than you would normally have on an normal PDC session. I attended (a little bit late I must admit but luckily Rob did text me) a session on Design for performance. Rob did sit thru the whole session and updated me quickly on what Rico Mariani told. Nice to see that some tools I already stumbled across in the last year or so (like vadump, clrprofiler) are getting more and more friends. One of them is xperf, or the Windows Performance Toolkit. It enables you to capture performance traces for your box. The whole range of tools for tracing and logging on the windows platform are still somewhat scattered and are not yet on the end-to-end monitoring that tools like AppSight (now from BMC) provide. However the Microsoft Teams are working on it and we will get solutions in the next year.

Another tool worth mentioning is MeasureIt. Nice to see Vance Morrison use his own tool to demo the different performance characteristics of single operations in the framework. He is really an performance architect to my heart. Working out which collection classes you should use (none), how a faster serailizer can be written and best of all find a performance bug in Activator.CreateInstance, a bug that is going to be solved.

Rob did log the most interesting links:

Measure Early and Often for Performance, part 1 & part 2

- What Every Dev Must Know About Multithreaded Apps

- CLR Profiler

- Visual Round Trip Analyzer (vrta.msi) link (still) broken…

- Vadump

- Pigs can fly

- Windows Performance Tools Kit

If you are into performance it is worth getting your hands on the deck...

Posted by Rene Schrieken | with no comments
Filed under:

Mount Hollywood

This was about to happen. Naturally when you are in LA, in West Hollywood you have to visit Mount Hollywood (or Mount Lee if you're only for the sign in LA). But before I set off I had to pack my stuff and say goodbye to my B&B. It worked out like I hoped for, an laid-back approach, good room, great breakfast, good location for getting around in LA.

To start the walk (rather not call it a hike) I parked in griffith park and from there I headed for the observatory strangely enough named after the Park. The observatory is located on a nice hillside which is reachable just under 30 minutes. Over there you find out that you could also have taken the car to get in front of the observatory.

From the observatory to head for Mount Hollywood but before that take a 'I was here picture' from the hollywood sign because on top of Mount Hollywood the angle for viewing the sign is not well.

 A very wide fire road leads you to the top of Mount Hollywood. That a fire road is needed becomes clear as you are actually walking across an area that has been recently hit by brush fire. There are no trees or other shady bits so make sure you are in enough supply of water and sunblock. After a 30 minutes uphill hike you reach the top where you are met with some nice overviews of the LA-bassin and thr surrounding mountains.

The reward is worth the effort.

Tnx LA for a lovely stay.

Posted by Rene Schrieken | with no comments
Filed under:

Mount Williamson

With 8214 feet this days mountain will be the highest of my trip. Off course higher peaks are available (Mount Baldy being the highest) but I considered them either to far or to difficult yet to conquer. To get to the start point to need to drive the Angles Crest Highway to the parking lot at Islip saddle, just past two tunnels. Any further was not posible anyway.

From the car park the trail named Silver Moccasin leads you in a moderate ascent with steep drop offs through low bushes and white fir and jeffrey pines (got that from the hiking booklet). Quickly you are up to some beautifull views across the San Gabriel crest.

And this was only 2 miles in the trip. After the much needed water and sandwiches entered the system I was ready for the last stretch towards the summit and the steepest part of the hike. The pros for hiking at this altitude is the lower temperature which make you sweat less, the cons is the very much unpaved road. It needs some clever navigation to choose a path that is and doable and doesn't lead you to a dead-end (on a 200 feet cliff).

After reaching the top the views are much different when you look into easterly direction.

The mojave dessert lay at your feet. The contrast couldn't have been higher.  

 

 

Posted by Rene Schrieken | with no comments
Filed under:

Take a break

Today no thrilling new hikes. I did get out just to get some mileage but I had to adjust my plans just as I arrived at Trippet Ranch. The area was closed because of the high danger for bush fires. So I drove to Agoura hills to walk into the Cheeseboro canyon and take it easy.

b

You see: all joy. Or this explains why I'm not IT's next top model.

I already told you I drive around the Los Angeles County. The lonely planet warned for the driving habbits of the LA-inhabitants but it feels not much different than in the Netherlands. You just have to watch out for at least 3 cars, the one in the front, the one in the back and the one left of you. If they don't start touching you or you don't start touching them you can continue. The only difference between here in LA and at home the cars interchange every second. Just to monitor three cars assumes you drive on the far right of the road. And that causes a bit of an issue. Because most of the time you're screwed in the right lane. Either the lane changes in a 'right lane must turn' strip in the most unexpected moments (I have a GPS in the car, it recalculates new routes very often), a parked car comes into sight or you're sandwiched between traffic leaving and entering the highway/freeway/interstate. A better choice is to keep as far left as possible (but still keep the right part of the road, you're not in Great Britain). The problem then is speeding. All cars are by definition driving to fast. And I'm not saying that I never drive too fast but I really don't want to be booked here. So I most of the time end-up somewhere in the middle of the road having to keep track of all traffic around me.

This in the VW rabbit (2.5 litres: that is far more that I have in the Netherlands in my Renault Megane, but I also had to re-fuel on tuesday, which is also far more often than in the Netherlands). Not sure about those environmental aware californians. On the other hand: they still have some things to improve their CO2 bookmark.

(picture taken at the car park at the Josphine Saddle Trail head) 

 

 

 

Posted by Rene Schrieken | 1 comment(s)
Filed under:

Sandstone Peak

Having been in cayons for the lats few days I decided it was time for some serious work. The Sandstone Peak Loop of 6 miles and an elevation of 1300 feet seemed a good choice. Sandstone Peak is the highest mountain within the Santa Monica Mountains. The peak is located in the middle of what's called Circle X Ranch. It is an hour ride from Hollywood and the last miles of Yerba Buena Road winds itselfs around rough rock formations and beatifull views to the Mishe Mokwa Trail head.

After a mile into the walk the balanced rock comes into view. It is not hard to recognize and it doesn't need a lot of imagination to understand why it is named that way.

The lunch stop was at split rock. From this point onwards no more shady bits, just open wilderness. The factor 30 sunmilk is used a lot. The hike continuous to reach Backbone trail just below a few giant watertanks. From there I reached the first goal of this days hike: Inspiration Point.  

This point is just on 2800 feet elevation.

The last stretch brings me to the small path that heads up to Sandstone peak and brings me to the highest point in the hike, 3111 feet. The last few feet require some mountaineering but the views are more than worth it.

 

I'm not sure if you can read the plaquette but it states 'Mt. Allen'. The fact is that it is also Sandstone Peak. Names doesn't tell it all though. This rock is not from Sandstone, it is some volcanic rock, very, very hard. Looking around gives you views on the ocean, the LA bassin (smoggy) and the San Gabriel Mountains. When the body and mind is focussed again for finishing this hike I head downhill to reach the car on the exact spot I left it.

Encountered species:
Grey Squirels: 1
Rabbits: 1
Lizards: lost count
Birds: yes
Humans: 2

 

 

Posted by Rene Schrieken | 2 comment(s)
Filed under:

Sturtevant Falls

This day I opted for a moderate walk 4 and a half hours hike in a historic canyon and to a free-leaping watefall. The hike started with a 0.7 miles steep descent. This is always a great moment to realize that at the end of your day of have to walk uphill again.

Down in the canyon I was welcomed by the sign 'Bear Country'. I thought there was already enough danger out there but no, the califonians just added bears. Making a lot of noise should scare them away. Strangly enough the rules of the Angeles Forest prohibit making noise. I wonder if they will ever find out why so many hikers get killed by bears. 

The great thing about canyon walks is that they block the sun hence the tempertures are more convenient. On the downside you are always faced with a climb to reach the end and top of the canyon. But thas was for later, first find a real waterfall. 

On the  way to the fall I encountred my first snake. Tecnically speaking the snake encoutered me and decided to slide away into the fallen leaves, which give him away. He didn't rattle so it wasn't a rattle snake. Near the waterfall I was warned by an fellow hiker that a snake was passing the path.  It was a king snake, one of the not poissionous species but neither of us wanted to verify that.

A few miles in the hike the free falling waterfall appeared. The lack of water is also influencing this waterfall but at least for this one its intentions are clear.

From this point onwards the hike went uphill for 3 miles and I can tell you I was quite pleased to find that I reached spruce grove which marked the start of the return leg of my walk. Still a modest climb was needed to 3500 feet near mount Zion. By this time the battery of my camera was empty so no evidence. The last few miles just brought me back to my startpoint where I still had to face the 0.7 miles uphill.

Score for today:
Bears: 0
Mountain Lions:0
Rattle Snakes: 0
Snakes (non possiones): 2
Possiones Oak: yes

 

Posted by Rene Schrieken | with no comments
Filed under:

Colby Canyon and Josphine Saddle

This days hike went to the Angeles National Forest. You need a permit for parking the car so I first drove to the Los Angeles River Ranger District office to buy the permits. On my way I drove through area that was hit by the recent forest fire. It looks like a moon landscape. You realize that the warnings for the use of open fire are to be taken very serious.

In the Angeles National Forest I drove up the Angeles Crest Highway  past Clear Creek junction in the hart of the San Gabriel Mountains. There the Colby Canyon trail starts. I must admit that the trail gives you the oppertunity to either climb Josephine Peak or Strawberry Peak but in the ascent to Josepehine Saddle I realized that the last few months the extra hours on the project didn't helped the stamina. I had two options: go on in a terrible slow pace and return to the car far after sunset or just enjoy the views at the Saddle and then return. The latter was the obvious choice.

To give an impression of the Colby Canyon:


No rattlesnakes yet but the fast amount of lizards can't be missed:

Posted by Rene Schrieken | with no comments
Filed under:

Latency and Througput

Yesterday I drove with my rented VW Rabbit to the visitor centre of the Santa Monica Mountains in Thousands Oaks. The lady at the desk provided me with the maps for the different areas and the well ment advice: be aware of the mountain lion. She didn't mentioned the Poison Oak and the rattle snake though.

I picked 'the waterfall' as my destination. Water is a problem in California so I shouldn't expect much 'fall' more 'drizzle', explained the desk lady. I took the car (somehow the visitor centre is in the middle of town, far, far away from the actual parks) and arrived ten minutes later at the car park. The Rancho Sierra Vista/Satwiwa park was home for centuries for farming and ranching.

 

After a hike of 2 hours I finally got to the 'waterfall'. Calling it a drizzle is offensive to drizzle. I would like to stick with 'drip'. The water dripped form basin to the other, several times.

 And that reminded me immidiately of our latency (but maybe also througput) issues of our prodcution server located in a datacentre in Silicon Valley. We ran several tests from The Netherlands and India but always ended up with complaints on the performance. We claimed the fast atalantic ocean contributed to this and now I confirmed. From West Holywood the performance is great. It simply takes too long for the water to reach its goal: The bottom of the canyon, enabling the plants, wildlife and trees to flourish.

 

Posted by Rene Schrieken | with no comments
Filed under:

PDC 2008

It is al in the pocket now. I'm going (again) to the PDC in LA. To get final approval the signatures of three managers were needed and the team secretary was kind enough to arrange my flight. As far as I know a rather large group of dutch developers and architects is heading for LA. We'll meet near the Starbuck coffee corner at the first floor.

Posted by Rene Schrieken | 2 comment(s)
Filed under:

I'm done!

Ok, so I was finished at speakers talent. I didn't win.

I must admit that I picked up some nerves before but it struck me hard when I realized in the first 10 seconds of so of my 5 minutes talk that the sound system quality was so poor that nobody was going to hear me. It took me off balance for about 30 seconds, ruining the best part of my talk (which should have had two jokes in it). After that I steered smoothly to the end and the full fledged demo (TFS and VS2005, running a teambuild) did work! 

Things I learned today:

  • Check the sound system when there are enough people around
  • If you can present in your native language, do so.
  • Try to make the best of it, even you find the setting not ideal.

I know by now that I need some more practice. So if anyone is interested in having a demo on TeamBuild (or Service Factory) give me call!

When time permits I will create a screencast of my presentation, afterall I have a full five minute script now!

I'm finished...

I like challenges but this dive might be just too deep. If you're in for a laugh (or really think that I'm a nice guy) and you are around Amsterdam on june 13th (is that my lucky number?) come visit the DevDays. There I'll have my five minutes of fame, during the SpeakersTalent competition.

 

You wonder why I'm scared to death? Somehow I entered the competition  (in the jury Dino Esposito among others)requiring me to present in english. As you probably know by now, I'm not a native english writer, nor a native english speaker.

 

I'm going to practice my pronounciation for the rest of the weekend but I realize my chances for victory are slim.

 

CU on wednesday, june 13th between 12:00 and 13:00, at the Launch Auditorium in the RAI, Amsterdam :-) 

Windows Live Messenger needs to close

I'm not sure what happened with my company laptop still running Windows XP but it is clear that something is going wrong.

 

 

 

 

 

 

 

 

This screenshot is NOT manipulated. Actually the 'we need to close' box shows first. Then the main Live Messenger window show and I can start a conversation. As long as I don't click 'Send error report' or 'Don't Send' everything works fine. As soon as I do click any button party is over and I have to restart Messenger.

I'm also very sorry for the inconvenience....

;-)

Posted by Rene Schrieken | 1 comment(s)
Filed under:

Design for Testability, NMock and CodeCoverage

In one of my previous posts I showed some code calling the Team Foundation Server. During test runs I had a reference to our production TFS box. You can imagine that carefull testing was the first law to obey, hence the built-in option 'Emulate' to not really destroy anything.

For Unit testing this approach was somewhat cumbersome so I needed a better approach. My first class model looked like this:

In this model I have two dependencies on two external types in the assembly Microsoft.TeamFoundation.Build.Proxy. During Unit testing I want to call an instance of those classes that have the same signature. NMock provide such functionality. It simulates an actual class. To instantiate an Mock class you need to provide it an interface. Time for some refactoring.

As you can see the Action classes now depend on the new Interface ITeamFoundationServer. The  class TeamFoundationServer implements that interface and has dependencies on the  TFS classes.   The Action classes obtain an instance to an implementation of ITeamFoundationServer by calling the static property Instance on the TeamFoundationServer class. So this class also acts as a Factory.

Mock

When we are running a unit test we want to provide our own implementation of the ITeamFoundationServer interface. For this to happen we need a form of dependency injection. As I do not want to introduce a complete, full blown dependency injection framework (I could have used ObjectBuilder), I simply provide a dependency injection constructor on the TeamFoundationServer class. The constructor accepts an ITeamFoundationServer implementation and sets the corresponding private static field _Instance. The default constructor is private which prevents instantiating the TeamFoundationServer class from non-testing code.

After you added a reference to the NMock assembly you can start creating Mocks in your test method. First you start off with creating a Mockery object and then you're ready for creating a mock object for the interface. The instance returned from that call is injected in our code by the means of the dependency constructor as shown in the following snippet:

Mockery mock = new Mockery();
ITeamFoundationServer itfsMock = (ITeamFoundationServer) mock.NewMock(typeof(ITeamFoundationServer));
TeamFoundationServer tfsDummy = new TeamFoundationServer(itfsMock);

The next step is to define what call will be expected on the interface and which return values should be delivered in that case. For example:

Expect.Once.On(itfsMock).Method("GetListOfBuilds").With(new object[] {"par1", "par2"}).Will(Return.Value(TestData()));

This tells the NMock framework to expect one call to GetListOfBuilds with two string parameters. That call will return testdata. The testdata is choosen so that it exercises different execution paths to maximize codecoverage. Now you're ready to  make the call to your class/classes under test. As the call returns one final call to the mock framework will check that all of our expected calls have been taking place.

mock.VerifyAllExpectationsHaveBeenMet();

We now have a unit test that can safely run without the need for an up-and-running teamfoundationserver. So everybody can relax...

CodeCoverage

The best thing of the mock object is the flexibility in accepting and returning data for testcases that would require running complex database scripts or infrastructure. You can even throw exceptions. Having said that there is no reason for a codecoverage of less than 100%.

If you have no ambition you're close to death. It is however hard to reach 100%. In my case the real implementation was also taken into account for the coverage and was off-course not covered by any test. In the first run only 60% of the code was covered. By adding more testcases (and richer testdata), refactor out common code and having the mock framework throw excpetions I achieved over 80%.

To reach the 90% I needed some trickery. Inspection of the non-coveraged code blocks revealed that some private constructors were not called. With some reflection magic that can be solved:

Type tfsType = typeof(TeamFoundationServer);
ConstructorInfo[] call = tfsType.GetConstructors(BindingFlags.NonPublic | BindingFlags.CreateInstance | BindingFlags.Instance);
object tfsInstance = call[0].Invoke(null);

Also the Dispose method was not fully covered because some internal fields where never set. Also for this CodeCoverageCase some reflection magic was needed. This is how you achieve that. Pay attention to the fact that this field is private so it can not be set from the testcode.

tfsInstance.InvokeMember("_Instance",
  BindingFlags.Instance | BindingFlags.SetField | BindingFlags.NonPublic,
  null,
  tfsInstance,
  new object[] { tfsInstance });

Calling Dispose now did exercise all code paths.

Click to enlarge 

Conclusion

If you're serious about Unit testing you need to design for testability. A good test design enables the Unit test to insert Mock objects without cluttering you're code with test artifacts. Using Mock objects gives you the ability to test even complex sceanrio's relatively simple. Using Code coverage to measure the effectiveness of your unit tests is a best practise. To achieve top code coverage ratings you might need some magic.

EntLib 3.0 CTP Validation block

The first CTP release of the Enterprise Library, which is available for download from CodePlex, contains the first release of the long awaited Validation block.

Tom already gave some insight in what could be expected. Today I downloaded the bits and investigated the current implementation.

First of all: the help documentation is not ready and the EntLib Config application does not handle the validation block yet.

I will demo here two of the posible validation scenario's. First of all the validation based on Attributes. You simply take the data class and decorate the properties or fields with the validation attributes.

public class Customer
{
  [StringLengthValidator(2,15)]
  public string Name;

  [TodayValidator()]
  public DateTime BirthDate;
}

On the Name field we see StringLengthValidator that will validate if a Name has a length of minimum 2 and maximum 15.

On the BirthDate field I created a Validator myself. It validates if the Birthdate is less than the current date. Creating a custom validator is simple by just inheriting ValidatorAttribute:

public class TodayValidator : ValidatorAttribute
{
  public override IValidator CreateValidator() 
  {
    return new RangeValidator<DateTime>(DateTime.Now);
  }
}

To check if the defined validations are met the following code is used:

ValidationResults attributedValidation = Validation.Validate<Customer>(customer);

foreach (ValidationResult result in attributedValidation)
{
  Console.WriteLine("{0}:{1}", result.Key, result.Message);
}

The ValidationResults class has also an IsValid property which is set accordingly.

One of the nice things is the posibility to define the validation rules in a configurationsource, for example the app.config file.

The following config defines two rulesets and the stringlength validator on the name attribute of the Customer class:

<configSections>
  <section name="validation"   type="Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.ValidationSettings, Microsoft.Practices.EnterpriseLibrary.Validation" />
</configSections>
<validation>
  <type name="Entlib3Ctp.Customer" defaultRule="relaxed">
    <rule name="relaxed">
      <fields>
        <field name="Name">
          <add name="NameMaxLength" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator, Microsoft.Practices.EnterpriseLibrary.Validation" upperBound="15" upperBoundType="Inclusive"/>
        </field>
     </fields>
   </rule>
   <rule name="strong">
     <fields>
        <field name="Name">
         <add name="NameMaxLength" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator, Microsoft.Practices.EnterpriseLibrary.Validation" upperBound="10" upperBoundType="Inclusive"/>
        </field>
      </fields>
    </rule>
  </type>
</validation>

In the validaton config first define the Type for which the rules are to be used. Then you define one or more rules. Within each rule you configurate the field  the validators  should act on.

By using a name for the ruleset you can switch in code between relaxed and a more tight validation. The relaxed validation can be used for example if the user needs to store the data temporary.

To choose which ruleset to use call the ValidationFactory:

IValidator<Customer> strongRules = ValidationFactory.CreateValidatorFromConfiguration<Customer>("strong");

In this case the "strong" rules are loaded and therefore the Name field of the Customer object should be no more than 10 characters.

I do not want to give any indications on performance of the validation logic but I will share some of my observations. First of all the call to Validation.Validate will create the validators based on the configuration source AND attributes in each call. If you need to validate the same object type multiple times create the validators only once by calling the appropiate ValidationFactory method. In the current CTP version creating the validators based on attributes takes approximately twice the time than creation of the validators defined in the app.config. If you know you're ruleset is in the config file use the methods ...FromConfiguration to prevent reflecting over your type.

The first look at the Validation block from the Enterprise Library 3.0 looks very promising. It will be a good fit for most of the projects.

In the attached zip you will find a small demo project.

Posted by Rene Schrieken | 3 comment(s)
Filed under:

Delete builds during the build

Now that is an intriguing title. But if you are using Team Foundation Server and especially Team Build you know where I'm talking about.

If you use the team build as the heart beat of your project and therefore build daily (or nightly if you're in the java camp) you end up with a large list  of Builds. Most of them are probably failed (just kidding), some of them have a build quality of unexamined and most of them are so old you probalby never want to touch or install any of it.

So you want to get rid of the old builds. Luckily you can. Microsoft provided us with a nice command line utility called tfsbuild which enable you to remove completed builds. Just provide a projectname and a buildnumber. Repeat 400 times until all unwanted builds are deleted.

There must be an easier way. I already found this solution but in our development shop I'm not the owner of the buildbox. Handing over the control of which builds to delete to an uncontrolled service didn't appealed to me much.

So reinvent the wheel to come up with a for me more suitable solution. Create a msbuild Task that deletes builds based on criteria that are provided in the build script. In the download you'll find the source (so you can see that there is no virus in it) of the build task that enables you to delete builds from the BuildStore. If you place the compiled assembly in the same source control folder where tfsbuild.proj resides you can start configuring.

In your tfsbuild.proj script do this:

<UsingTask AssemblyFile="DeleteBuildEasy.dll" TaskName="DeleteBuilds" />

<Target Name="AfterEndToEndIteration">
<DeleteBuilds 
   TeamServer="[your tfs server]" <!-- tfs:8080 -->
   TeamProject="$(TeamProject)"   
   BuildType="$(BuildType)" 
   Status="Failed"      
   Quality="Unexamined"

   Days="20" />
</Target>

Check-in all your changes, kick-off your build and you'll see the builds disappear as snow for the sun. Having the Days as selection mechanism quarantees that you do not have to modify the script day after day. If you come up with a good set of thresholds you can leave it running without any aftercare.

Best of all is that not only you're builds from the BuildStore will disappaer but also the files on you're buildserver will be removed, so it really cleans up.

This attached source code shows the basic mechanism. I have a more advanced version available. That one will also be able to run as service (as mentioned earlier) and has a more sophisticated query mechanism. Just contact me if you're intereseted in that version.

[UPDATE]

When you use this task on a TFS2008 based server keep in mind that this task DOESN'T honor the KeepForever=true property. As a matter of fact it will happily remove the build.

Source code is here

More Posts Next page »