在西纳特拉,我有一个类似于以下的路线设置:

put '/test' do
  begin
    logger.info 'In put begin block'

    write_to_file(request.body.read)

    [200, '']
  rescue RuntimeError => e
    [500, 'some error']
  end
end

def write_to_file(data)
  logger.info "writing data with size #{data.size}"
  # Code to save file...
end

当我发送小于或等于500 MB的数据时,一切似乎都正常工作,但当我尝试发送大于或等于500 MB的数据时,我会得到一些奇怪的日志输出,然后客户端最终会出错,错误如下:excon::errors::socketerror:eoferor(eoferor)
来自服务器(sinatra)的日志如下所示:
对于小于500兆字节的数据:
I, [2013-01-07T21:33:59.386768 #17380]  INFO -- : In put begin block
I, [2013-01-07T21:34:01.279922 #17380]  INFO -- : writing data with size 209715200
xxx.xxx.xxx.xxx - - [07/Jan/2013 21:34:22] "PUT /test " 200 - 22.7917

对于大于500兆字节的数据:
I, [2013-01-07T21:47:37.434022 #17386]  INFO -- : In put begin block
I, [2013-01-07T21:47:41.152932 #17386]  INFO -- : writing data with size 524288000
I, [2013-01-07T21:48:16.093683 #17380]  INFO -- : In put begin block
I, [2013-01-07T21:48:20.300391 #17380]  INFO -- : writing data with size 524288000
xxx.xxx.xxx.xxx - - [07/Jan/2013 21:48:39] "PUT /test " 200 - 62.4515
I, [2013-01-07T21:48:54.718971 #17386]  INFO -- : In put begin block
I, [2013-01-07T21:49:00.381725 #17386]  INFO -- : writing data with size 524288000
I, [2013-01-07T21:49:33.980043 #17267]  INFO -- : In put begin block
I, [2013-01-07T21:49:41.990671 #17267]  INFO -- : writing data with size 524288000
xxx.xxx.xxx.xxx - - [07/Jan/2013 21:50:06] "PUT /test " 200 - 110.2076
xxx.xxx.xxx.xxx - - [07/Jan/2013 21:51:22] "PUT /test " 200 - 108.5339

不完全确定这里发生了什么,所以我想我的问题是两个方面,A。这两个案例之间有什么根本不同,会导致他们这样做?B.有没有更好的方法来处理数据来缓解这种情况?

最佳答案

问题出在apache/passenger上。用webrick运行服务器缓解了这个问题。

10-08 11:28