thomaswang
V2EX  ›  问与答

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

By thomaswang at 2019 年 10 月 22 日 · 2314 次点击

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
目前尚无回复
© 2026 V2EX · 24ms · 3.9.8.5