Пример #1
0
func newVISGHSExecutor() *ghsvisExecutor {
	log.Infoln("Initializing the VISGHS Executor...", *tracerAddr)
	c, err := tracer.NewGRPCDisplayClient(*tracerAddr, grpc.WithInsecure())
	if err != nil {
		log.Fatalf("failed to connect: %v", err)
	}
	t := tracer.New(c)

	// Establish gRPC on the deisgnated port
	lis, err := net.Listen("tcp", ":0")
	if err != nil {
		log.Fatalf("grpc failed to listen: %v", err)
	}
	grpcServer := grpc.NewServer()

	// build command executor
	nexec := prepareExecutorInfo(lis.Addr())
	s := newvisghsScheduler(nexec)

	t := tracer.NewHTTPDisplay(http.DefaultServeMux, s.OnRun)
	server := tracer.NewGRPCServer(t)
	tracer.RegisterTraceServiceServer(grpcServer, server)
	go grpcServer.Serve(lis)
	time.Sleep(2 * time.Second)
	go http.ListenAndServe(":12345", nil)

	return &ghsvisExecutor{tasksLaunched: 0, Tracer: t}
}
Пример #2
0
func setupGHS(mux *http.ServeMux) {
	s := state{}

	t := tracer.New(tracer.NewHTTPDisplay(mux, s.OnRun))

	s.wg = &sync.WaitGroup{}

	count := 25
	s.wg.Add(count)
	nodes := make([]*graphalg.Node, 0)
	s.ghs = make([]*ghs.State, 0)

	for i := 0; i < count; i++ {
		n := &graphalg.Node{
			ID:     graphalg.NodeID(fmt.Sprintf("n%v", i+1)),
			Tracer: t,
		}
		nodes = append(nodes, n)
		s.ghs = append(s.ghs, &ghs.State{Node: n})
	}

	for i := 0; i < count; i++ {
		for j := i + 1; j < count; j++ {
			log.Infoln("join", i, j)
			w := rand.NormFloat64()*1.0 + 4.0
			nodes[i].Join(nodes[j], w, graphalg.MakeChanPair)
		}
	}

	for _, g := range s.ghs {
		go func(g *ghs.State) {
			n := g.Node
			n.NodeUpdate("from node")
			for _, e := range n.Edges() {
				e.EdgeUpdate()
			}

			graphalg.Run(g, s.wg.Done)
		}(g)
	}

	log.Infoln("running")
}