Esempio n. 1
0
func main() {
	cfg := Config{
		Render: RenderConfig{
			Threads:       1,
			Addr:          ":8090",
			DebugAddr:     ":9090",
			HotCacheDelay: "0s",
		},
		CommonConfig: app.CommonConfig{
			MetaSize: 8,
			TileSize: 256,
		},
	}

	if cfg.Render.PerfLog != "" {
		perflog.SetupPerflog(cfg.Render.PerfLog)
	}

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

	τ0 := time.Now()

	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")
	}

	removeDelay, err := time.ParseDuration(cfg.Render.HotCacheDelay)
	if err != nil {
		log.Fatalf("Invalid HotCacheDelay: %v", cfg.Render.HotCacheDelay)
	}
	ts, err := tileserver.NewTileServer(cfg.RenderPoolsConfig, cp, removeDelay)
	if err != nil {
		log.Fatalf("Failed to create tile server: %v", err)
	}

	δ := time.Since(τ0)
	log.Info("Done in %v seconds", δ.Seconds())

	// USR1, SIGHUP for style reload
	go sigHandler(syscall.SIGUSR1, ts.ReloadStyle, "ReloadStyle error")
	go sigHandler(syscall.SIGHUP, ts.ReloadStyle, "ReloadStyle error")

	servicestatus.SetOK() // Service is Ok if renders starts

	log.Info("Starting on %s...", cfg.Render.Addr)
	log.Fatal(tileserver.RunServer(cfg.Render.Addr, ts))
}
Esempio 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")
}