1
0
forked from MTSR/mapserver

per zoom workers

This commit is contained in:
NatureFreshMilk 2019-02-20 10:10:00 +01:00
parent 3ac14934dd
commit 645a4be524
5 changed files with 23 additions and 17 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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!")

View File

@ -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
}