登录
首页 >  Golang >  Go问答

net.Dialer#KeepAlive 和 http.Transport#IdleTimeout 之间有什么区别?

来源:stackoverflow

时间:2024-04-04 12:57:43 125浏览 收藏

珍惜时间,勤奋学习!今天给大家带来《net.Dialer#KeepAlive 和 http.Transport#IdleTimeout 之间有什么区别?》,正文内容主要涉及到等等,如果你正在学习Golang,或者是对Golang有疑问,欢迎大家关注我!后面我会持续更新相关内容的,希望都能帮到正在学习的大家!

问题内容

type dialer struct {
    ......
    // keepalive specifies the keep-alive period for an active
    // network connection.
    // if zero, keep-alives are enabled if supported by the protocol
    // and operating system. network protocols or operating systems
    // that do not support keep-alives ignore this field.
    // if negative, keep-alives are disabled.
    keepalive time.duration
}
type Transport struct {
    ......
// IdleConnTimeout is the maximum amount of time an idle
    // (keep-alive) connection will remain idle before closing
    // itself.
    // Zero means no limit.
    IdleConnTimeout time.Duration
}

我认为keep-alive是tcp连接应该保持的时间。但 idleconntimeout 似乎是同一回事。那么它们之间有什么区别,如果我都设置了这些变量,tcp连接可以保持多长时间?


解决方案


“保持活动”一词在两种上下文中含义不同。

net/http 传输文档使用该术语来指代 persistent connections。保持活动或持久连接是一种可用于多个 HTTP 事务的连接。

Transport.IdleConnTimeout 字段指定传输在关闭连接之前将未使用的连接保留在池中的时间。

网络拨号器文档使用“保持活动”术语来引用 TCP feature for probing the health of a connection

Dialer.KeepAlive 字段指定向对等方发送 TCP 保持活动探测的频率。

这两个设置在堆栈的不同层执行不同的操作。

终于介绍完啦!小伙伴们,这篇关于《net.Dialer#KeepAlive 和 http.Transport#IdleTimeout 之间有什么区别?》的介绍应该让你收获多多了吧!欢迎大家收藏或分享给更多需要学习的朋友吧~golang学习网公众号也会发布Golang相关知识,快来关注吧!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>