The Inquisitive Coder – Davy Brion's Blog

Trying to walk that thin line between intelligence and ignorance

Archive for June, 2009

Avoid Using NHibernate With NUnit 2.4.6

Posted by Davy Brion on 24th June 2009

We just spent about 2 hours trying to find out why our NHibernate tests were about 10x slower on our build server than they were on our local machines. I had noticed lately that the build for one of our projects was taking longer and longer but i hadn’t really timed the difference. This project has about 1200 tests that use NHibernate and they run in about 45-60 seconds on my local machine. It turns out they took around 15 minutes on the buildserver when running them through TeamCity.

I logged into the buildserver and ran the tests manually using nunit’s console runner (with an NUnit-2.4.7 build that i happened to have installed somewhere on the machine) and they only took about 45 seconds. After a lot of guesswork and screwing around, it turned out that we never modified our base build script (why yes, i do believe in build script inheritance) to use a newer version of NUnit. We set up the buildserver about 1 year ago, and at that time, the latest stable NUnit version that TeamCity supported was NUnit 2.4.6. Our base build script was still referring to NUnit 2.4.6, which apparently sets log4net to use debug level logging. Now, NHibernate logs a huge amount of information at the debug level, so this turned out to slow down all of our builds that had NHibernate tests.

We changed the the 2.4.6 version in our script to 2.4.7 and the build time of this particular project decreased from around 50 minutes to about 35 minutes. Yes, that’s still a lot but this is a huge project with a lot of legacy tests and the entire build process is pretty complex. Other projects went from build times from around 7 minutes to about 2 minutes.

That’s a pretty nice improvement for simply changing a “6″ to a “7″ ;)

Posted in NHibernate, Performance, Test Driven Development | 3 Comments »

Surface Development For Belgian TV

Posted by Davy Brion on 22nd June 2009

Some of my coworkers recently developed 2 Surface applications for VTM, one of the commercial Belgian TV channels. This is one of the few high-profile usages of Microsoft’s Surface in Belgium so far. Be sure to check out the videos on our company website.

Posted in Software Development | No Comments »

And We’re Back

Posted by Davy Brion on 22nd June 2009

I got back from the Dominican Republic yesterday morning so i just wanted to post a short ‘review’ of the trip. Getting there took a looong time, because our plane first stopped in Cuba where we had to wait for another hour before we flew into Punta Cana. Unfortunately, we weren’t allowed to get off the plane for a short time which kinda sucks after 10 hours of flying. The little bit of Cuba i did get to see (through the window) did look pretty nice though. So after 13 hours we finally landed at Punta Cana’s airport and then we had to take a 2 hour bus ride to get to our hotel.

The hotel was great. Big, nice rooms. Lots of restaurants (4 plus a general buffet as well). Great pool, including a nice bar. Fantastic beach, also with a bar obviously. Plenty of activities and a few shops as well. If you really want to, you could have a pretty good time without even leaving the resort.

But that would be a bit of a shame because the country has so much more to offer than beautiful resorts. I went on two excursions while i was there. The first one was a snorkeling trip which was great. It was basically a whole day on a boat going along the Caribbean coastline, which in itself is already a sight to behold. Then there were 2 snorkeling sessions, one before noon, and one in the afternoon. For lunch, we went to the Saona island which you may know better as the Bounty Island (used in the commercials) to have a barbecue plus some relaxing on the beach. We also spent some time in a ‘natural swimming pool’ which is located within the sea on a huge sandbank (which was the result of a hurricane a few years back, as i’ve been told). It really is mindblowing to stand up in the middle of the ocean, with the water only reaching up to your waist.

The second excursion was a truck safari from the southern part of the island to the north side. I’d definitely recommend doing this because the sights you see along the way are unbelievably beautiful. And you don’t just spend the whole time in the truck either. We stopped along a sugar cane field and tried real sugar from a sugar cane. We also visited some people in the country side where we tried fresh coffee (from beans that had finished roasting in the sun just a few days ago), fresh cocoa (both in powder form after non-industrial processing as well as directly from the fruit), fresh Creole pine apple, coconuts, Mama Juana and other things as well. We had lunch on some ranch in the mountains (seeing large palm trees on top of high mountains is pretty cool as well) and after that we did some horseback riding. We also visited a tiny school (with only 2 classrooms) and a big church in Higuey which is apparently pretty famous. In the afternoon we stopped along a beach in the north side of the island (with the Atlantic ocean instead of the Carribean sea). We definitely saw a lot of beautiful things during this excursion. Funny side story: some British tourists that were also on the truck brought notepads and pens for the poor children we’d meet along the way. During one of our walks, they gave them to two kids who were sitting in front of their house. What these tourists didn’t realize was that those kids were sitting in front of a very nice house which actually had a beautiful pool in the backyard. Good thing these poor kids now also have notepads and pens ;)

Combining these excursions with a lot of relaxing at the beach definitely makes for a great trip. I’m not really a going-to-the-beach-kinda-guy but the Bahayibe beach and the Carribean Sea are just too nice to pass up on. And the water is just incredible… it’s crystal clear, it’s very warm, and occasionally you’ll see a bunch of colorful fish swim by or even around you.

