[OpenLayers-Dev] Reasoning behind Layer.HTTPRequest selectUrl()
crschmidt at metacarta.com
Wed Nov 12 14:39:31 EST 2008
On Wed, Nov 12, 2008 at 01:59:59PM -0500, Nathan Gerber wrote:
> A member of my team and I are curious about why the selectUrl() function
> within Layer.HTTPRequest is as it is? It seems like alot of unnecessary
> overhead to pick a server to submit your requests to. It looks as though
> alot of thought went into this but it just doesn't seem to make alot of
> sense to either of us. It seems to parse through an entire parameter string
> which should be identical for each tile aside from the bounding box. It also
> seems that if I have an array of 3 servers and one of the servers fails when
> I do the retry attempt it will go right back to the server that failed
> instead of attempting to make use of another server within the array.
I think the answer, in a single wrd, is: "Caching."
When makign a request, typically a browser will "hold onto" a tile
inside of the same instance unless explicitly told otherwise by caching
headers, etc. By design, OpenLayers takes advantage of this by ensuring a
request for the same tile will always be the same. This way, if you drag
the map left, then back right, you get back the same tiles, from the
local cache, rather than a different set of tiles.
There is code in the default onImageLoadError which will fall back to a
random selection (assuming IMAGE_RELOAD_ATTEMPTS is greater than 0),
which handles the fallback case where a given server might be down.
This destroys the caching argument in the uncommon case where a server
is down. See OpenLayers.UTil.onImageLoadError.
> What I'm looking for is a sort of reasoning behind this? It just seems too
> complex to be this way for no particular reason. That said unless changing
> this will break something my team and I will be looking into rewriting the
> function to make a little more sense by incrementing through the servers one
> at a time rather than basing it on the bounding box.
This will make caching less useful, resulting in mre traffic against
your server and longer load times for your tiles in the users browser.
So long as you're willing to accept these costs, the change will not
More information about the Dev