使用 Rack 将网络上传到套接字

发布于 2024-10-14 01:42:10 字数 363 浏览 2 评论 0原文

我目前有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

睫毛溺水了 2024-10-21 01:42:10

你是对的: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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文