使用 Rack 将网络上传到套接字
我目前有一个 Sinatra 应用程序在 FCGI 处理程序中运行。我想编写一个处理程序,该处理程序将位于rackup文件中(可能位于Sinatra应用程序的前面),并通过套接字将大文件上传到另一台服务器(不首先将其缓冲在磁盘上),并与请求互锁。所以我想做的是某种无需参数准备的流解码发送工作流程。我在某处读到这有一个问题,因为特别是由于 Rails 团队希望看到中间件管道的方式,Rack 中的所有上传都已可回滚,这意味着上传将被缓冲,所以不仅我无法提供Rack 内的上传进度,但我还必须在磁盘上缓冲文件,然后将其发送到下游。
是否有一些跨后端解决方案将网络服务器的请求循环与机架响应器联系起来,并且不强制输入倒带(并且不强制上传的内存缓冲,这绝对是愚蠢的疯狂)?目前解决此类问题的方法是什么?
I currently have a Sinatra app running in an FCGI handler. I want to write a handler that will sit within the rackup file (probably in front of the Sinatra app) and will stream big file uploads to another server via sockets (without buffering it on disk first) and do so in interlock with the request. So what I would like to do is some kind of stream-decode-send workflow without param preparsing. I've read somewhere that there is a problem with this because specifically due to the way the Rails team wants to see the middleware pipeline all uploads in Rack have been made rewindable which implies that the upload will be buffered, so not only I cannot provide an upload progress within Rack but I also have to buffer the file on disk and then send it downstream.
Is there some cross-backend solution that ties the request loop of the webserver to the Rack responder and does not force rewinding on the input (and does not force in-memory buffering of the upload which is an absolute stupid madness)? What are the current approaches to this kind of problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是对的:Rack 规范要求可回滚输入,这意味着缓冲。 Rack 似乎不适合这项工作。
您可能想尝试 FastCGI,它确实允许非缓冲流。或者也许是一个 Java Servlet。我的2美分:你真的需要它吗?如果没有,不用担心,磁盘空间非常便宜。如果是这样,你真的需要用 Ruby 来做吗?
编辑:Mongrel::HTTPRequest 不支持无缓冲的大型流输入(没有猴子补丁)
You are right: the Rack spec mandates rewindable input, which implies buffering. It seems Rack is not the tool for this job.
You may want to try FastCGI, which does indeed allow non-buffered streaming. Or maybe a Java Servlet. My 2¢: Do you really need it? If not, don't worry, disk space is really cheap. If so, do you really need to do it in Ruby?
edit: Mongrel::HTTPRequest does not support unbuffered large streaming inputs (without monkeypatching)