The one downside to the trip was that there was hardly anything to do at night where we were. The northern side apparently has a lot more going on at night (it’s only normal with all the mass-tourism over there) but on the southern side there’s really not much to do outside of what’s going on in your resort. I was there with my best friend so we were hoping for some interesting bars to go to at night, but we mostly stuck to the lobby bar in the resort for a lack of anything better. You could just go to local towns and visit the bars over there but that’s not really recommended unless you’re with a reasonably-sized group to avoid trouble.

But apart from that, everything was great and i’d definitely recommend it to anyone. And after all of that, we spent another 9 hours on a plane to land in Brussels with pouring rain and pretty chilly weather *Sigh*.

I still have to go through a couple hundred blog posts that i missed, a shitload of email and some other stuff i have to do as well. I’ll start posting and coding again in the next couple of days though ;)

Posted in Off Topic | 1 Comment »

Time For A Much Needed Break

Posted by Davy Brion on 7th June 2009

As you have probably noticed, i haven’t been very active lately. Mostly because of some situations in my personal life lately which took up a lot of my spare time. Because of this, i haven’t been posting as much as i used to, nor did i contribute anything to NHibernate in the past couple of weeks. Luckily for me, i’m leaving for a trip to the Dominican Republic in a couple of days where i intend to explore the limits of the concept “relaxation”. As much as i love software development and computers, i’m really looking forward to not even touching a computer (or any electronic device for that matter) for about 10 days :) . Who could think of computers when you’re hanging out a place that looks like this:

paradise

I’ll see you all in about 2 weeks :)

Posted in Off Topic | 10 Comments »

How Can This Test Fail?

Posted by Davy Brion on 3rd June 2009

We have a certain class which sometimes makes some tests fail… the code is old (consider it legacy) but it’s not that bad… but we just can’t figure out why it sometimes causes tests the fail.

Here’s an example of a test that occasionally fails:

        [Test]

        public void TestGet_CacheableObjectReturned()

        {

            TestCacheableObject cacheableObject = new TestCacheableObject("test", 60000);

 

            CacheProvider.GetInstance().Put(cacheableObject);

 

            try

            {

                Assert.AreSame(cacheableObject, CacheProvider.GetInstance().Get("test"));

            }

            finally

            {

                CacheProvider.GetInstance().Remove("test");

            }

        }

If it fails, it’s on the following line:

                Assert.AreSame(cacheableObject, CacheProvider.GetInstance().Get("test"));

Sometimes, the Get method of the CacheProvider returns null in this test, even though the cacheable object has just been added to the CacheProvider.

Here’s the code of the CacheProvider:

    public class CacheProvider

    {

        private static object monitor = new object();

 

        private static CacheProvider _instance;

 

        private IDictionary<object, CacheableObject> _cacheDictionary;

 

        private CacheProvider()

        {

            _cacheDictionary = new Dictionary<object, CacheableObject>();

        }

 

        public static CacheProvider GetInstance()

        {

            lock (monitor)

            {

                if (_instance == null)

                {

                    _instance = new CacheProvider();

                }

            }

 

            return _instance;

        }

 

        public void Put(CacheableObject value)

        {

            if (ContainsKey(value.Key))

            {

                Remove(value.Key);

            }

 

            value.Provider = this;

            _cacheDictionary.Add(value.Key, value);

            value.StartTicking();

        }

 

        public CacheableObject Get(object key)

        {

            if (_cacheDictionary.ContainsKey(key))

            {

                return _cacheDictionary[key];

            }

 

            return null;

        }

 

        public void Remove(object key)

        {

            _cacheDictionary.Remove(key);

        }

 

        public bool ContainsKey(object key)

        {

            return _cacheDictionary.ContainsKey(key);

        }

    }

This is the code of the CacheableObject class:

    public abstract class CacheableObject

    {

        private object _key;

        private CacheProvider _cacheProvider;

 

        private Timer _timer;

 

        protected abstract double GetTimeToLive();

 

        public CacheableObject(object key)

        {

            _key = key;

        }

 

        public void StartTicking()

        {

            _timer = new Timer(GetTimeToLive());

            _timer.Elapsed += Timer_Elapsed;

            _timer.Start();

        }

 

        private void Timer_Elapsed(object sender, ElapsedEventArgs e)

        {

            _timer.Stop();

            Provider.Remove(this.Key);

        }

 

        public object Key

        {

            get

            {

                return _key;

            }

        }

 

        public CacheProvider Provider

        {

            get

            {

                return _cacheProvider;

            }

            set

            {

                _cacheProvider = value;

            }

        }

    }

And this is the code of the TestCacheableObject that is used in the failing test:

        public class TestCacheableObject : CacheableObject

        {

            private double _ttl;

 

            public TestCacheableObject(string key, double ttl)

                : base(key)

            {

                _ttl = ttl;

            }

 

            protected override double GetTimeToLive()

            {

                return _ttl;

            }

        }

I can’t for the life of me figure out why the test above fails sometimes. It happens very occassionaly, sometimes it even takes weeks or months before it fails again. It’s not just the test above, it’s basically every test that uses the CacheProvider’s ContainsKey method (either directly or indirectly) that fails sometimes.

Important note to consider: when these tests fail, they take about 10ms…

If anyone has a clue what could possibly cause this, i’d be very willing to hear it :)

Posted in Test Driven Development | 24 Comments »