我如何在grails中实现请求超时? [英] How do I implement a request timeout in grails?
问题描述
我希望能够在grails中设置一个可配置的(通过控制器/操作)请求超时。其目标是以确定性的方式处理罕见的高负载故障模式。例如,我知道如果给定的控制器/操作在30秒内没有返回,那么某些事情是非常错误的,我不想让用户挂起。
<如果可能的话,我想在应用程序逻辑中处理这个问题,因为根据事件的条件,可能会有合理的恢复或消息传递。
因为时间可能会在请求处理生命周期的任何地方达到。
我不认为这很容易实现。您可能仅限于您正在使用的Servlet容器的功能。例如,使用tomcat,你可以设置一个 connectionTimeout 。不幸的是,这可能不会给你你所要求的控制,因为超时和响应更多的是容器的摆布。
你可能有办法做后台线程,定时器,中断和一些黑魔法,但这可能是一个不明智的事情。
我发现了几个邮件列表讨论话题: http://grails.1312388.n4.nabble.com/How-to-change-request-timeout-td1356007.html 由Peter Ledbrook引用: 我不知道Grails功能为 http://www.mail-archive.com/users@tomcat.apache.org/msg38090.html
这个。它支持会话时间
,但不支持请求超时。
Servlet容器有连接
超时。
I'd like to be able to set a configurable (by controller/action) request timeout in grails. The objective is to handle a rare high-load failure mode in a deterministic way. For example, I know that if a given controller/action doesn't return in 30 seconds, then something is horribly wrong and I don't want to keep the user hanging.
I'd like to handle this within the application logic if possible, as there might be reasonable recoveries or messaging depending upon the conditions of the event.
Filters don't work because the time might be reached anywhere in the request processing lifecycle.
I don't think this is easily achievable. You're probably limited to the capabilities of the Servlet container you're using. For example, with tomcat you could set a connectionTimeout. Unfortunately, this may not give you the control that you're asking for since the timeout and response are more at the mercy of the container.
There's probably a way you could do it with background threads, timers, interrupts, and some black magic, but that would probably be an ill-advised thing.
A couple mailing list discussions I found on the topic:
http://grails.1312388.n4.nabble.com/How-to-change-request-timeout-td1356007.html
Quote from within by Peter Ledbrook:
I don't know of a Grails feature for this. It supports the session time out, but not a request time out. Servlet containers have connection timeouts.
http://www.mail-archive.com/users@tomcat.apache.org/msg38090.html
这篇关于我如何在grails中实现请求超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!