【发布时间】:2015-01-26 06:11:25
【问题描述】:
我遇到了与性能相关的问题。我有一个在 VPS 上运行的 ROR 应用程序。在互联网上花了很多时间讨论这个问题并且无法找到可靠的解决方案后,我在这里发布了我的问题。 我的 ROR 应用程序有近 300 个优质 视频 和 200 个 pdf,注册后用户可以观看免费视频。如果用户通过付款升级帐户,则他/她可以观看优质视频。
目前我正在使用发送文件方法提供视频文件,下面是代码。
SEND_FILE_METHOD = :default
def download
head(:not_found) and return if (track = Video.find_by_id(params[:id])).nil?
#head(:forbidden) and return unless track.downloadable?(current_user)
path = track.video.path(params[:style])
head(:bad_request) and return unless File.exist?(path) && params[:format].to_s == File.extname(path).gsub(/^\.+/, '')
contenttype = MIME::Types.type_for(path).first.content_type # => "image/gif"
send_file_options = { :type => contenttype }
case SEND_FILE_METHOD
when :apache then send_file_options[:x_sendfile] = true
when :nginx then head(:x_accel_redirect => path.gsub(Rails.root, ''), :content_type => send_file_options[:type]) and return
end
send_file(path, send_file_options)
end
我的问题是,
- 通过 Rails 应用程序提供优质视频的正确方法是什么?(我的客户端 VPS 只有 1 GB RAM)并且视频保存在 VPS 上的文件系统中。我担心的是,如果我的应用程序一次收到超过 100 个请求,ROR 应用程序可能无法服务器请求。我也想过把它放在公共文件夹中,但是这些视频仅供付费用户使用,所以我不能将它们放在公共视频中。
任何帮助或解决方案的链接都非常感谢.. 非常感谢:)
【问题讨论】:
-
请不要对短语使用任意粗体格式。它分散了问题的注意力。相反,看看大多数关于 SO 的问题是如何格式化并模仿的。
标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.2 ruby-on-rails-3.1