Пример #1
0
func main() {
	config, _ := skynet.GetClientConfig()

	var err error

	config.Log = skynet.NewConsoleSemanticLogger("TestServiceClient", os.Stderr)

	client := client.NewClient(config)

	// This will not fail if no services currently exist, as
	// connections are created on demand this saves from chicken and
	// egg issues with dependencies between services
	service := client.GetService("TestService", "", "", "")
	// (any version, any region, any host)

	// This on the other hand will fail if it can't find a service to
	// connect to
	in := map[string]interface{}{
		"data": "Upcase me!!",
	}
	out := map[string]interface{}{}
	err = service.Send(nil, "Upcase", in, &out)

	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(out["data"].(string))
}
Пример #2
0
func main() {
	config, args := skynet.GetClientConfig()
	client := client.NewClient(config)

	service := client.GetService("Fibonacci", "", "", "")

	if len(args) == 0 {
		fmt.Printf("Usage: %s <positive number>*\n", args[0])
		return
	}

	for _, arg := range args[1:] {
		index, err := strconv.Atoi(arg)
		if err != nil {
			panic(err)
		}
		req := fibonacci.Request{
			Index: index,
		}
		resp := fibonacci.Response{}
		err = service.Send(nil, "Index", req, &resp)
		if err != nil {
			fmt.Println(err)
		} else {
			fmt.Printf("%d -> %d\n", index, resp.Value)
		}
	}
}
Пример #3
0
func main() {
	config := &skynet.ClientConfig{
		DoozerConfig: &skynet.DoozerConfig{},
	}

	flagset := flag.NewFlagSet("sleepclient", flag.ContinueOnError)

	skynet.FlagsForClient(config, flagset)

	req := sleeper.Request{
		Message: "Hello!",
	}

	var (
		retry  time.Duration
		giveup time.Duration
	)

	flagset.DurationVar(&req.Duration, "sleepfor", 5*time.Second,
		"how long to sleep")
	flagset.BoolVar(&req.ExitWhenDone, "exit", false,
		"have the service call os.Exit(0) when finished sleeping")
	flagset.BoolVar(&req.PanicWhenDone, "panic", false,
		"have the service panic when finished sleeping")
	flagset.BoolVar(&req.UnregisterWhenDone, "unregister", false,
		"have the service unregister when finished sleeping")
	flagset.BoolVar(&req.UnregisterHalfwayThrough, "unregister-halfway", false,
		"have the service unregister half-way through the sleep")
	flagset.DurationVar(&retry, "retry", time.Second,
		"how long to wait before trying again")
	flagset.DurationVar(&giveup, "giveup", 5*time.Second,
		"how long to wait before giving up")

	flagset.Parse(os.Args[1:])

	config.MaxConnectionsToInstance = 5

	client := client.NewClient(config)

	service := client.GetService("Sleeper", "", "", "")

	service.SetTimeout(retry, giveup)

	resp := sleeper.Response{}

	start := time.Now()

	err := service.Send(nil, "Sleep", req, &resp)

	duration := time.Now().Sub(start).Nanoseconds()

	fmt.Printf("request took %dns\n", duration)

	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Printf("%s -> %s\n", req.Message, resp.Message)
	}
}
Пример #4
0
func main() {
	config, _ := skynet.GetClientConfig()
	client := client.NewClient(config)

	service := client.GetService("TutorialService", "1", "Development", "")

	req := &TutorialRequest{
		Value: 1,
	}

	resp := &TutorialResponse{}

	err := service.Send(nil, "AddOne", req, resp)

	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(resp.Value)
	}
}
Пример #5
0
func main() {
	flagset := flag.NewFlagSet("simple", flag.ContinueOnError)
	flagset.IntVar(&requests, "requests", 10, "number of concurrent requests")
	flagset.IntVar(&goMaxProcs, "maxprocs", 1, "GOMAXPROCS")

	runtime.GOMAXPROCS(goMaxProcs)

	c := make(chan os.Signal, 1)
	quitChan := make(chan bool, 1)
	requestChan := make(chan string, requests*3)
	workerWaitGroup := new(sync.WaitGroup)

	go watchSignals(c, quitChan)

	simpleArgs, _ := config.SplitFlagsetFromArgs(flagset, os.Args[1:])
	flagset.Parse(simpleArgs)

	simpleClient = client.GetService("TestService", "", "", "")

	startTime := time.Now().UnixNano()
	fmt.Printf("Starting %d Workers\n", requests)
	for i := 0; i < requests; i++ {
		go worker(requestChan, workerWaitGroup)
	}

	requestNum := 0

	for {
		select {
		case <-quitChan:
			close(requestChan)
			workerWaitGroup.Wait()
			stopTime := time.Now().UnixNano()

			successful, _ := strconv.Atoi(successfulRequests.String())
			total, _ := strconv.Atoi(totalRequests.String())
			failed, _ := strconv.Atoi(failedRequests.String())

			lost := total - successful - failed

			percentSuccess := float64(successful) / float64(total) * 100
			percentFailed := float64(failed) / float64(total) * 100
			percentLost := float64(lost) / float64(total) * 100

			runtime := (stopTime - startTime) / 1000000
			rqps := float64(total) / (float64(runtime) / 1000)

			fmt.Printf("======================================")
			fmt.Printf("======================================\n")
			fmt.Printf("Completed in %d Milliseconds, %f Requests/s\n",
				runtime, rqps)
			fmt.Printf("\nTotal Requests: %d, Successful: %d (%f%%)",
				total, successful, percentSuccess)
			fmt.Printf(", Failed: %d (%f%%)", failed, percentFailed)
			fmt.Printf(", Lost: %d (%f%%)\n\n", lost, percentLost)
			return

		default:
			requestChan <- "simple"
			requestNum++
		}
	}
}