Go http.Get, concurrency, and “Connection reset by peer”

前端 未结 4 1661
萌比男神i
萌比男神i 2020-12-05 03:18

I have between 1000-2000 webpages to download from one server, and I am using go routines and channels to achieve a high efficiency. The problem is that every time I run my

4条回答
  •  一生所求
    2020-12-05 03:53

    Still a golang newbie, hopefully this helps.

    var netClient = &http.Client{}
    
    func init() {
        tr := &http.Transport{
            MaxIdleConns:       20,
            MaxIdleConnsPerHost:  20,
        }
        netClient = &http.Client{Transport: tr}
    }
    
    func foo() {
        resp, err := netClient.Get("http://www.example.com/")
    }
    

提交回复
热议问题