dtlh12053 2019-01-23 15:02
浏览 167

Go Transport中的keep-alive TTL永远不会关闭连接

I have an application hosted on AWS which is running on Production creates an http server as mentioned in the below sample code. There is default timeout of 180 seconds in the go library. So, ideally connections not used should be closed after 180 seconds.

myMux := http.NewServeMux()
myMux.Handle("/SOME_PATH", appHandler{myHandler})
err = http.ListenAndServe(viper.GetString("handler.port"), myMux)

The problem is when traffic increases on the application, number of connections increases. But when traffic comes down number of connections remains same.

I am using go version go1.10 linux/amd64 and this application is behind Amazon ALB.

Edited question:

As you can see the rate at which connections are decreasing is very slow when application is behind ALB. So, what could be the problem enter image description here

  • 写回答

1条回答 默认 最新

  • dqg17080 2019-05-11 00:45
    关注

    When you setup your server you should add timeouts appropriate for your application, for example

    srv := &http.Server{
        ReadTimeout:  5 * time.Second,
        WriteTimeout: 20 * time.Second,
        IdleTimeout:  180 * time.Second,
        Handler:      myMux,
    }
    

    With this the idle connections should get turned off. If it's an upstream load balancer sending health checks on that many connections the solution would be different.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配