我如何在grails中实现请求超时? [英] How do I implement a request timeout in grails?

查看:90
本文介绍了我如何在grails中实现请求超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在grails中设置一个可配置的(通过控制器/操作)请求超时。其目标是以确定性的方式处理罕见的高负载故障模式。例如,我知道如果给定的控制器/操作在30秒内没有返回,那么某些事情是非常错误的,我不想让用户挂起。



<如果可能的话,我想在应用程序逻辑中处理这个问题,因为根据事件的条件,可能会有合理的恢复或消息传递。



因为时间可能会在请求处理生命周期的任何地方达到。

解决方案

我不认为这很容易实现。您可能仅限于您正在使用的Servlet容器的功能。例如,使用tomcat,你可以设置一个 connectionTimeout 。不幸的是,这可能不会给你你所要求的控制,因为超时和响应更多的是容器的摆布。



你可能有办法做后台线程,定时器,中断和一些黑魔法,但这可能是一个不明智的事情。



我发现了几个邮件列表讨论话题:


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:

这篇关于我如何在grails中实现请求超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