1

我使用 Helicon Zoo 在 Windows Server 2008 机器上设置了一个 rails 应用程序。

我的问题是下载 400MB 以上的文件。

在我的 rails 应用程序中,我使用以下内容将文件发送到客户端:

应用程序/控制器/hosted_files_controller.rb

class HostedFilesController < ApplicationController
  before_filter :authenticate_user!
  around_filter :catch_not_foun

  def download
    @footprint = UserAbility.new(current_user).footprints.find(params[:id])
    send_file path
  end

  private

    def path
      if @footprint.subpath?
        @path = "#{HOSTED_FILES_PATH}\\#{@footprint.subpath}\\#{@footprint.filename}"
      else
        @path = "#{HOSTED_FILES_PATH}\\#{@footprint.filename}"
      end
    end

    def catch_not_found
      yield
    rescue ActiveRecord::RecordNotFound
      recover_and_log "We couldn't find that record.", "No record found using the id (#{params[:id]})"
    rescue ActionController::MissingFile
      recover_and_log "We couldn't find the file on our server.", "The file was not found at the following path: #{@path}"
    end

    def recover_and_log (displayed, logged)
      logger.info "!!! Error: #{logged}"
      redirect_to root_url, alert: displayed
    end
end

我在 production.rb 文件中注释掉了config.action_dispatch.x_sendfile_header,因为我没有使用 Apache 或 Nginx。

这适用于服务器上低于 ~400MB 的所有文件。在我超过它之后,我从 Helicon Zoo 收到一个 500 内部服务器错误,内容如下:

Helicon Zoo module has caught up an error. Please see the details below.
Worker Status
The process was created
Windows error
The pipe has been ended. (ERROR CODE: 109)
Internal module error
message: ZooApplication backend read Error. 
type: ZooException
file: Jobs\JobBase.cpp
line: 566 
version: 3.1.98.508 
STDERR
Empty stderr

有谁知道发生了什么?我不知所措。

我试过了:

  • 增加 send_file 上的 buffer_size(不起作用)
  • 在 IIS 中为应用程序池设置内存设置(不起作用)
  • 将 x_sendfile_header 更改为 X-Sendfile 和 X-Accel-Redirect(不起作用)

我正在考虑尝试在 Windows Server 上安装 Apache 并使用 x_sendfile_header 卸载将文件发送到 Apache,但我害怕搞砸已经(几乎)工作的应用程序。

有谁知道如何解决这个问题?

4

1 回答 1

0

By default with current version of Helicon Zoo Ruby applications are installed as FastCGI Ruby Rack connector. Since FastCGI protocol is a blocking protocol it may have some limitations on request timeout or request max size. If you need to send large files I suggest you to go "Ruby 1.9 Rack over HTTP with Thin" route instead. I suppose you've been following Ruby on Rails (2.3.x and 3.x.x) instruction. Now just follow additional steps from Ruby Rack over HTTP with Thin instruction, like running "gem install thin" command and editing web.config as follows:

In the < handlers> section comment out two lines that follows

< !-- Ruby 1.9 over FastCGI -->

Uncomment two lines that follows 
< !-- Ruby 1.9 over HTTP, using Thin as a back-end application server -->
In the <environmentVariables> section uncomment line 
< !-- Use this APP_WORKER with HTTP Ruby engine and Thin. Thin need to be installed.
< add name="APP_WORKER" value="GEM_HOME\bin\thin start" />

Another solution, since you already using Helicon products, would be installing Helicon Ape that provides support for X-Sendfile HTTP header (see documentation) header as in Apache and is free for several sites per server. This solution would be even better since low level WinHTTP code will be used to send data, which will decrease load to the server and improve response speed.

于 2014-04-20T20:26:04.537 回答