Ruby/JRuby 和 WEBrick 一次处理一个请求

发布于 2024-09-06 09:17:12 字数 85 浏览 7 评论 0原文

有谁知道如何强制 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 技术交流群。

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

发布评论

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

评论(4

层林尽染 2024-09-13 09:17:13

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.

夏至、离别 2024-09-13 09:17:13

您绝对不应该使用 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.

我是有多爱你 2024-09-13 09:17:13

如果您运行的是 Rails 4,您可以应用以下补丁,webrick 将开始同时处理请求。

diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb
index e3119ec..ef04aa8 100644
--- a/railties/lib/rails/commands/server.rb
+++ b/railties/lib/rails/commands/server.rb
@@ -93,14 +93,6 @@ module Rails
       middlewares << [Rails::Rack::Debugger]  if options[:debugger]
       middlewares << [::Rack::ContentLength]

-      # FIXME: add Rack::Lock in the case people are using webrick.
-      # This is to remain backwards compatible for those who are
-      # running webrick in production. We should consider removing this
-      # in development.
-      if server.name == 'Rack::Handler::WEBrick'
-        middlewares << [::Rack::Lock]
-      end
-
       Hash.new(middlewares)
     end

If you are running rails 4 you can apply the following patch and webrick will start serving requests concurrently.

diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb
index e3119ec..ef04aa8 100644
--- a/railties/lib/rails/commands/server.rb
+++ b/railties/lib/rails/commands/server.rb
@@ -93,14 +93,6 @@ module Rails
       middlewares << [Rails::Rack::Debugger]  if options[:debugger]
       middlewares << [::Rack::ContentLength]

-      # FIXME: add Rack::Lock in the case people are using webrick.
-      # This is to remain backwards compatible for those who are
-      # running webrick in production. We should consider removing this
-      # in development.
-      if server.name == 'Rack::Handler::WEBrick'
-        middlewares << [::Rack::Lock]
-      end
-
       Hash.new(middlewares)
     end
铜锣湾横着走 2024-09-13 09:17:12

如果您使用 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.

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