Example #1
0
File: main.go Project: houcy/gofast
func doStream(trans *gofast.Transport, routines int, msg gofast.Message) {
	var wg sync.WaitGroup

	for i := 0; i < routines; i++ {
		wg.Add(1)
		go func() {
			ch := make(chan gofast.Message, 100)
			since := time.Now()
			stream, err := trans.Stream(msg, true, ch)
			if err != nil {
				log.Fatal(err)
			}
			//fmt.Println("started", msg)
			var received int64
			go func() {
				for msg := range ch {
					//fmt.Println("received", msg)
					trans.Free(msg)
					atomic.AddInt64(&received, 1)
					if atomic.LoadInt64(&received) == int64(options.count+1) {
						stream.Close()
						time.Sleep(4 * time.Second)
						break
					}
				}
				wg.Done()
			}()
			av.Add(uint64(time.Since(since)))
			for j := 0; j < options.count; j++ {
				since := time.Now()
				if err := stream.Stream(msg, false); err != nil {
					fmt.Printf("%v\n", err)
					panic("exit")
				}
				//fmt.Println("count", msg)
				av.Add(uint64(time.Since(since)))
			}
		}()
	}
	wg.Wait()
}
Example #2
0
File: main.go Project: houcy/gofast
func doRequest(trans *gofast.Transport, routines int, msg gofast.Message) {
	var wg sync.WaitGroup

	for i := 0; i < routines; i++ {
		wg.Add(1)
		go func() {
			for j := 0; j < options.count; j++ {
				since := time.Now()
				if rmsg, err := trans.Request(msg, false); err != nil {
					fmt.Printf("%v\n", err)
					panic("exit")
				} else {
					trans.Free(rmsg)
				}
				av.Add(uint64(time.Since(since)))
			}
			wg.Done()
		}()
	}
	wg.Wait()
}