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

问题描述

我无法弄清楚为什么我的Rails应用程序(托管在Heroku(雪松)上)继续分配越来越多的内存。如果我不知道更好的话,我会说这是Ruby / Rails中的内存泄漏,但由于我对Ruby / Rails完全陌生,因此我觉得我错过了完全明显的东西。



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

  source'https://rubygems.org'

gem'rails','3.2.8'

group:development do
gem'sqlite3'
end

group:assets do
gemsass-rails,〜> 3.2.5
gemcoffee-rails,〜> 3.2.2
gemuglifier,〜> 1.3.0
end

gemjquery-rails,〜> 2.1.2

group:production do
gem'newrelic_rpm'
gempg,〜> 0.14。 1
end

我使用中所见的代码几乎相同。我不明白我做错了什么。



任何指导都将不胜感激。



编辑(9/12):如果相关,我使用ruby 1.9。 b
$ b

我正在使用命中服务器(C#):

$ p $ for(;; Thread.Sleep(10000))
wc.DownloadString(http://vast-earth-9859.herokuapp.com/);

编辑(9/13):试着禁用New Relic并查看它是否仍然是R14s。 / p>

解决方案

尝试删除新的宝石。我在heroku上有同样的问题,罪魁祸首是新奇的宝石。
您可以检查当前是内存的对象。下面的代码显示了对象数量。

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


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应用程序中无限增长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 06:15