Skip to content

Commit

Permalink
Make renderd maxzoom-agnostic.
Browse files Browse the repository at this point in the history
  • Loading branch information
asciipip committed Jun 24, 2014
1 parent cd0dbe0 commit a75be73
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
2 changes: 0 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@
- Record last-served date for tiles so as to expire unaccessed tiles.

* commands to force expiration of tiles in queuemaster

* Make renderd max-zoom agnostic
21 changes: 11 additions & 10 deletions renderd.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@


class ContinuousRenderThread:
def __init__(self, maxz, dequeue_strategy, amqp_channel, threadNumber):
def __init__(self, dequeue_strategy, amqp_channel, threadNumber):
console.printMessage("Creating thread %d" % (threadNumber))
self.maxz = maxz
self.dequeue_strategy = dequeue_strategy
self.chan = amqp_channel
self.threadNumber = threadNumber
self.tilesizes = [ getTileSize(NTILES[z], True) for z in range(0, self.maxz + 1) ]
self.maps = [ None for z in range(0, self.maxz + 1) ]
self.tilesizes = []
self.maps = []

self.commandQueue = self.chan.queue_declare(exclusive=True).method.queue
self.chan.queue_bind(queue=self.commandQueue, exchange='osm', routing_key='command')
Expand All @@ -41,6 +40,9 @@ def __init__(self, maxz, dequeue_strategy, amqp_channel, threadNumber):
self.printMessage("Created thread")

def loadMaps(self, zoom):
if len(self.maps) <= zoom:
self.tilesizes.extend([ getTileSize(NTILES[z], True) for z in xrange(len(self.tilesizes), zoom + 1) ])
self.maps.extend([None] * (zoom - len(self.maps) + 1))
self.maps[zoom] = {}
for mapname in MAPNIK_LAYERS:
console.debugMessage('Loading mapnik.Map: {0}/{1}'.format(zoom, mapname))
Expand Down Expand Up @@ -69,7 +71,7 @@ def renderMetaTileFromMsg(self, msg):
layerTimes = None
if metaTileNeedsRendering(z, metax, metay):
message = 'Rendering {0}/{1}/{2}'.format(z, metax, metay)
if not self.maps[z]:
if len(self.maps) <= z or not self.maps[z]:
self.loadMaps(z)
layerTimes = self.runAndLog(message, renderMetaTile, (z, metax, metay, NTILES[z], self.maps[z]))
if layerTimes:
Expand All @@ -91,7 +93,7 @@ def on_command(self, chan, method, props, body):
if command == 'quit' or command == 'exit':
chan.stop_consuming()
elif command == 'newmaps':
self.maps = [ None for z in range(0, self.maxz + 1) ]
self.maps = []
elif command == 'reload':
reload(globals()[parts[1]])
elif command == 'queuemaster online':
Expand Down Expand Up @@ -153,10 +155,9 @@ def metaTileNeedsRendering(z, x, y):

if __name__ == "__main__":
console.printMessage('Initializing.')
maxz = int(sys.argv[1])

if len(sys.argv) >= 3:
dequeue_strategy = sys.argv[2]
if len(sys.argv) >= 2:
dequeue_strategy = sys.argv[1]
else:
dequeue_strategy = 'by_work_available'

Expand All @@ -168,5 +169,5 @@ def metaTileNeedsRendering(z, x, y):
console.printMessage('Starting renderer.')
rconn = pika.BlockingConnection(pika.ConnectionParameters(host=DB_HOST))
rchan = rconn.channel()
renderer = ContinuousRenderThread(maxz, dequeue_strategy, rchan, 0)
renderer = ContinuousRenderThread(dequeue_strategy, rchan, 0)
renderer.renderLoop()

0 comments on commit a75be73

Please sign in to comment.