http - Golang http客户端为什么有MaxConnsPerHost没有MaxConns

标签 http go connection-pooling

  • 我在 Go http 包中看到:

    MaxIdleConnsPerHost int

    但是我没有看到整个 http 客户端的任何 MaxConns,为什么?
  • 如果我只限制 MaxIdleConns(每个客户端)是否有可能超过此限制的事件连接数? (我认为答案很简单,但是否只是理论上的?)

  • 从文档:
    // MaxIdleConnsPerHost, if non-zero, controls the maximum idle
    // (keep-alive) connections to keep per-host. If zero,
    // DefaultMaxIdleConnsPerHost is used.
    MaxIdleConnsPerHost int
    
    
    
    // MaxConnsPerHost optionally limits the total number of
    // connections per host, including connections in the dialing,
    // active, and idle states. On limit violation, dials will block.
    //
    // Zero means no limit.
    MaxConnsPerHost int
    

    最佳答案

    I do not see any MaxConns for the whole http client, why?


    因为没有。如果您不想与该客户端发出超过 n 个并发请求,请不要这样做(如果客户端会限制,这将是一个主要的使用方法)。

    If I only limit MaxIdleConns (per the whole client) is it possible to have more than this limit of active connections?


    是的。 MaxIdlConns限制空闲连接而不是非空闲连接。

    关于http - Golang http客户端为什么有MaxConnsPerHost没有MaxConns,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61428428/

    相关文章:

    c# - 验证 BSB 是有效的澳大利亚 BSB 号码

    javascript - 为什么 NodeJS 可以使用 Chain API 稍后请求设置 post 表单?

    c# - 任何人都有示例代码,用于将一个网站的 "chunked"HTTP 流式下载直接上传到单独的 Web 服务器?

    java - 自定义连接池慢(JAVA)?

    c - 手动将协议(protocol)头与正文分离

    docker - 使用 Docker 的标准 Go 项目布局导致构建上下文问题

    http - 在 golang http.FileServer() 中列出错误链接的目录

    go - KafkaIO连接器/Apache Beam Transform“运行” SDK是否可用?

    c# - 是否可以从 .net 线程触发并忘记长时间运行的 SQL 语句(在 SQL Server 2005+ 上)?

    sql - 如何限制从我的 tomcat 部署的 java 应用程序到 SQL Server 服务器的连接数?