func main() { // parse command line options flag.Parse() // create pipeline pipeline := falcore.NewPipeline() // setup file server for public directory if *flagPath != "" { // Serve files from public directory pipeline.Upstream.PushBack(&filter.FileFilter{ BasePath: *flagPath, DirectoryIndex: "index.html", }) } else { falcore.Warn("Path to public directory is missing") } // parse upstream list and create the upstream pool upStrings := regexp.MustCompile("[0-9]+").FindAllString(*flagUpstream, -1) ups := make([]*filter.UpstreamEntry, len(upStrings)) for i, s := range upStrings { port, _ := strconv.Atoi(s) ups[i] = &filter.UpstreamEntry{ Upstream: filter.NewUpstream(filter.NewUpstreamTransport("localhost", port, 0, nil)), Weight: 1, } } // create upstream pool and add to pipeline if len(ups) > 0 { pipeline.Upstream.PushBack(filter.NewUpstreamPool("railsdemo", ups)) } else { falcore.Warn("No upstream ports provided") } // add any downstream filters you might want such as etag support or compression // setup server server := falcore.NewServer(*flagPort, pipeline) // start the server // this is normally blocking forever unless you send lifecycle commands if err := server.ListenAndServe(); err != nil { fmt.Println("Could not start server:", err) } }
// Logs the number of pending requests at WARN level every :interval // :name is included in log line // Does not log if nothing is being throttled. func (t *Throttler) StartReporter(name string, interval time.Duration) { go func() { var waiting int64 for { time.Sleep(interval) waiting = t.Pending() if waiting > 0 { falcore.Warn("%v: %v requests waiting", name, waiting) } } }() }
func (up UpstreamPool) pingUpstreams() { pingable := true for pingable { select { case <-up.shutdown: return case <-up.pinger.C: gotone := false for i, ups := range up.pool { if ups.Upstream.PingPath != "" { go up.pingUpstream(ups, i) gotone = true } } if !gotone { pingable = false } } } falcore.Warn("Stopping ping for %v", up.Name) }