November 2006 - Posts

Google Search API fails sporadically with "502 Bad Gateway"

I heard about Google's web service interface to the search database back when it was released, but today was my first attempt to use it.  I'm trying to learn python, but the SOAP toolkits for python seem to be in a state of flux so I switched back to C# rather than figure out which python libraries to download. 

I experienced two problems, one minor and one major.  The doSearch method  takes a bunch of strings, and if you pass null in, you get back weird errors talking about no signature match and java.lang.String.  Passing String.Empty fixes that. 

The second problem is that, requests to search sporadically fail with "502: Bad Gateway".  From my googling (ah, the irony) for a solution, this has been a problem since January 2006, and is still unsolved. 

The solution on the forums seems to be catch the exception and try again; I didn't expect that to work, but it did.  I wrote a console app that sent the same string to the gateway 30 times, and it seemed to randomly error out.  A snippet of the output is below:

12:27:14.593 - The request failed with HTTP status 502: Bad Gateway.

12:27:19.046 - Success, found 782000 items.

12:27:32.625 - Success, found 782000 items.

12:27:35.000 - Success, found 782000 items.

12:27:35.984 - The request failed with HTTP status 502: Bad Gateway.

12:27:39.843 - Success, found 782000 items.

12:27:42.593 - Success, found 782000 items.

This makes this obviously unsuitable for anything more than playful experimentation, but since the API doesn't return ads, I guess Google doesn't care.

 

Web Service performance numbers--plenty fast for UI work

While designing Web Services, the question of "interface granularity" often comes up.  Conventional wisdom is that Web Service calls are slow, so the interface must be quite coarse to prevent performance problems.

 

Four years ago, a partner and I built a 2-tier system, a rich client app that talked directly to a database.  Towards the end of the development cycle, the users said, "We know we said this was for internal use, but we want to use this application over the Internet."

 

Bam! That is the kind of major requirements change that can kill projects.  After some research, we factored the database calls into an IDataAccess interface that had two implementors: the original database layer and a web service layer that then called the original database layer.  On startup, the app figures out which interface to use.  As our research and prototyping showed, web services are plenty fast for this scenario. 

 

My current project is also a rich client backed by web services, and we are discussing how quickly the UI needs to respond to the user.  Microsoft's performance guidelines suggest one threshold, "A good guideline for interactive response is 500 milliseconds."

 

Jim Webber estimates that SOAP adds 14 milliseconds round trip.  Network latency is usually less than 50 milliseconds round trip in the US, increasing roughly linearly to a rough maximum of 300 milliseconds worldwide. 

 

In my experience, a hit to an optimized database costs roughly 20 ms, plus latency to the database machine of another 5-10 ms.  So we are looking at 14 + 50 + 20 + 10 = 94ms.  Add in another 50 ms for authentication, authorization and business logic on the server, which leaves the UI well under the 500 ms limit.  Anyone have numbers for how much SSL increases latency?

 

I just did some performance testing that supports these numbers as reasonable.  Using a unit test that connects to the web service and uses it to insert a row in a database (everything on the same machine), I was seeing average call times of 15 ms.  That leaves room for a lot of latency before the application slows down.

 

On my project four years ago, we were forced into a finer grained (more talkative) interface by previous decisions.  These days, I'm choosing this architecture with my eyes open, and I like the view.

More Posts