master.go 992 字节
Newer Older
H
Helin Wang 已提交
1 2 3 4 5 6 7 8 9
package main

import (
	"net"
	"net/http"
	"net/rpc"
	"strconv"
	"time"

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

12
	"github.com/PaddlePaddle/Paddle/go/master"
H
Helin Wang 已提交
13 14 15
)

func main() {
H
Helin Wang 已提交
16
	port := flag.Int("port", 8080, "port of the master server.")
17

H
Helin Wang 已提交
18 19 20 21
	faultTolerance := flag.Bool("fault_tolerance", false, "enable fault tolerance (requires etcd).")
	taskTimeoutDur := flag.Duration("task_timout_dur", 20*time.Minute, "task timout duration.")
	taskTimeoutMax := flag.Int("task_timeout_max", 3, "max timtout count for each task before it being declared failed task.")
	chunkPerTask := flag.Int("chunk_per_task", 10, "chunk per task.")
H
Helin Wang 已提交
22 23
	flag.Parse()

H
Helin Wang 已提交
24 25
	if *faultTolerance {
		panic("fault tolernance not implemented.")
H
Helin Wang 已提交
26 27 28

	}

29
	s := master.NewService(*chunkPerTask, *taskTimeoutDur, *taskTimeoutMax)
H
Helin Wang 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
	err := rpc.Register(s)
	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)
	}
}