Sunday, June 23, 2013

Setting up Dagger on Eclipse for Google App Engine

Dagger is a dependency injection framework similar to Guice, but code can be generated at compile time to wire together dependencies instead of using reflection at run time.  It's written by some of the same guys who created Guice and had problems with its speed when it runs on Android.

I also have problems with the start-up time of Guice on Google App Engine where "loading requests" can keep a user waiting for your app to get itself up and running.

Dagger promises to shave some precious seconds off this app startup time and probably also make each request faster.  Reflective calls on App Engine can be slow - I don't know how slow but will eventually run some tests to see how much difference Dagger makes.

To get it running in Eclipse you need to modify your projects settings under Java Compiler > Annotation Processing > Factory Path and add the following 4 jar files: dagger-x.x.x.jar, dagger-compiler-x.x.x.jar, javax.inject.jar and javawriter-x.x.x.jar

You also need to tick the "Enable project specific settings" in the parent configuration page" for these settings to take effect.

Tuesday, January 15, 2013

Whats the real uptime of Google App Engine?

One of the principal reasons for running your website on Goole App Engine is its high reliability.  Their engineers carry the pagers for you so when something goes wrong at 4am you can stay in bed while they scramble to sort it out.  That is great in theory but how well do they do their jobs?

The Service Level Agreement promises 99.95% "uptime" and defines compensation if that level is not met.  Uptime is defined by Google as more than 10% errors for the datastore or the serving infrastructure.  Most of the services such as the task queue, email, Blobstore and memcache are not covered at all.  They could go down taking your app with them but this is not considered downtime by the SLA.  Also, when the system is running slowly your sites get penalised by Googles ranking algorithm but slow responses are also not covered in the SLA.

Last night my application running on GAE had another outage which seem to be a lot more frequent than I expect.  Each time something happens they analyse the problem, post a message apologising and describe how they fixed something so it won't happen again .... but then something else happens to take the site off-line.

I monitor the site with Pingdom so I can  look at the historical "real uptime" of my app.  This is reported  as 99.87 uptime over the past 60 days.  Over this time the app has not been offline due to application failures - only infrastructure failures.

Slightly below their SLA requirements.

Pingdom also allows me to download the historical data as a csv and analyse it myself.  In the last 60 days they pinged my site 86400 times and it was down 196 times.  That is 0.23% downtime or 99.87% uptime.  Hey thats the same as the official figure!

But what if we add requests that took an unacceptable amount of time to return?  The average request time is about 800ms from the Pingdom servers and anything over 10 seconds is seriously slow.  There were also 270 pings that took longer than 10000ms but were logged as successful.  That would take the amount of "bad requests" to 0.54% or 99.46% uptime.  Requests over 5 seconds were more than twice this amount.  Lucky for Google they do not promise your site will be fast!

All in all, I'm pretty happy with that uptime considering that I no not need to worry about my own infrastructure and software security.  I also have faith that big G will continue to improve and refine their systems or they will lose a lot of business.  I'm probably less sensitive to downtime than a lot of their customers.

Tuesday, December 18, 2012

Tired eyes? Code on the dark side.

If you have a Mac, press ctrl-alt-command+8 and the screen colours invert.  Great for the eyes.  I wonder how many other obscure useful key combinations are hiding in OSX for me to discover?

I've been trying out IntelliJ IDEA again today and love the new "Darcular" theme that makes is easy on the eyes, especially at night. I do think that, given time, I would come to prefer it over Eclipse.  It seems everybody does.  The basic premise that a comercial product will have less bugs and more features holds true because they have more incentive to keep customers happy.

This week however, I do not have the time to re-learn all the keybindings and figure out where the configuration options are.  Once again I've put it aside till another day... or decade.

Wednesday, December 12, 2012

Google Maps v3 with GWT - Example

For a long time there was no official port of Google Maps v3 to GWT.  This issue, created in June 2010, is still marked as "Started".  Comments on that issue seem to indicate that the problem was due to the difficulty in generating the bindings automatically so it would be easy to keep in sync with the JavaScript API.  The older v2 maps API also did not use overlay types which allows more optimised code to be generated, which v3 does.

