Ruby/JRuby 和 WEBrick 一次处理一个请求
有谁知道如何强制 WEBrick 一次处理多个请求?我在页面上使用一些 Ajax 来执行长时间运行的数据库相关任务,并且我可以清楚地看到请求正在管道中处理。
Does anyone knows how to force WEBrick to process more than one request at a time? I'm using some Ajax on my page for long running database-related tasks and I can clearly see the requests are being processed in a pipeline.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
webrick 一次只处理一个请求,这通常适合开发。
如果您希望并行运行,请查看 mongrel_cluster 或很棒的 unicorn 或 乘客 当然。
webrick only processes one request at a time, which is usually fine for development.
If you want things to run in parallel have a look at mongrel_cluster or the awesome unicorn or passenger of course.
您绝对不应该使用 WEBrick 来处理长时间运行的请求。最适合这项工作的 Web 服务器可能是 Thin,因为它由 EventMachine 提供支持,这使得编写异步代码成为可能,这样服务器就不会阻塞。
You should definitely not be using WEBrick for long running requests. The best web server for the job would probably be Thin, as it's powered by EventMachine which makes it possible to write asynchronous code so that the server doesn't block.
如果您运行的是 Rails 4,您可以应用以下补丁,webrick 将开始同时处理请求。
If you are running rails 4 you can apply the following patch and webrick will start serving requests concurrently.
如果您使用 JRuby,请查看 GlassFish gem(以 gem 形式精简的 GlassFish 服务器)、Trinidad gem(与使用 Tomcat 相同)或各种其他选项,如 warbler(生成可以直接运行或部署到任何环境的 .war 文件)应用服务器)。 JRuby 是在 Ruby 上部署高度并发应用程序的最简单方法,相比之下,C Ruby 选项显得相当原始。
If you use JRuby, check out the GlassFish gem (stripped-down GlassFish server in gem form), the Trinidad gem (same thing using Tomcat), or various other options like warbler (produces .war files you can run directly or deploy to any app server). JRuby is the easiest way for sure to deploy a highly-concurrent application on Ruby, and makes the C Ruby options look rather primitive in comparison.