内存在空的 Rails 应用程序中无限增长 [英] Memory grows indefinitely in an empty Rails app

查看:19
本文介绍了内存在空的 Rails 应用程序中无限增长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白为什么我的 Rails 应用程序(托管在 Heroku (cedar) 上)不断分配越来越多的内存.如果我不知道更多,我会说这是 Ruby/Rails 中的内存泄漏,但由于我对 Ruby/Rails 完全陌生,我觉得我错过了一些非常明显的东西.

我正在使用由 rails new 生成的 Rails 默认值,以及完全最新的 gems:

source 'https://rubygems.org'宝石导轨",3.2.8"组:开发做宝石'sqlite3'结尾组:资产做gem "sass-rails", "~> 3.2.5"宝石咖啡轨",〜> 3.2.2"gem "uglifier", "~> 1.3.0"结尾gem "jquery-rails", "~> 2.1.2"组:生产做宝石'newrelic_rpm'宝石pg",〜> 0.14.1"结尾

我正在使用 几乎相同.我不明白我做错了什么.

任何指导将不胜感激.

编辑 (9/12):如果相关,我使用的是 ruby​​ 1.9.

我用来访问服务器的代码(C#):

using (var wc = new WebClient())for (;; Thread.Sleep(10000))wc.DownloadString("http://vast-earth-9859.herokuapp.com/");

编辑 (9/13):尝试禁用 New Relic 并查看它是否仍然是 R14.

解决方案

尝试移除 newrelic gem.我在 heroku 上有同样的问题,罪魁祸首是新遗物.您可以检查当前的对象是内存.下面的代码显示了对象计数.

ObjectSpace.each_object.with_object(Hash.new(0)){|obj, h|h[obj.class] +=1 }.select{|k,v|puts "#{k} => #{v}" 如果 k == String ||k == 数组 ||k == 哈希}

I can't figure out why my Rails app (hosted on Heroku (cedar)) keeps allocating more and more memory. If I didn't know any better I'd say that this a memory leak in Ruby/Rails, but since I'm completely new to Ruby/Rails, I feel like I'm missing something completely obvious.

I'm using Rails defaults generated by rails new, and completely up-to-date gems:

source 'https://rubygems.org'

gem 'rails', '3.2.8'

group :development do
  gem 'sqlite3'
end

group :assets do
  gem "sass-rails", "~> 3.2.5"
  gem "coffee-rails", "~> 3.2.2"
  gem "uglifier", "~> 1.3.0"
end

gem "jquery-rails", "~> 2.1.2"

group :production do
  gem 'newrelic_rpm'
  gem "pg", "~> 0.14.1"
end

I'm using the default newrelic config. I have zero models and one controller, nothing_controller.rb, which was generated using rails generate controller nothing:

class NothingController < ApplicationController
  def index
  end
end

I deleted public/index.html and added an empty views/nothing/index.html.erb. The only other thing I did to the generated app was add a route to routes.rb:

Nothing::Application.routes.draw do
  root :to => "nothing#index"
end

I committed, pushed it to Heroku, then wrote a quick script that would load my Heroku page every 10 seconds. This is what my New Relic reports:

That's all there is to it. Memory just keeps increasing like that until it passes Heroku's limit of 512MB. The code in this app is pretty much the same as the code I've seen in the tutorial I followed. I don't understand what I'm doing wrong.

Any guidance would be greatly appreciated.

EDIT (9/12): In case it's relevant, I'm using ruby 1.9.

Code I'm using to hit the server (C#):

using (var wc = new WebClient())
  for (;; Thread.Sleep(10000))
    wc.DownloadString("http://vast-earth-9859.herokuapp.com/");

EDIT (9/13): Going to try disabling New Relic and seeing if it still R14s.

解决方案

Trying removing newrelic gem. I had have same issue on heroku and culprit was newrelic gem. You can check your current object that is memory. Below code show you the object count.

ObjectSpace.each_object.with_object(Hash.new(0)){|obj, h| h[obj.class] +=1 }.select{|k,v| puts "#{k} => #{v}" if k == String || k == Array || k == Hash}

这篇关于内存在空的 Rails 应用程序中无限增长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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