Optimistic Locking For Retrieving Result Sets

I’m in the middle of updating my Silverlight code to use asynchronous HTTP requests — fortunately, I spent last summer writing a GWT application, where HTTP requests have always been asynchronous, so I’ve got a library of patterns for solving common problems.

For instance, suppose that you’re doing a search, and then you’re displaying the result of the search. The most reliable way to do this is to use Pattern Zero, which is, do a single request to the server that retrieves all the information — in that case you don’t need to worry about what happens if, out of 20 HTTP requests, one fails.

Sometimes you can’t redesign the client-server protocol, or you’d like to take advantage of caching, in which case you might do something like this (in psuedo code):

getAListOfResults(new AsyncCallback {
     ... clearGUI();
         foreach(result as item) {
            fetchItem(item,new AsyncCallback {
               ... addItemToGui()
         }
}

First we retrieve a list of items, then we retrieve information about each item: this is straightforward, but not always reliable. Even if your application runs in a single thread, as it would in GWT or if you did everything in the UI thread in Silverlight, you can still have race conditions: for instance, results can come back in a random order, and getAListOfResults() can be called more than once by multiple callbacks — that’s really the worst of the problems, because it can cause results to appear more than once in the GUI.

There are a number of solutions to this problem, and a number of non-solutions. A simple solution is to make sure that getAListOfResults() never gets called until the result set has come back. I was able to do that for quite a while last summer, but the application finally reached a level of complexity where it was impossible… or would have required a major redesign of the app. Another is to use pessimistic locking: to not let getAListOfResults() run while result sets are coming back — I think this can be made to work, but if you’re not careful, your app can display stale data or permanently lock up.

Fortunately there’s a pattern to retrieve result sets using optimistic locking that displays fresh data and can’t fail catastrophically

Continue Reading »

Managing Concurrency With Asynchronous HTTP Requests

I developed a rather complicated GWT application last summer and spent plenty of time struggling with the concurrency issues involved with with applications that use asynchronous web requests: for instance, the HttpWebRequest in Silverlight or the XmlHttpRequest in Javascript. Up until Silverlight 2 beta, Silverlight programmers could perform synchronous requests, but the latest version of Silverlight supports only asynchronous requests… We’re scrambling to update our apps.

There’s a “standard model” that works for writing reliable, performant and secure RIAs — it works for GWT, Flex, and Silverlight and plain old AJAX apps too.

Continue Reading »

3 Comments »

Paul Houle on March 27th 2008 in Asynchronous Communications, Dot Net

Threading in C# and dot net

It’s not always easy to find good documentation online for the Microsoft universe, but Joe Albahari has written a great article about Threading in C#.

No Comments »

Paul Houle on March 26th 2008 in Dot Net

The Wisdom of a Closed Platform

Daniel Eran Dilger has been a leading writer about the iPhone since before it came out,  and this week he writes about the choices Apple made about concurrency in the iPhone.   Unlike Windows Mobile,  the iPhone only allows the user to have a single third-party application running at a time.  Dan makes the case that portables don’t provide a rich enough interface to let users juggle multiple running tasks (it’s hard enough to do this with a desktop computer) and that it won’t be possible to give a phone-like experience without tight control on process lifecycle.

He’s right.  I’ve got a friend who has an HTC handheld that runs Windows Mobile.  It looks nice,  and it’s got some good features,  but every so often it gets in a state that pegs the CPU at 100%;  it gets warm pretty quick,  so this can’t be good for battery life.  Vendors like Apple, Sun and Nintendo, who have a lot of control over hardware and software aspects of  platform,  can often users an experience that can’t be matched by more open platforms,  where no vendor claims responsibility for the performance of a system.

No Comments »

Paul Houle on March 13th 2008 in Media

Windows Server Core Installation

Tom’s Hardware has a nice review of the Core Installation of Windows Server 2008,  which makes it possible to install Windows Server 2008 with a limited GUI.  It’s exciting to see Windows get more mature and flexible:  the core install takes up about half the disk space of a conventional install.  However,  the fit and finish of the Core Installer is poor — for instance,  an administrator needs to type more than 900 characters on the command line to install Microsoft IIS.  We’ll give Microsoft another chance,  but,  for now,  the Core Installation is less mature than text-mode linux distributions were a decade ago.

Fit and finish are important factors in choosing a server operating system — I’ve been trying to repurpose an old laptop as a media server,  and finding it a challenge to find a modern Linux installation that installs without trouble on a machine with no DVD drive and limited RAM.

No Comments »

Paul Houle on March 12th 2008 in Uncategorized

Intrusion of the Real

Dave Bonta photographs a red hawk on the Penn State campus, and meditates on how people’s experience of nature is conditioned by our shared hyperreality. Dave notes that ‘a helpful webpage on film sound clichés, “the Red-Tailed Hawk scree signifies outdoors and a big, lonely place.” Anytime a rocky mountainside appears in a movie, you can almost count on hearing that raspy scream, which most people probably assume belongs to an eagle. It’s also used as an all-purpose signifier of impending or just-concluded drama in the typical outdoors adventure flick.’

Most students walked by obliviously while a handful used cellphone cameras to capture the hawk attacking it’s prey. He was left with an awkward feeling that he’d met a creature from another world — but wasn’t completely sure if he, or the hawk, were the alien visitor.

No Comments »

Paul Houle on March 11th 2008 in Media, Nature

Share My Web Statistics?

Michael Arrington at Tech Crunch announces that Google Analytics now lets webmasters share data with other Google products, and suggests that they should let us share web statistics with everyone, a suggestion that I find a little disturbing.

Like it or not, web marketing is cutthroat, and search engine optimizers are always looking for an edge on the competition — open web statistics are an invitation for somebody else to eat your lunch.

Personally, I like Quantcast, which provides public statistics about the readership of web sites that are useful for advertisers and others, but that respect the privacy of webmasters and users.

No Comments »

Paul Houle on March 6th 2008 in Analytics

The J-Factor

There’s a nice article at the Torque Report about the Toyota iQ,  which hits the road next fall.  In a bit of national pride,  Toyota based the design on the ‘J-Factor’,  “that aspect of Japanese originality and quality that creates modern, attractive, and globally appealing products from the apparent disharmony and contradictory nature of its original components.”  Toyota developed six major technical innovations to develop a car less than 3 meters with great drivability and comfortable seating for three adults and a child.

I’ve long noticed the difference in priorities between US and Japanese car manufacturers.  The Corolla and Civic were designed by people who are passionate about small cars — they’re small on the outside but big on the inside.  The Chevy Cobalt,  on the other hand,  seems to be designed by people who think that driving a small car is like wearing a hair shirt,  and even likable vehicles like the Dodge Caliber and  Buick Lacrosse seem quite puffy:  oddly small on the outside for the large exterior.

With gas at $3.40 a gallon and heading up,  we can only hope that American carmakers will focus innovation on fuel efficiency and appealing small cars rather than gimmicks such as OnStar and ultrasonic sensors to keep you from mashing the back wall of your garage with an oversized vehicle.

No Comments »

Paul Houle on March 6th 2008 in Design, Japan

Beautiful Morning

It looked like a winter wonderland when I woke up in Brooktondale this morning,  about 1000 feet above the lake.  I found that the ice had melted in Ithaca,  where I drove to do some business.  I drove up route 13  around 10 am,  on the stretch between Stewart Park and the Mall,  which cuts a diagonal up the Cayuga Lake Valley with sweeping vistas of Ithaca and the Lake.  I looked across the lake to the other side of the lake,  and noticed that above a certain altitude the trees were silvery — they were still covered with ice.  I rounded the bend at the end of the straight segment of the road and suddenly the trees around me were covered with ice as well.

One thing I like about the Ithaca area is the variation of microclimates:  it can be raining downtown but snowing at Cornell.  Downtown gardeners appreciate being able to grow plants that would otherwise need to be a few hundred miles south to grow;  the microclimates on the slopes of the finger lakes are essential for our growing wine industry.

No Comments »

Paul Houle on March 6th 2008 in Ithaca

Polyhedra.org

Our new web site, a collection of interactive 3-d polyhedra based on the canvas element and AJAX has just gone live.

It’s a really fun site that shows what can be done with Javascript in 2006. It turns out that Canvas performance is good enough in Firefox, Safari and Opera that simple 3-d rendering can be done in the browser. Unfortunately, it may be too late for Microsoft to add canvas support to IE, but the folks of Google have created a library that adds canvas support to Internet Explorer. Thanks to this, polyhedra.org works on IE, even if it is a little poky.

No Comments »

Paul Houle on June 13th 2006 in AJAX, Math, Web