github.com/stackdocker/rkt@v0.10.1-0.20151109095037-1aa827478248/Godeps/_workspace/src/google.golang.org/grpc/benchmark/server/main.go (about)

     1  package main
     2  
     3  import (
     4  	"flag"
     5  	"math"
     6  	"net"
     7  	"net/http"
     8  	_ "net/http/pprof"
     9  	"time"
    10  
    11  	"github.com/coreos/rkt/Godeps/_workspace/src/google.golang.org/grpc/benchmark"
    12  	"github.com/coreos/rkt/Godeps/_workspace/src/google.golang.org/grpc/grpclog"
    13  )
    14  
    15  var (
    16  	duration = flag.Int("duration", math.MaxInt32, "The duration in seconds to run the benchmark server")
    17  )
    18  
    19  func main() {
    20  	flag.Parse()
    21  	go func() {
    22  		lis, err := net.Listen("tcp", ":0")
    23  		if err != nil {
    24  			grpclog.Fatalf("Failed to listen: %v", err)
    25  		}
    26  		grpclog.Println("Server profiling address: ", lis.Addr().String())
    27  		if err := http.Serve(lis, nil); err != nil {
    28  			grpclog.Fatalf("Failed to serve: %v", err)
    29  		}
    30  	}()
    31  	addr, stopper := benchmark.StartServer(":0") // listen on all interfaces
    32  	grpclog.Println("Server Address: ", addr)
    33  	<-time.After(time.Duration(*duration) * time.Second)
    34  	stopper()
    35  }