thomaswang
V2EX  ›  问与答

使用 go http client(code 如下), 压测一台服务器上的 http server, qps 是 1.2w, 隔三差五的就返回 read: connection reset by peer

  •  
  •   thomaswang · Oct 22, 2019 · 1944 views
    This topic created in 2401 days ago, the information mentioned may be changed or developed.

    http server 这台机器(这个上面的 HTTP server 业务耗时很短的), 连接数也不多, 如下图, 我该如何排查, 找到问题,解决问题呢, 求解答

    func HttpPost(url string, http_body string) {
    	payload := strings.NewReader( http_body)
    	client := &http.Client{}
    	req, _ := http.NewRequest("POST", url, payload)
    
    	req.Header.Add("Content-Type", "text/plain")
    	req.Header.Add("User-Agent", "PostmanRuntime/7.17.1")
    	req.Header.Add("Accept", "*/*")
    	req.Header.Add("Cache-Control", "no-cache")
    	req.Header.Add("Postman-Token", "f54288e2-8fd5-4478-8138-746e16017f5e,79731914-e661-45f7-83ad-6c53a131ba10")
    	req.Header.Add("Host", "localhost:8080")
    	req.Header.Add("Accept-Encoding", "gzip, deflate")
    	req.Header.Add("Content-Length", "10")
    	req.Header.Add("Connection", "keep-alive")
    	req.Header.Add("cache-control", "no-cache")
    
    	res, err := client.Do(req)
    	if err == nil {
    		defer res.Body.Close()
    		body, err1 := ioutil.ReadAll(res.Body)
    		if err1 != nil {
    			init_config.FileLogs.Error("err1: ", http_body, string(body), err1.Error())
    		} else {
    		}
    	} else {
    		init_config.FileLogs.Error("err: ", http_body, err.Error()) // 这一行记录到的 read: connection reset by peer
    	}
    }
    

    目标服务器

    [root@xx log]# netstat -anp | wc -l
    3596
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1240 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 17:48 · PVG 01:48 · LAX 10:48 · JFK 13:48
    ♥ Do have faith in what you're doing.