HTTP断开/请求和响应处理之间的超时 [英] HTTP disconnect/timeout between request and response handling

查看:1545
本文介绍了HTTP断开/请求和响应处理之间的超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设以下情形:


  1. 客户端发送HTTP POST到服务器

  2. 请求是有效的,
    由服务器已经被处理。数据已经被插入到数据库中。

  3. Web应用程序响应客户端

  4. 客户端遇到超时
    并没有看到HTTP响应。

在这种情况下,我们见面的情形:
- 客户端不知道他的数据是有效的,正确插入
- 网络服务器(轨道3.2应用程序)未显示任何异常,不管它是后面的apache代理或不

In this case we meet situation where: - client does not know if his data was valid and been inserted properly - web server (rails 3.2 application) does not show any exception, no matter if it is behind apache proxy or not

我找不到如何HTTP文件中处理这样的场景。我的问题是:

I can't find how to handle such scenario in HTTP documentation. My question are:

一)应客户想到的是他的数据可能已经处理? (所以后来尝试例如GET请求数据是否已经提交)

a) should client expect that his data MAY be processed already? (so then try for example GET request to check if data has been submitted)

B)如果没有(一) - 应该服务器检测到它?是有可能做到在导轨上?在这种情况下的变化可以颠倒。在这种情况下,我希望一些从Rails应用程序厚望,但没有...

b) if not (a) - should server detect it? is there possibility to do it in rails? In such case changes can be reversed. In such case i would expect some kind of expection from rails application but there is not...

推荐答案

HTTP是无状态协议 :根据定义意味着你可以不知道在客户端的HTTP动词 POST 成功与否。

有一些技术,Web应用程序使用来克服这个HTTP'功能'。他们包括

There are some techniques that web applications use to overcome this HTTP 'feature'. They include.

然而,这些都不是真的要帮助您的问题。当我在过去碰上这些类型的问题,他们的 服务器时间太长处理的几乎总是结果web请求

However, none of these are really going to help with your issue. When I have run into these types of issues in the past they are almost always the result of the server taking too long to process the web request.

有是一个真正伟大的报价来,我小声对自己的不眠之夜:

There is a really great quote to that I whisper to myself on sleepless nights:

网络请求是一个可怕的地方,你想进入和离开一样快
  你可以 - 里克布兰森

"The web request is a scary place, you want to get in and out as quick as you can" - Rick Branson

您想进入和退出100的Web请求 - 500毫秒。你满足这些数字,你将有一个Web应用程序,将表现良好/与Web服务器玩好。

You want to be getting into and out of your web request in 100 - 500 ms. You meet those numbers and you will have a web application that will behave well/play well with web servers.

为此的我建议你研究多久你的帖子的服用,并找出如何缩短这些请求即可。如果你正在做的DBMS之前在服务器端做一些严肃处理插入你应该考虑这些交给了某种任务处理/排队系统。

To that end I would suggest that you investigate how long your post's are taking and figure out how to shorten those requests. If you are doing some serious processing on the server side before doing dbms inserts you should consider handing those off to some sort of tasking/queuing system.

严肃处理的例子可能是某种形式的图片上传的,可能与上传经过一些图像处理。
一个任务和排队解决方案的一个例子是:的RabbitMQ 并的芹菜

An example of 'serious processing' could be some sort of image upload, possibly with some image processing after the upload. An example of a tasking and queuing solution would be: RabbitMQ and Celery

一个例子解决您的问题可能是:


  1. 插入数据的一部分进入数据库管理系统(或者甚至更快一些的NoSQL解决方案

  2. 手离开昂贵的处理后台任务。

  3. 返回到用户/ Web的客户端。 (甚至寿在后台任务仍在运行)

  4. 听的最后答复(<一个href=\"http://stackoverflow.com/questions/11077857/what-are-long-polling-websockets-server-sent-events-sse-and-comet/12855533#12855533\">polling,流媒体或中的WebSockets)这一步是不是一个简单的任务,但最终的结果是非常值得的努力。

  1. insert a portion of your data into the dbms ( or even faster some NoSQL solution )
  2. hand off the expensive processing to a background task.
  3. return to the user/web-client. ( even tho in the background the task is still running )
  4. listen for the final response with ( polling, streaming or websockets) This step is not a trivial undertaking but the end result is well worth the effort.

收紧的网络请求,这将是一个难得的一天,您的客户端没有收到响应。

Tighten up those web request and it will be a rare day that your client does not receive a response.

在罕见一天,客户端不接收数据:你如何prevent多个职位......我不知道你的数据什么。不过,也有一些架构相关的事情,你可以做唯一标识您的文章。即计算出在服务器端如果数据是更新创建

On that rare day that the client does not receive the data: How do you prevent multiple posts... I don't know anything about your data. However, there are some schema related things that you can do to uniquely identify your post. i.e. figure out on the server side if the data is an update or a create.

这个答案介绍了一些可以使用轮询/流/ WebSockets的技术。

This answer covers some of the polling / streaming / websockets techniques you can use.

这篇关于HTTP断开/请求和响应处理之间的超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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