【问题标题】:Ruby server very slow outside localhost (teambox)Ruby 服务器在本地主机之外非常慢(teambox)
【发布时间】:2010-03-13 07:12:50
【问题描述】:

我刚刚在我的 Ubuntu 9.10 服务器上安装了 TeamBox。我使用提供的服务器脚本在端口 3000 上启动并运行它。

运行速度极慢,从另一台计算机连接时,每个 HTTP 请求最多需要 30 秒。

我使用链接从 shell 加载 TeamBox,完全没有花费时间。

然后我设置了一个 SSH 隧道,它再次运行得非常快。

我在这台服务器上通过 apache 以及 SAMBA 等运行了大约 30 个虚拟主机,没有任何问题。

如何解决此问题?

【问题讨论】:

  • 您解决了这个问题吗?我刚刚遇到了一个非常相似的问题:Ubuntu 10.04,rails 3.0.1,当从 localhost 工作时一切都很快。当使用网络上的任何其他服务器时,页面需要 30 多秒才能加载。这甚至发生在一个全新/干净的 Rails 应用程序中,所以我强烈怀疑这是一些库/网络/配置问题。
  • 经过进一步调查,我可以从其他计算机和其他 Web 服务器(例如 Grails)正常 ping 服务器。所以这不太可能是系统或网络范围的问题,而只是 Rails 问题。

标签: ruby localhost performance ubuntu-9.10


【解决方案1】:

我的 redmine(ruby、webrick)太慢了。 现在我解决了这个问题: apt-get install mongrel <br> ruby /home/redmine/redmine/script/server mongrel -e production 完成了,redmine的工作速度非常好! 由

【讨论】:

  • 只是想说明这个解决方案非常有效。安装 mongrel,然后运行“rails server mongrel”,现在对 localhost 和其他机器的请求同样快速。不确定问题是什么,但我猜 WEBrick 在 Ubuntu 上存在某种问题。
【解决方案2】:

您使用的是乘客吗?几周前我遇到了同样的问题,并通过将其添加到我的虚拟主机文件中解决了这个问题。

 # Speeds up spawn time tremendously -- if your app is compatible.
    # RMagick seems to be incompatible with smart spawning
    RailsSpawnMethod smart

    # Just in case you're leaking memory, restart a listener
    # after processing 5000 requests
    PassengerMaxRequests 5000

    # only check for restart.txt et al up to once every 5 seconds,
    # instead of once per processed request
    PassengerStatThrottleRate 5

    # Keep the spawners alive, which speeds up spawning a new Application
    # listener after a period of inactivity at the expense of memory.
    RailsAppSpawnerIdleTime 0

    # Additionally keep a copy of the Rails framework in memory. If you're
    # using multiple apps on the same version of Rails, this will speed up
    # the creation of new RailsAppSpawners. This isn't necessary if you're
    # only running one or 2 applications, or if your applications use
    # different versions of Rails.
    RailsFrameworkSpawnerIdleTime 0

    # Keep the application instances alive longer. Default is 300 (seconds)
    PassengerPoolIdleTime 1000

【讨论】:

  • 不使用乘客。我不是通过 apache 运行 Teambox,而是使用它附带的 python 服务器。我很困惑为什么在通过 localhost 访问它和通过 LAN 访问它之间会有如此巨大的速度差异。对服务器的每个 HTTP 请求都会发生延迟。这似乎更像是一个网络问题。一旦 python 服务器收到请求,它就会非常快速地处理它。什么可能导致这种情况?
  • @natcow:如果不使用 IP,DNS 查找是最常见的
【解决方案3】:

发布 RoR 应用程序的一个好方法是使用 Nginx 作为 HTTP(S) 反向代理,与 thin ruby​​ 服务器关联(作为 gem 提供)。

Here is a good tutorial about Nginx with RubyOnRailshere another about thin

我也使用 redmine,在 OpenVZ 容器下使用 Nginx 和 Thin,并且运行良好!

【讨论】:

    猜你喜欢
    • 2011-06-05
    • 2020-07-12
    • 2011-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-01
    相关资源
    最近更新 更多