Pages

Saturday, 10 September 2011

Fire-proof Software #2: Designing Fault Tolerant Systems

OLYMPUS DIGITAL CAMERA

Follow-up from part 1.

This is a few of the failure conditions we see with real production software, along with some approaches to deal with them. The general idea is to define activities.

  • Each activity is a unit of work that may either complete or fail and that can be retried if necessary.
  • An activity has a start and an end, as well as a status (Complete/Failed).
  • An activity also has success criteria that allow a process to check the activity actually completed.

The database contains a schedule of those activities along with a MaxRunTime value and a flag indicating if it's currently running. The MaxRunTime allows processes to spot an activity that timed out.

Input data not available (Failure of one of the upstream systems)

You can’t bet on the fact that upstream systems will work, regardless of the reason why, they will fail. There is no point trying to imagine the reasons behind the potential failure, what matters is the impact of the failure on your system and on the business.

  • Have a retry policy for each activity (retry period + retry window)
  • Use a stale version of the data (previous day for instance) if acceptable with the business.

Notification not available

  • Back-up the notification mechanism with an activity schedule: an activity should automatically start at a defined time if it hasn’t already.
  • If an activity has already started following a notification, the DB flag in the activity schedule table will guarantee that it doesn't start again.

Process crash

  • Have a Windows service detect the process crash and restart the process.
  • If the process crashes following an unhandled exception, the currently running activity will be automatically marked as failed. When the process starts again it should attempt to schedule or start the failed activity.
  • If the process is simply killed with no opportunity to mark the current activity as failed the activity will still appear as running in the ActivitySchedule. When the process starts again it will see that its activity is currently running and will simply schedule a check at StartTime + MaxRunTime. Obviously the check will fail and the process will restart the activity.

Process stalls

  • Kill it with a watchdog thread: this is a pattern used by embedded systems on real-time OSs to reset a stalled CPU. Inside the app server process the main thread –the one that does all the work- should periodically reset the watchdog flag. If the watchdog flag is not reset after a defined period of time the watchdog thread kills the process after failing the current activity.

Server down or unreachable

  • Use 2 servers, one primary and one backup.
  • Each server runs identical processes scheduling the same activities. Both processes will attempt to start their activity at the same time however the ActivitySchedule table in the DB will allow only one process to actually start the activity.
  • If one server goes down, all processes will simply attempt to reschedule their activities upon restart.
  • If one server goes down while an activity is running, the activity will still appear as running in the ActivitySchedule. Upon restart processes will see the activity is marked as running and will schedule a check at the expected completion time.

Database not available

  • Avoid maintaining a single DB connection for too long, that reduces the opportunities of the system to reconnect.
  • If you can detect the connection failure and don’t want the complexity of implementing a retry mechanism, at least fail the current activity to take advantage of the activity’s retry policy.

Saturday, 3 September 2011

Sink-Proof Software #1: Designing Fault Tolerant Systems

OLYMPUS DIGITAL CAMERAMiddleware Enterprise apps usually do straightforward things: they pump data from here, crunch it a bit, dump it there. Complexity comes from the variety of data sources, their reliability and more importantly how much availability (up-time) the business requires.

Say you write an app that processes a daily list of financial instruments to perform a Present Value calculation. What if the input data is not available, i.e. if that list of instruments is not ready? Do you raise a critical fault and give up? Do you use a stale list of instruments? Do you wait a bit and retry? How long should you retry, should you retry forever until the list is available or is there a point where you should give up? Should the retry period be constant or should it increase exponentially to save resources?

What if one of your processes was waiting for a notification from another system and that notification was never received?

What do you do if a process crashes because of an unhandled exception, an out-of-memory exception or a third-party library bug? Is there a system in place to restart the process automatically? Does it take over its task where it left off or does it restart from scratch?

What do you do if a process stalls? Because of a blocked DB call for instance, or some synchronous API call that never comes back…

What if that process was handling client requests? Do you have a backup process to handle the requests while the primary process recovers? Can the system handle a down time?

What do you do if the entire application server goes down either because an engineer tripped on the power cable, the server room was flooded by hurricane Irene, a plane crashed on your main datacentre, the datacentre's power supply failed or there is no more network connectivity to the datacentre?

What do you do if the database is not available for some time? Do you store data in memory temporarily? Do you detect it and try and reconnect or do you just fail on all subsequent DB calls? Do you reroute the DB logging to log files so that logs remain accessible?

Thursday, 18 August 2011

Do I need this config file?

Config files are all over the place with .NET: WCF, Log4Net, everything comes with an XML config file even if you didn't ask for one.

But when you think about it, why do you need config files really? Usually that's because you want to change some behaviour without having to rebuild the code. Ok. But what is so bad about rebuilding the code?

