1.背景

 在性能测试场景中,需要进行评估服务的QPS和服务并发数.完全模拟程序并发数非go 语言channel和gorouting 莫属如下脚本内容
package main
import (
    "fmt"
    "net/http" 
    "time"
)
func requestServer(ch chan <- string){
     resp, err := http.Get("http://192.168.1.12:88")
     if err != nil {
        ch <- fmt.Sprint(err)
        return 
     }
     ch <- fmt.Sprint(resp.Status)
     defer resp.Body.Close()

}
func main() {
    ch := make(chan string)
    count := 5000
    //开始计时
    begin := time.Now()
    fmt.Println("开始时间:", begin)  
    for i := 0; i<= count; i++ {
        go requestServer(ch)
    }
    for y := 0; y<=count; y++ {
        fmt.Println(<-ch)
    }
    end := time.Now()
    fmt.Println("结束时间:", end, time.Since(begin)) 
}