pserver.go 1009 字节
Newer Older
1 2 3 4 5 6 7
package main

import (
	"net"
	"net/http"
	"net/rpc"
	"strconv"
W
wuyi05 已提交
8
	"time"
9

H
Helin Wang 已提交
10 11
	"github.com/namsral/flag"

12
	"github.com/PaddlePaddle/Paddle/go/pserver"
W
wuyi05 已提交
13
	log "github.com/sirupsen/logrus"
14 15 16
)

func main() {
H
Helin Wang 已提交
17
	port := flag.Int("port", 0, "port of the pserver")
W
wuyi05 已提交
18 19 20 21
	etcdEndpoint := flag.String("etcd-endpoint", "http://127.0.0.1:2379",
		"comma separated endpoint string for pserver to connect to etcd")
	etcdTimeout := flag.Int("etcd-timeout", 5, "timeout for etcd calls")
	logLevel := flag.String("log-level", "info", "log level, one of debug")
22 23
	flag.Parse()

W
wuyi05 已提交
24 25 26 27 28 29 30 31 32 33 34 35
	level, err := log.ParseLevel(*logLevel)
	if err != nil {
		panic(err)
	}
	log.SetLevel(level)

	timeout := time.Second * time.Duration((*etcdTimeout))
	s, err := pserver.NewService(*etcdEndpoint, timeout)
	if err != nil {
		panic(err)
	}
	err = rpc.Register(s)
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
	if err != nil {
		panic(err)
	}

	rpc.HandleHTTP()
	l, err := net.Listen("tcp", ":"+strconv.Itoa(*port))
	if err != nil {
		panic(err)
	}

	err = http.Serve(l, nil)
	if err != nil {
		panic(err)
	}
}