In the Enterprise world if you intend to make a change to a config file in production, you’re not going to just change the file on the production server (unless you're Jack Bauer and you have a death wish after your wife was murdered). You're going to make the change in the staging environment first then test it. If the system didn’t collapse then you'll raise a change request, have it approved by change management and eventually release it in prod. Well now compare that with rebuilding the code... mmm? Same amount of hassle, you'd have to go through the same steps anyway.

I find the main benefit of config files in Enterprise server apps is to ease the pain involved in moving from development to staging and from staging to production. This is where the config files are really useful because you have one code base for many environments. Connection strings, timeout values, environment identifiers, log file paths, simulated dates, weekend definitions, job start times, retry windows, SMTP servers, Tibco RV transport settings... They all depend on where you run the code from.

Friday, 1 July 2011

Using Mobile Broadband in Europe with Huawey Mifi

Blog 2011-09-03 001 (478x640) (373x500) (224x300)I was in Singapore recently and used the little Huawey with a local SIM card to get mobile internet for the iPhone, iPad and Vaio.

To do the same in Europe, I’m trying out MaxRoam. You pay 10 Euros for the SIM card then you top it up as you go.

Steps:

  1. Buy the card
  2. Activate it on the MaxRoam website
  3. Insert the SIM in the Mifi device
  4. Plug the Mifi device to your PC over USB
  5. Install the drivers located on the Mifi. This also creates a little shortcut on the desktop.
  6. Launch the shortcut that opens the configuration page of the Mifi.
  7. There you can unlock the SIM by typing its code and specify the MaxRoam APN details.
  8. The MaxRoam website tells you how much you have left on your account and lets you top-up.

Thursday, 26 May 2011

UK tech.days Day 3–Client Apps

The last day was all about writing Windows GUIs.

UKTechDays 2011-05-25 001During the intro Mark Quirk listed the technologies currently available for building client apps. He gave his personal recommendation about which one to choose: “if you’re not sure which one to go for give a try to Silverlight and see if it works for you.” When he asked “show of hands, who here has written code in Silverlight?” most of the attendees in the packed room raised their hand (I didn’t).

Amazing how Silverlight has quickly moved from something that was rather niche to a mainstream Windows technology. Now it is the toolkit you use by default when you don’t have a compelling reason to use any other (a bit like MFC 15 years ago). What used to be just a cut-down version of the .NET framework for browser plug-in is now much more…

Mike Taulty went over what’s coming in Silverlight 5:

  • access to low-level XNA APIs for 3D graphics
  • video: playback rate control and pitch correction
  • the client networking stack is faster and was moved to its own thread.
  • faster app startup through multi-core JITing
  • faster XAML parser
  • WS-Trust support for SAML security tokens
  • support for multiple top-level windows
  • trusted browser application: if you sign the XAP you can run an in-browser Silverlight app in fully trusted mode and therefore be able to do nasty things such as P/Invoke…

Impressive… One by one the limitations associated with Silverlight are going away.

Laurent Bugnion talked about MVVM, showing a solution where 3 projects (Silverlight, WPF and Web) were accessing the same service. Some videos of his previous talks here and here.

Wednesday, 25 May 2011

Windows Phone 7–Day 2 of UK tech.days

UKTechDays 2011-05-24 002

If (Developpers.Happy()) return OnInvestment;

Today’s track was all about Windows Phone 7.

Brendan Watson talked about the Windows Phone Marketplace.

There are currently 17000 apps registered in the market place. The average selling price of an app is $2.93.

The Nokia deal will bring more carrier partnerships with countries where it’s difficult to get into (China for instance).

You can currently create apps in 30 countries but sell them in only 16. This number is expected to go up to 35 by the time Mango comes out.

Something clever about the market place: devs have the possibility to initiate beta testing programs.

Most of the other talks centred around UI design and performance. We heard a good number of tips and tricks from coders who faced specific performance issues when building apps and showed how to solve them.

Gergely Orosz described how his team spent a month discussing how Cocktail Flow would look like, building photoshop prototypes.

  • small team, rapid prototyping and iteration.
  • full visual plans with Photoshop and Flash. Several iterations.
  • found inspiration in design guidelines for Windows Phone (MSDN)…
  • …and YouTube videos of app demos

Some of his graphic design tips:

  • You don’t have to stick with black (even if this is the default for most apps)
  • Use images in menu items. Square images with grey frame look good.
  • Use non dominant background images
  • Keep dominant images for headers
  • Spice up the buttons with gradients or different typo

Quotes from Gergely:

“Allow your designer gene to come out”

“Content is king but don’t ignore the chrome”

Oren Nachman gave lots of tips to optimise performance:

  • Don’t use the ProgressBar control that comes out the box. It’s jerky. Instead use the PerformanceProgressBar from the Silverlight Toolkit.
  • Enable RedrawRegions flag in debug mode to make it obvious when Silverlight is redrawing regions for no reason.
  • Use the CacheMode property (on the WrapPanel for instance) to put images on the GPU and avoid redrawing them.
  • Alternatives to the current ListBox: LongListSelector, LowProfileImageLoader

Also Oren mentioned that in the coming Mango release,

  • the ListBox was completely revisited and will be faster.
  • Networking: HttpWebRequest will take place on a background thread.

Tuesday, 24 May 2011

Overview of HTML5 – Day 1 of UK tech.days

UK Tech Days

It’s day 1 of UK Tech Days at the Vue cinema of Fulham Broadway where I attended the Web track.

I heard a number of talks today, one of them about HTML5 by Bruce Lawson.

HTML5 is an on-going effort and is not yet complete but lots of bits can already be used now.

In 1999 the W3C decided that HTML was finished and that the future was XML with XHTML1. Then it started planning XHTML2 where a lot of importance was given to language purity. No one cared.

Following work initiated by Ian Hickson with WHATWG, W3C decided to start working on HTML again and created HTML5. XHTML2 was eventually deprecated. So how come did HTML5 prevail on XHTML2? Bruce said:

  • it’s backward compatible with existing websites and
  • it’s more tolerant to error handling: the spec precisely defines what to do when markup does not validate.

The design principles that guide HTML5 are based around:

  • the 80/20 rule and
  • the belief that users are more important than authors, authors are more important than theoretical purity.

Other technologies not part of HTML5 but often used together: SVG, geolocation and CSS3.

HTML5 defines markup elements but also many JavaScript APIs.

HTML5 introduces the commonly used <div> as proper elements that actually mean something (header, footer, side bar). This makes it easier to build accessible apps because the browser can immediately identify the footer, the header, the side bar…

It also standardises some commonly used input forms (such as date pickers for instance) with the <input type=”…”/> element.

The <video> element displays play/pause controls on top of the video, works with many formats and remove the need for a plugin.

Media queries allow you to define several files with various resolutions depending on the capabilities of the device.

The <track> element shows subtitles over a video. The subtitles are in plain text therefore searchable and you can define several languages.

Other features:

  • detection of connection loss
  • offline application cache
  • server-sent events (to avoid polling)
  • web sockets

Good quotes by Bruce:

“HTML5 wants you to go to the pub”

“Nobody likes their bits to be in a black box, everybody likes their bits to be manipulated”

Wednesday, 18 May 2011

Upgrading from iPad1 to iPad2

It’s a bit thinner and a bit lighter, the screen is a bit brighter but nothing very spectacular.
The most striking difference is with the app start-up time. All apps that take a little while to load initially, such as BBC iPlayer, Google Earth, Friendly, Evernote, the New York Times, MobileRSS, BBC News all take less time to start-up on the iPad2.

And it's a bit more slippery as well when handled bare.

Facetime on a tablet is fun (although the image quality for the other party is better when using the iPhone 4, because the iPad2 camera is so poor). 

Monday, 16 May 2011

The New Safari Books Online app for iPad!

 

IMG_0005

At last!!! The reason why I bought an iPad in the first place! Being able to browse the wonderful Safari Books Online library from the iPad and download entire books for offline reading in the tube.

Last year O’Reilly released a first version of Safari To Go that was one of the worse apps on the planet at the time. They removed it from the app store less than a month after release.

So far the least worse way to browse the books from an iPad was to use the full web front-end, which wasn’t too bad with a browser supporting full-screen. But reading a book on the web was sluggish: you had to wait every time you clicked the next page, offline reading was not possible so no way to read in the London tube.

Version 2.0.1 of Safari To Go is a proper native iPad app that uses the whole screen and allows you to touch swipe between pages (compare that to the wasted space and sluggish web feel of version 1.0).

When flipping pages you have access to a very handy pop-up Table of Contents (I wish iBooks had that).

Table Of Contents

You can cache the entire book you’re currently reading. This is a very useful functionality that even the web front-end did not allow: all you could do with Safari Books Online was download individual chapters as PDF. Because there was a limit on how many chapters you could download each year you always had to think twice before downloading an entire book. That made offline reading very tedious.

Saving a book for offline use looks like this:

Offline Bookbag

Saving Offline Bookbag

Sunday, 8 May 2011

Conferences List

 

Conference When Next Where
FOWA Miami February   Miami
SXSW March   Austin
DevWeek March   London
Qcon March   London
DevTeach March   Toronto
MIX March April 12-14, 2011 Las Vegas
VBug4Thought April   Midlands, UK
Microsoft Tech Days UK April May 23-27, 2011 London
Future of Web Design May May 16-28, 2011 London
FOWA Dublin May   Dublin
DDD Southwest June   Bristol
Norwegian Developers Conference May May 25-27, 2011 Oslo
TechEd US May May 16-19, 2011 Atlanta
Code Generation June   Cambridge
TechEd Europe June June 25-29 2012 Amsterdam
FOWA London October   London
DDD Any time of the year   Reading
PDC November   Redmond
LeWeb December   Paris