在 AppEngine 中检测客户端中止的请求
我在 AppEngine 中有一个请求需要一些时间才能完成(很多秒)。有没有办法检测用户或某些网络问题是否已经中止请求?这将使我节省继续生成结果的服务器负载,无论如何它都不会去任何地方。
我在开发模式下尝试了以下操作,但都不起作用(尚未检查它在生产模式下的行为是否不同):
- 检查 resp.getOutputStream 是否完成而不抛出 IOException
- 检查是否有中断发送到 servlet 线程
谢谢,马库斯
PS:我真的对这个问题特别感兴趣,而不是对如何重组我的应用程序以使请求更快或防止中止或其他事情感兴趣。
I have a request in AppEngine that takes a little while to complete (many seconds). Is there a way to detect whether the user or some network problem has already aborted the request? This would allow me to save myself the server-load of continuing the result generation, which won't go anywhere anyways.
I tried the following in Dev-Mode, but neither worked (haven't checked yet whether it behaves differently in production mode):
- Checking whether resp.getOutputStream completes without throwing an IOException
- Checking whether there was an Interrupt sent to the servlet thread
Thanks, Markus
PS: I am really specifically interested in this question, not in ways to restructure my app to make the request faster or prevent aborts or other things.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道这在应用程序引擎上是否可行,应用程序引擎不允许正在进行的请求。处理程序/servlat 返回后,响应将发送到客户端。
I don't know if that is possible at all on the App Engine, app engine doesn't allow in progress request. The response is sent to the client after that the handler/servlat has returned.
不,无法从应用程序内部检测到这一点。我不会担心这个。
No, there is no way to detect this from inside the app. I wouldn't worry about it.
已经晚了,但这可能有用。在 Golang 中,您可以使用 Context 包检测中断。
以下是 Francesc Campoy 对其进行解释的有用视频:
https://www.youtube.com/watch ?v=LSzR0VEraWw
Way late but this may be useful. In
Golang
you can detect interrupts using theContext
package.Here is a useful video of Francesc Campoy explaining it:
https://www.youtube.com/watch?v=LSzR0VEraWw