Category Archives: tools

Site uptime monitoring

siteuptimeMy PerfectTablePlan website and all the associated websites (such as http://www.weddingtableplan.com) have gone down three times this week. Sigh. The first time they went down for 5 hours, the second time for 3.5 hours and the third time for 6 hours. Perhaps they have been overdoing the festivities at my ISP, 1and1.co.uk . I am not impressed. Somebody needs a good kick up the arse.

To rub salt into the wound they even had the cheek to put up parking pages with ads in place of my sites. Some of these ads were for my own sites, which also displayed parking pages  – with more ads. So 1and1 were potentially taking money off me through adwords at the same time! I have a feeling 1and1 and I may be parting company in the not too distant future.

I am now setting up a copy of my site with a different ISP. If (when?) the site goes down again I should be able to point the DNS to the backup ISP.

At least I found out about it quickly due to site monitoring service www.siteuptime.com . I use their free service, which is adequate for my needs at present. Are you monitoring your site(s)? Do you have a back-up plan?

Optimising your application

When I first released PerfectTablePlan I considered 50-200 guests as a typical event size, with 500+ guests a large event. But my customers have been using the software for ever larger events, with some as large as 3000 guests. While the software could cope with this number of guests, it wasn’t very responsive. In particular the genetic algorithm I use to optimise seating arrangements (which seats people together or apart, depending on their preferences) required running for at least an hour for the largest plans. This is hardly surprising when you consider that seating assignment is a combinatorial problem in the same NP-hard class as the notorious travelling salesman problem. The number of seating combinations for 1000 guests in 1000 seats is 1000!, which is a number with 2,658 digits. Even the number of seating combinations for just 60 guests is more than the number of atoms in the known universe. But customers really don’t care about how mathematically intractable a problem is. They just want it solved. Now. Or at least by the time they get back from their coffee. So I made a serious effort to optimise the performance in the latest release, particularly for the automatic seat assignment. Here are the results:

ptp308_vs_ptp_310.png

Total time taken to automatically assign seats in 128 sample table plans varying in size from 0 to 1500 guests

The chart shows that the new version automatically assigns seats more than 5 times faster over a wide range of table plans. The median improvement in speed is 66%, but the largest plans were solved over ten times faster. How did I do it? Mostly by straightening out a few kinks.

Some years ago I purchased my first dishwasher. I was really excited about being freed from the unspeakable tyranny of having to wash dishes by hand (bear with me). I installed it myself – how hard could it be? It took 10 hours to do a wash cycle. Convinced that the dishwasher was faulty I called the manufacturer. They sent out an engineer who quickly spotted that I had kinked the water inlet pipe as I had pushed the dishwasher into place. It was taking at least 9 hours to get enough water to start the cycle. Oops. As soon as the kink was straightened it worked perfectly, completing a cycle in less than an hour. Speeding up software is rather similar – you just need to straighten out the kinks. The trick is knowing where the kinks are. Experience has taught me that it is pretty much impossible to guess where the performance bottlenecks are in any non-trivial piece of software. You have to measure it using a profiler.

Unfortunately Visual Studio 2005 Standard doesn’t seem to include profiling tools. You have to pay for one of the more expensive versions of Visual Studio to get a profiler. This seems rather mean. But then again I was given a copy of VS2005 Standard for free by some nice Microsofties – after I had spent 10 minutes berating them on the awfulness of their “works with vista” program (shudder). So I used an evaluation version of LTProf. LTProf samples your running application a number of times per second, works out which line and function is being executed and uses this to build up a picture of where the program is spending most time.

After a bit of digging through the results I was able to identify a few kinks. Embarrassingly one of them was that the automatic seat assignment was reading a value from the Windows registry in a tight inner loop. Reading from the registry is very slow compared to reading from memory. Because the registry access was buried a few levels deep in function calls it wasn’t obvious that this was occurring. It was trivial to fix once identified. Another problem was that some intermediate values were being continually recalculated, even though none of the input values had changed. Again this was fairly trivial to fix. I also found that one part of the seat assignment genetic algorithm took time proportional to the square of the number of guests ( O(n^2) ). After quite a bit of work I was able to reduce this to a time linearly proportional to the number of guests (O(n) ). This led to big speed improvements for larger table plans. I didn’t attempt any further optimisation as I felt was getting into diminishing returns. I also straightened out some kinks in reading and writing files, redrawing seating charts and exporting data. The end result is that the new version of PerfectTablePlan is now much more usable for plans with 1000+ guests.

I was favourably impressed with LTProf and will probably buy a copy next time I need to do some optimisation. At $49.95 it is very cheap compared to many other profilers (Intel VTune is $699). LTProf was relatively simple to use and interpret, but it did have quirks. In particular, it showed some impossible call trees (showing X called by Y, where this wasn’t possible). This may have been an artefect of the sampling approach taken. I will probably also have a look at the free MacOSX Shark profiler at some point.

I also tried tweaking compiler settings to see how much difference this made. Results are shown below. You can see that there is a marked difference with and without compiler optimisation, and a noticeable difference between the -O1 and -O2 optimisations (the smaller the bar, the better, obviously):

vs2005_optimisation_speed.png

Effect of VS2005 compiler optimisation on automatic seating assignment run time

Obviously the results might be quite different for your own application, depending on the types of calculations you are doing. My genetic algorithm is requires large amounts of integer arithmetic and list traversal and manipulation.

The difference in executable sizes due to optimisation is small:

vs2005_optimisation_size.png

I tried the two other optimisation flags in addition to -O2.

  • /OPT:NOWIN98 – section alignment does not have to be optimal for Windows 98.
  • /GL – turns on global optimisation (e.g. across source files, instead of just within source files).

Neither made much noticeable difference:

vs2005_additional_opt.png

However it should be noted that most of the genetic algorithm is compiled in a single file already, so perhaps /GL couldn’t be expected to add much. I compared VC++6 and VS2005 version of the same program and found that VS2005 was significantly faster[1]:

vc6_vs_vs2005_optimisation_speed1.png

I also compared GCC compiler optimisation for the MacOSX version. Compared with VS2005 GCC has a more noticeable difference between optimised and unoptimised, but a smaller difference between the different optimisations:

gcc_optimisation_speed.png

Surprisingly -O3 was slower than -O2. Again the effect of optimisation on executable size is small.

gcc_optimisation_size2.png

I also tested the relative speeds of my 3 main development machines[2]:

relative-machine-speed.png

It is interesting to note that the XP box runs the seat assignment at near 100% CPU utilisation, but the Vista box never goes above 50% CPU utilisation. This is because the Vista box is a dual core, but my the seat assignment is currently only single threaded. I will probably add multi-threading in a future version to improve the CPU utilisation on multi-core machines.

In conclusion:

  • Don’t assume, measure. Use a profiler to find out where your application is spending all its time. It almost certainly won’t be where you expected.
  • Get the algorithm right. This can make orders of magnitude difference to the runtime.
  • Compiler optimisation is worth doing, perhaps giving a 2-4 times speed improvement over an application built without compiler optimisation. It probably isn’t worth spending too much time tweaking compiler settings though.
  • Don’t let a software engineer fit your dishwasher.

Further reading:

“Programming pearls” by Jon Bentley a classic book on programming and algorithms

“Everything is fast for small n” by Jeff Atwood on the Coding Horror blog

[1] Not strictly like-for-like as the VC++6 version used dynamic Qt libraries, while the VS2005 version used static Qt libraries.

[2] I am assuming that VS2005 and GCC produce comparably fast executables when both set to -O2.

Beware upgradeware

fungi.jpgSome years back my wife bought a PC and got a ‘free’ inkjet printer with it. It was a really lousy printer, but hey, it was free. When it ran out of ink we tried to get a new inkjet cartridge, but the cheapest set of cartridges we could find was £80. That was 4 times the price of other comparable cartridges at the time. Some further research showed that you could buy the printer for £20 – with cartridges! Their ugly sales tactics didn’t work. We threw it in the dustbin and bought an Epson inkjet, which gave years of sterling service using third party sets of cartridges costing less than £10.

When I started my company I had a thousand decisions to make. One of them was which software to use to create and maintain my new product website. It just so happened that my new ISP (1and1.co.uk) was offering a bundle of ‘free software worth £x’ when you signed up (I forget the amount). It included a web design package (NetObjects Fusion 8 ) and an FTP package (WISE-FTP). Hoorah, free (as in beer) software and 2 less decisions to make. I was weak. Instead of spending time checking out reviews and evaluating competitors, I just installed and starting using them. It didn’t occur to me that they might be using the same sales tactics as the manufacturer of the lousy printer. In this imperfect world, if something appears too good to be true, it usually is. And so it was in this case. I grew to hate both these pieces of software.

WISE-FTP was just flaky. It kept crashing and displaying German error messages, despite the fact that I had installed the English version. No problem, I just uninstalled and installed FileZilla which is free (as in beer and speech), stable and does everything I need and more.

NetObjects Fusion was flaky and hard to use. By saving after every edit I could minimise the effects of the regular crashes and I assumed that I would learn how to work around other problems in time. But I never did. By the time I decided that the problems were more due to the shortcomings of NetObjects Fusion as a software package, rather than my (many) shortcomings as a web designer, it was a little late. I had already created an entire website, which was now stored in NetObjects Fusion’s proprietary database. Some of the bugs in NetObjects Fusion are so major that one wonders how much testing the developers did. My ‘favourite’ is the one where clicking a row in a table causes the editor to scroll to the top the table. This is infuriating when you are editing a large table (my HTML skills haven’t yet reached the 21st century).

In despair I eventually paid good money to upgrade to NetObjects Fusion 10. Surely it would be more stable and less buggy after two major version releases? Bzzzzt, wrong. The table scrolling bug is still there and it crashed 3 times this morning in 10 minutes. Also, every time I start it up the screen flashes and I get the ominous Vista warning message “The color scheme has been changed to Windows Vista Basic. A running program isn’t compatible with certain visual elements of Windows”. Even just trying to buy the software upgrade off their website was a confusing nightmare. The trouble is that it is always easier in the short-term to put up with NetObject Fusion’s many shortcomings than to create the whole site anew in another package.

For want of a better term I call this sort of software ‘upgradeware’ – commercial software that is given away free in the hope that you will buy upgrades. This is quite distinct from the ‘try before you buy’ model, where the the free version is crippled or time-limited, or freeware, for which there is no charge ever. Upgradeware is the software equivalent of giving away a printer in the hope that you will buy overpriced cartridges. Only it is less risky, as the cost of giving away the software is effectively zero. It seems to be a favoured approach for selling inferior products and it is particularly successful when there is some sort of lock-in. It certainly worked for NetObjects in my case.

Norton Anti-virus are the masters of upgradeware. Norton Anti-virus frequently comes pre-installed on new PCs with a free 1-year subscription. The path of least resistance is to pay for upgrades when your free subscription runs out. By doing these deals with PC vendors, Symantec sell vast amounts of subscriptions, despite the fact that Norton Anti-virus has been shown in test after test to be more bloated and less effective than many of its competitors. And if you think Norton Anti-virus doesn’t have any lock-in, just try uninstalling it and installing something else. It is almost impossible to get rid of fully. Last time I tried I ended up in a situation where it said I couldn’t uninstall it, because it wasn’t installed, and I couldn’t re-install, because it was still installed.

I feel slightly better now that I have had a rant about some of my least favourite software. But there is also a more general point – ‘free’ commercial software can end up being very expensive. Time is money and I hate to think how much time I have wasted struggling with upgradeware. So be very wary of upgradeware, especially if there is any sort of lock-in. When I purchased a new Vista PC, the first thing I did was to reinstall Vista to get rid of all the upgradeware that Dell had installed (Dell wouldn’t supply it to me without it). You could also draw the alternative conclusion that upgradeware might be a good approach for making money from lousy software. But hang your head in shame if you are even thinking about it. It would be better for everyone if you just created a product that was good for customers to pay for it up-front.

Ps/ If you fancy the job of converting www.perfecttableplan.com to beautiful sparkly clean XHTML/CSS and your rates are reasonable – feel free to contact me with a quote.

Moving from POP3 to IMAP

palm.jpgI have been using the POP3 protocol to collect all my emails from my ISP for the last few years. POP3 stores emails locally once they have been read from the server. This works great if you have a single PC, but it is a bit of a disaster if you check your email from multiple PCs. For example, trying to synchronise the emails on my ‘master’ desktop PC after using the laptop for a week on holiday was a royal pain. I would set the laptop not to remove messages from the POP3 server when read (unless deleted) and then re-do all the marking as read, tagging and sorting into sub-folders when I got home. Groan.

I chose POP3 because I was familiar with it and because I was using some auto-responder software that only worked with POP3. Now that I use e-junkie for sending out licence keys I don’t really need the auto-responder. So I decided to try IMAP, an alternative protocol that stores emails on a central server. So far I am very pleased with the move.

I use Mozilla Thunderbird on all my computers and my email is hosted by 1and1.co.uk. Both Thunderbird and 1and1 support POP3 and IMAP, so this made the transition very easy. I just set-up new IMAP accounts for each email account on each machine in Thunderbird. The POP3 accounts are still there so I can search them, but they no longer retrieve new emails.

Now, when I mark an email read or move it to a sub-folder, the change is immediately visible across all my email clients. Hoorah. I realise the same could be said for webmail. But I then would have to use webmail. Ugh. Lets not go there.

I was a bit worried about network latency issues with IMAP, but it haven’t noticed any problems so far and searching IMAP emails on the 1and1 server seems similar in performance to searching POP3 emails locally.

I haven’t quite worked what to do about backing-up my email yet. With POP3 it was easy, as the data was stored as files on my local machine. I am not sure what the best way to achieve this is with IMAP. In theory my ISP should be taking care of backing-up my IMAP data, but I am a bit paranoid after the recent disappearance of this blog. It is something I need to investigate further.

I am fairly conservative when it comes to adopting new technologies. Most of you reading this probably moved to IMAP ages ago. But if you didn’t, you might want to give IMAP a try. Even if you are currently a one-person company with a single PC/Mac (unlikely) it is going to make life easier if you later grow to multiple machines and/or people.

Codekana

codekanaI don’t remember when or where I first saw an editor with syntax highlighting. But I do remember that I was ‘blown away’ by it. It was immediately obvious that it was going to make code easier to understand and syntax errors easier to spot. I would now hate to have to program without it. So I was interested to try version 1.1of CodeKana, a recently released C/C++/C# syntax highlighting add-in for Visual Studio.

Codekana features include:

  • Finer grained syntax highlighting than VS2005 provides.
  • Highlighting of non-matching brackets and braces as you type.
  • Easy switching between header and body files.

In the code below Codekana colours the if/else/while blocks differently and visually pairs the braces:

syntax highlighting

I have only been using Codekana a few hours, but I am already impressed. I find the ability to quickly switch between C++ header and body files particularly useful. VS2005 only appears to allows switching body to header, not header to body (doh!). You need the dexterity of a concert pianist for the default Codekana keyboard shortcut (Ctrl-Shift-Alt-O), but it can be customised. I changed it to Ctrl+. (dot) .

Codekana also has other features, such as the ability to zoom in/out on code. This is quite ‘cool’, but I’m not sure yet whether it will be of much use. Time will tell.

I am new to VS2005 and I have yet to try out other add-ins, such as Visual Assist, but Codekana certainly seems to have a lot of potential and is excellent value at $39. I look forward to seeing what other features get added in future versions. Find out more and download the free trial here.

Disclosure: The author of Codekana is a JoS regular who I have corresponded with in the past and was kind enough to send me a complimentary licence.