使用Rack将流媒体上传到套接字 [英] Streaming web uploads to socket with Rack

查看:74
本文介绍了使用Rack将流媒体上传到套接字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个在FCGI处理程序中运行的Sinatra应用程序.我想编写一个处理程序,该处理程序将位于机架文件中(可能位于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.

是否存在一些跨后端解决方案,将Web服务器的请求循环与Rack响应器绑定在一起,并且不强行回退输入(也不强行上载内存缓存,这绝对是愚蠢的疯狂)?目前解决此类问题的方法是什么?

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?

推荐答案

您是对的:Rack规范要求可回绕的输入,这意味着要缓冲.看来Rack不是完成这项工作的工具.

You are right: the Rack spec mandates rewindable input, which implies buffering. It seems Rack is not the tool for this job.

您可能想尝试FastCGI,它确实允许非缓冲流.也许是Java Servlet.我的2¢:您真的需要吗?如果没有,请不要担心,磁盘空间确实很便宜.如果是这样,您真的需要在Ruby中执行此操作吗?

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?

编辑:Mongrel :: HTTPRequest不支持无缓冲的大型流输入(无monkeypatching)

edit: Mongrel::HTTPRequest does not support unbuffered large streaming inputs (without monkeypatching)

这篇关于使用Rack将流媒体上传到套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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