V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
moonsn
V2EX  ›  程序员

请教一个 nginx 超时限制问题

  •  2
     
  •   moonsn · 2019-11-11 16:04:23 +08:00 · 2411 次点击
    这是一个创建于 1600 天前的主题,其中的信息可能已经有所发展或是发生改变。
    proxy_read_timeout 10ms;
    

    如上配置,如果一个 response 由于某些原因,每 9ms 进行了一次传输(由于两次读操作在 timeout 限制内,所以不会超时)。多次传输才传完 response 的话,假如 response 整体 10ms 超时,response 整体是超时的。这个整体的超时要怎么控制?

    The timeout is set only between two successive read operations, not for the transmission of the whole response.

    附官网指令文档:

    Syntax:	proxy_read_timeout time;
    Default:	
    proxy_read_timeout 60s;
    Context:	http, server, location
    

    Defines a timeout for reading a response from the proxied server. The timeout is set only between two successive read operations, not for the transmission of the whole response. If the proxied server does not transmit anything within this time, the connection is closed.

    第 1 条附言  ·  2019-11-11 20:07:19 +08:00
    对不起,我没有描述原始需求。

    我有个 subrequest 请求,用于获取旁路的信息,比如用户认证什么的。

    但是我希望能有个超时机制。使用 proxy_read_timeout 并不能真正做到我想要的限制 response 整体超时。
    9 条回复    2019-11-12 01:12:38 +08:00
    Oa
        1
    Oa  
       2019-11-11 17:12:54 +08:00
    一小时 8 分钟过去了。。。。。
    moonsn
        2
    moonsn  
    OP
       2019-11-11 17:21:38 +08:00
    @Oa 估计是问题比较偏?
    dppd
        3
    dppd  
       2019-11-11 19:37:13 +08:00
    其实还不太明白你的意思...从 keepalive 和 HTTP1.1 入手?
    moonsn
        4
    moonsn  
    OP
       2019-11-11 20:08:33 +08:00 via Android
    @dppd append 了

    我有个 subrequest 请求,用于获取旁路的信息,比如用户认证什么的。

    但是我希望能有个超时机制,这样不至于让旁路拖慢了主请求。使用 proxy_read_timeout 并不能真正做到我想要的限制 response 整体超时。
    moonsn
        5
    moonsn  
    OP
       2019-11-11 20:15:53 +08:00 via Android
    @dppd 感谢,我试试 keepalive
    eason1874
        6
    eason1874  
       2019-11-11 20:21:55 +08:00
    “多次传输才传完 response 的话,假如 response 整体 10ms 超时,response 整体是超时的。”

    估计大家都看不懂你说什么,怀疑自己水平不够,于是进来看一眼又退出了。你可以把 Nginx 所有 _timeout 结尾的配置都看一遍,看哪个适合你。
    azh7138m
        7
    azh7138m  
       2019-11-11 21:14:31 +08:00
    send_timeout ?
    moonsn
        8
    moonsn  
    OP
       2019-11-11 21:17:39 +08:00
    @eason1874 嗯,确实描述有问题,append 的需求是否简单明了?
    dndx
        9
    dndx  
       2019-11-12 01:12:38 +08:00
    OpenResty `body_filter_by_lua` 可以根据已经花在处理上的时间终止请求。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2588 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 15:38 · PVG 23:38 · LAX 08:38 · JFK 11:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.