Use of Close in http Request

huangapple go评论76阅读模式
英文:

Use of Close in http Request

问题

Closehttp.Request{}结构体中的一个布尔字段,表示是否在请求完成后关闭连接。设置为true表示在请求完成后关闭连接,设置为false表示不关闭连接。

Close设置为truefalse对并发请求有什么影响?会影响并发请求吗?

设置Closetrue会在每个请求完成后关闭连接,这可能会导致一些额外的开销,因为每个请求都需要重新建立连接。这可能会降低并发请求的性能。

设置Closefalse会在请求完成后保持连接打开,这样可以提高并发请求的性能,因为可以重用连接。但是,如果连接保持打开时间过长,可能会导致连接资源的浪费。

因此,根据具体情况,需要权衡性能和资源利用的需求,选择适当的Close设置。

英文:

what is concurrent relation of Close boolean field in http.Request{}
What is the impact of setting it to true or false ? Will it hamper concurrent requests ?

答案1

得分: 1

http.Request类型无论如何都不安全用于并发使用。

将Request.Close设置为true或false不会干扰并发请求,因为如果您同时使用Request,您的代码行为是未定义的。

英文:

The http.Request type is not safe for concurrent use anyway

Setting Request.Close to true or false does not interfere with concurrent requests as your code has undefined behaviour anyway if you use a Request concurrently.

huangapple
  • 本文由 发表于 2015年8月18日 14:40:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/32065280.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定