Ejemplo n.º 1
0
func (self *TileServer) ServeTileRequest(tc *gopnik.TileCoord, prio gopnikrpc.Priority, wait_storage bool) (tiles []gopnik.Tile, renderTime, saveTime time.Duration, err error) {
	τ0 := time.Now()

	tiles, renderTime, saveTime, err = self.serveTileRequest(tc, prio, wait_storage)

	// Statistics
	hReqT.AddPoint(time.Since(τ0).Seconds())
	if err == nil {
		hReqOk.Inc()
	} else {
		hReqErr.Inc()
	}

	// save to perflog
	perflog.SavePerf(perflog.PerfLogEntry{
		Timestamp:  time.Now(),
		Coord:      *tc,
		RenderTime: renderTime,
		SaverTime:  saveTime,
	})

	return
}
Ejemplo n.º 2
0
func main() {
	cfg := gopnikprerenderlib.PrerenderGlobalConfig{
		Prerender: gopnikprerenderlib.PrerenderConfig{
			UIAddr:         ":8088",
			DebugAddr:      ":8097",
			NodeQueueSize:  100,
			RequestTimeout: "1h",
		},
		CommonConfig: app.CommonConfig{
			MetaSize: 8,
			TileSize: 256,
		},
	}

	app.App.Configure("Prerender", &cfg)

	clI, err := plugins.DefaultPluginStore.Create(cfg.Prerender.Slaves.Plugin, cfg.Prerender.Slaves.PluginConfig)
	if err != nil {
		log.Fatal(err)
	}
	cl, ok := clI.(gopnik.ClusterPluginInterface)
	if !ok {
		log.Fatal("Invalid cache plugin type")
	}

	coords, err := loadPlanFile()
	if err != nil {
		log.Fatal(err)
	}
	coordsLen := len(coords)
	slavesAddrs, err := cl.GetRenders()
	if err != nil {
		log.Fatalf("GetRenders error: %v", err)
	}

	// Setup perflog
	if cfg.Prerender.PerfLog != "" {
		perflog.SetupPerflog(cfg.Prerender.PerfLog)
	}

	// Timeouts
	requestTimeout, err := time.ParseDuration(cfg.Prerender.RequestTimeout)
	if err != nil {
		log.Fatalf("Invalid request timeout: %v", err)
	}

	// Plan
	coordinator := newCoordinator(slavesAddrs, requestTimeout, cfg.Prerender.NodeQueueSize, coords)
	coords = nil
	resChan := coordinator.Start()

	// WebUI
	if cfg.Prerender.UIAddr != "" {
		cpI, err := plugins.DefaultPluginStore.Create(cfg.CachePlugin.Plugin, cfg.CachePlugin.PluginConfig)
		if err != nil {
			log.Fatal(err)
		}
		cp, ok := cpI.(gopnik.CachePluginInterface)
		if !ok {
			log.Fatal("Invalid cache plugin type")
		}

		go runWebUI(cfg.Prerender.UIAddr, coordinator, cp)
	}

	// Cli and log

	bar := pb.StartNew(coordsLen)
	for res := range resChan {
		perflog.SavePerf(res)
		bar.Increment()
	}

	bar.FinishPrint("Done")
}