diff --git a/server/tilerendererjob/common.go b/server/tilerendererjob/common.go index 44a9aeb..0d9c495 100644 --- a/server/tilerendererjob/common.go +++ b/server/tilerendererjob/common.go @@ -14,12 +14,21 @@ func getTileKey(tc *coords.TileCoords) string { strconv.Itoa(tc.Zoom) + "/" + strconv.Itoa(tc.LayerId) } -func renderMapblocks(ctx *app.App, jobs chan *coords.TileCoords, mblist []*mapblockparser.MapBlock) int { +func renderMapblocks(ctx *app.App, mblist []*mapblockparser.MapBlock) int { tileRenderedMap := make(map[string]bool) tilecount := 0 totalRenderedMapblocks.Add(float64(len(mblist))) for i := 12; i >= 1; i-- { + + //Spin up workers + jobs := make(chan *coords.TileCoords, ctx.Config.RenderingQueue) + done := make(chan bool, 1) + + for i := 0; i < ctx.Config.RenderingJobs; i++ { + go worker(ctx, jobs, done) + } + for _, mb := range mblist { //13 @@ -60,6 +69,10 @@ func renderMapblocks(ctx *app.App, jobs chan *coords.TileCoords, mblist []*mapbl //dispatch re-render jobs <- tc } + + //spin down worker pool + close(jobs) + <-done } return tilecount diff --git a/server/tilerendererjob/incremental.go b/server/tilerendererjob/incremental.go index 5f0cc6c..95a3c75 100644 --- a/server/tilerendererjob/incremental.go +++ b/server/tilerendererjob/incremental.go @@ -2,7 +2,6 @@ package tilerendererjob import ( "mapserver/app" - "mapserver/coords" "mapserver/settings" "time" @@ -13,7 +12,7 @@ type IncrementalRenderEvent struct { LastMtime int64 `json:"lastmtime"` } -func incrementalRender(ctx *app.App, jobs chan *coords.TileCoords) { +func incrementalRender(ctx *app.App) { lastMtime := ctx.Settings.GetInt64(settings.SETTING_LAST_MTIME, 0) @@ -36,7 +35,7 @@ func incrementalRender(ctx *app.App, jobs chan *coords.TileCoords) { continue } - tiles := renderMapblocks(ctx, jobs, result.List) + tiles := renderMapblocks(ctx, result.List) lastMtime = result.LastMtime ctx.Settings.SetInt64(settings.SETTING_LAST_MTIME, lastMtime) diff --git a/server/tilerendererjob/initial.go b/server/tilerendererjob/initial.go index 6455a8f..ffec5a3 100644 --- a/server/tilerendererjob/initial.go +++ b/server/tilerendererjob/initial.go @@ -2,7 +2,6 @@ package tilerendererjob import ( "mapserver/app" - "mapserver/coords" "mapserver/settings" "time" @@ -13,7 +12,7 @@ type InitialRenderEvent struct { Progress float64 `json:"progress"` } -func initialRender(ctx *app.App, jobs chan *coords.TileCoords) { +func initialRender(ctx *app.App) { logrus.Info("Starting initial rendering job") lastMtime := ctx.Settings.GetInt64(settings.SETTING_LAST_MTIME, 0) @@ -44,7 +43,7 @@ func initialRender(ctx *app.App, jobs chan *coords.TileCoords) { return } - tiles := renderMapblocks(ctx, jobs, result.List) + tiles := renderMapblocks(ctx, result.List) t := time.Now() elapsed := t.Sub(start) diff --git a/server/tilerendererjob/job.go b/server/tilerendererjob/job.go index da00fde..b39d4f0 100644 --- a/server/tilerendererjob/job.go +++ b/server/tilerendererjob/job.go @@ -2,24 +2,17 @@ package tilerendererjob import ( "mapserver/app" - "mapserver/coords" "mapserver/settings" ) func Job(ctx *app.App) { initMetrics() - jobs := make(chan *coords.TileCoords, ctx.Config.RenderingQueue) - - for i := 0; i < ctx.Config.RenderingJobs; i++ { - go worker(ctx, jobs) - } - if ctx.Settings.GetBool(settings.SETTING_INITIAL_RUN, true) { - initialRender(ctx, jobs) + initialRender(ctx) } - incrementalRender(ctx, jobs) + incrementalRender(ctx) panic("render job interrupted!") diff --git a/server/tilerendererjob/worker.go b/server/tilerendererjob/worker.go index aeda7d8..e2aec1a 100644 --- a/server/tilerendererjob/worker.go +++ b/server/tilerendererjob/worker.go @@ -6,7 +6,7 @@ import ( "github.com/sirupsen/logrus" ) -func worker(ctx *app.App, coords <-chan *coords.TileCoords) { +func worker(ctx *app.App, coords <-chan *coords.TileCoords, done chan bool) { for tc := range coords { //render tile @@ -24,4 +24,6 @@ func worker(ctx *app.App, coords <-chan *coords.TileCoords) { panic(err) } } + + done <- true }