コード例 #1
0
func asyncTest(client c.Client, total int) {

	resChan := make(chan *cheshire.Response, 20)
	errorChan := make(chan error, 200)

	start := time.Now().Unix()

	sent := total
	go func() {

		for i := 0; i < total; i++ {
			if i%1000 == 0 {
				log.Printf("Sending %d", i)
			}
			err := client.ApiCall(cheshire.NewRequest("/ping", "GET"), resChan, errorChan)
			if err != nil {
				log.Printf("apicall error %s", err)
				sent--
			}
			// if i % 2 == 0 {
			//     time.Sleep(1 * time.Millisecond)
			// }
		}
	}()
	count := 0

	log.Println("Starting select!")
	for {
		select {
		case res := <-resChan:
			count++
			if count%1000 == 0 {
				log.Printf("Recieved 1000 more, total %d, total time: %d", count, (time.Now().Unix() - start))
				log.Printf("RESULT %s", res)
			}

		case err := <-errorChan:
			count++
			log.Printf("ERROR FROM CHAN %s", err)
		}

		if count == sent {
			log.Println("FINISHED!")
			break
		}
	}

	log.Printf("Pinged %d in %d", total, (time.Now().Unix() - start))

}
コード例 #2
0
func syncTest(client c.Client, total int) {

	start := time.Now().Unix()

	for i := 0; i < total; i++ {
		if i%1000 == 0 {
			log.Printf("Sending %d", i)
		}
		_, err := client.ApiCallSync(cheshire.NewRequest("/ping", "GET"), 2*time.Second)
		if err != nil {
			log.Printf("apicall error %s", err)
		}
	}

	log.Printf("Pinged %d in %d", total, (time.Now().Unix() - start))

}
コード例 #3
0
ファイル: manager.go プロジェクト: sourabhg/goshire-shards
// Does a checkin with the requested client.  returns the
// router table revision of the connection.
func (this *Manager) Checkin(client client.Client) (int64, error) {
	response, err := client.ApiCallSync(cheshire.NewRequest("/chs/checkin", "GET"), 10*time.Second)
	if err != nil {
		return int64(0), err
	}
	revision := response.MustInt64("router_table_revision", int64(0))
	return revision, nil
}
コード例 #4
0
ファイル: helpers.go プロジェクト: sourabhg/goshire-shards
// Finds the RouterTable from the given client
//
func RequestRouterTable(c client.Client) (*RouterTable, error) {
	response, err := c.ApiCallSync(cheshire.NewRequest(ROUTERTABLE_GET, "GET"), 10*time.Second)
	if err != nil {
		return nil, err
	}
	if response.StatusCode() != 200 {
		return nil, fmt.Errorf("Error from server %d %s", response.StatusCode(), response.StatusMessage())
	}

	mp, ok := response.GetDynMap("router_table")
	if !ok {
		return nil, fmt.Errorf("No router_table in response : %s", response)
	}

	table, err := ToRouterTable(mp)
	if err != nil {
		return nil, err
	}
	return table, nil
}