Finally in March 2012 an official "prerelease" build was posted to the issue but never properly released.  However, it is very usable and seems quite complete.  One nice thing is that because it is generated automatically from the JavaScript API, it matches up very closely to the official docs.  An obvious exception to this is the central class is name GoogleMap rather than Map for obvious reasons.

I'll write a little about getting started using these maps and include a little demo.  The demo uses your current location (from HTML5 geo location object) and draws a circle on the map where it things you are.  The map is zoomed according to how accurate the reading is so the circle should look about the same size no matter what the accuracy.

Start by getting the jar and putting it in a folder somewhere (not in your WEB-INF) and add it to your class path.  Keep an eye on the downloads page in case a more recent lib is released.  At this point it is for the Maps 3.8.1 API which is a already a little out of date but looking at the changelog, I can't see any great features I'd be missing.

First here is the working demo: (watch out for the dialog asking if it can use your location)

and here is the code... First the module
<module rename-to="mapdemo">
  <inherits name=""/>
  <inherits name=""/>
  <entry-point class="com.vercer.mapdemo.client.Mapdemo"/>
  <add-linker name="xsiframe" />
and the GWT code to create a JS file that can be used "cross site"

public class Mapdemo implements EntryPoint
 public void onModuleLoad()
  Geolocation geolocation = Geolocation.getIfSupported();
  if (geolocation == null)
   Window.alert("Your old browser is stuck in the past");
  geolocation.getCurrentPosition(new Callback<Position, PositionError>()
   public void onSuccess(Position result)
   public void onFailure(PositionError reason)

 protected void display(Coordinates coordinates)
  // create a bounds 10 times larger than the accuracy error
  LatLng center = LatLng.create(coordinates.getLatitude(), coordinates.getLongitude());
  LatLng sw = Spherical.computeOffset(center, coordinates.getAccuracy() * 10, 225);
  LatLng ne = Spherical.computeOffset(center, coordinates.getAccuracy() * 10, 45);
  LatLngBounds outer = LatLngBounds.create(sw, ne);
  // create the map
  MapOptions mapOptions = MapOptions.create();
  GoogleMap map = GoogleMap.create(Document.get().getElementById("map"), mapOptions);
  // create a circle the size of the error
  CircleOptions circleOptions = CircleOptions.create();
  Circle circle = Circle.create(circleOptions);

Wednesday, November 28, 2012

Moving domains from 1 and 1 to NameCheap

Every time I think of a new "killer start-up" website idea I rush to to find that perfect .com domain name that maybe - just maybe - is still unregistered.  Normally I'm disappointed to find that almost every combination of relavent keywords was registered by domain squatters years ago.  I end up with some mediocre name with far too many letters and maybe the odd hyphen or two.  But I register them anyway.

Previously I used because ... well they were cheap - like 8.99 (now 10.99).  But unfortunately there are other costs: my time, my sanity and full rights to use my domain how I need.

Firstly, the user interface for their admin console seems to have been carefully designed to enrage its users.  Trying to do any simple task involves checking boxes and selecting obscure menu items and then waiting... maybe it will happen, maybe it won't.  Cancelling anything is virtually impossible.  Transferring your domain to another host is less fun than putting a hot poker up your pee hole.

But the biggest aggravation is that their DNS system does not let you define a wild card subdomain like *  When I build a website I like to have several versions live for clients to check out such as and  Also, a cool new feature of Google App Engine (GAE) is that it will map application versions to subdomains automatically.  So if I put a new version live "2012-11-28" I can see it at without any extra configuration.

But not with  Oh no.  In fact they limit you to making 5 subs domains on all of your domains.  If you have 20 domains with them you can still only create 5 subdomains between all of them.  Pathetic really.  They do this to force you to buy a more expensive package that allows you to use your own damn domain name how you bloody well like.  Infuriating.  If only they had a warning on their home page: "We are cheap but we will shaft you eventually"

So I googled about a bit for a good, cheap, popular domain host and came to NameCheap.  I'm pretty happy with that choice so far.  The UI is a bit dated but does everything I need without the hair-pulling-out.

The price is right too - I paid 8.69 USD for each transfer for a year including privacy protection.  That was using some discount code I pinched off the web SWITCH2NC that gives 1 dollar off.

Now I am happily all transferred over to NameCheap and it was a breeze.  Wild card subdomains are F.A.B.

So its cheaper and better.  The end.