我正在尝试将整个文件夹添加到我的Rails应用程序的JRuby 1.5类路径中.在JRuby的维基提出以下建议:"......添加config目录到JRuby的类路径config/environment.rb:"
$CLASSPATH << "file:///#{File.expand_path(File.join(RAILS_ROOT, 'config'))}/"
Run Code Online (Sandbox Code Playgroud)
这对我来说似乎不起作用.无论我是在Rails::Initializer.run块之前,之后还是之内放置它都没关系.无论如何,我得到:
/home/sean/src/sbruby/seo/config/environment.rb:45:NoMethodError: undefined method `<<' for nil:NilClass
/home/sean/apps/jruby/jruby-1.5.0/lib/ruby/gems/1.8/gems/rails-2.3.7/lib/rails/backtrace_cleaner.rb:2:NameError: uninitialized constant ActiveSupport::BacktraceCleaner
/home/sean/apps/jruby/jruby-1.5.0/lib/ruby/gems/1.8/gems/rails-2.3.7/lib/console_with_helpers.rb:5:NameError: uninitialized constant ApplicationController
Run Code Online (Sandbox Code Playgroud)
例如,我正在尝试在RAILS_ROOT被调用下添加一个文件夹resources/foobar,因此我将以下内容添加到environment.rb:
$CLASSPATH << "file:///#{File.expand_path(File.join(RAILS_ROOT, "resources", "foobar"))}/"
Run Code Online (Sandbox Code Playgroud)
同样的错误.
使用Rails将文件夹添加到JRuby类路径的正确方法是什么?
我们正在运行一个在Tomcat上运行的Rails上写的JRuby的小型Web应用程序.我们正在使用与另一个生产Web应用程序共享的Spring后端.不幸的是,我们一直遇到PermGen问题.
操作系统:Ubuntu Linux 2.6.24-24-server#1 SMP x86_64 GNU/Linux Java:1.6.0_21 Tomcat:6.0.28 JRuby:1.5.0 Rails:2.3.7
我们目前正在被谷歌,雅虎和百度抓获,因此网站使用率上升.我一直在使用JConsole监视Tomcat,我们肯定会看到有太多类的问题.当tomcat启动时,我们加载了大约12,000个类.8小时后,我们加载了近75,000个班级.PermGen同时从100MB增加到460MB.
类卸载工作正常,但它只在同一个8小时内卸载了~500个类.PermGen似乎永远不会被收集.
我们正在运行Tomcat的以下VM选项:
-Xms2048m -Xmx2048m -XX:MaxPermSize=512m -XX:PermSize=128m \
-XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:ParallelGCThreads=4 \
-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled
Run Code Online (Sandbox Code Playgroud)
显然存在某种泄漏.问题是在哪里?关于如何追踪谁以及对此负责的任何建议?我希望这是我们的一些非常愚蠢的错误,但我不知道从哪里开始.
任何建议将不胜感激.
编辑
看起来我们正在看到为每个传入请求创建一个新类.
编辑2
这肯定与JRuby有关.使用JConsole,我为类加载器启用了详细模式.以下是来自catalina.out的示例:
[Loaded anon_class1275113147_895127379 from file:/opt/apache-tomcat-6.0.28/webapps/notes/WEB-INF/lib/jruby-core-1.5.0.jar]
[Loaded anon_class1354333392_895127376 from file:/opt/apache-tomcat-6.0.28/webapps/notes/WEB-INF/lib/jruby-core-1.5.0.jar]
[Loaded anon_class1402528430_895127373 from file:/opt/apache-tomcat-6.0.28/webapps/notes/WEB-INF/lib/jruby-core-1.5.0.jar]
Run Code Online (Sandbox Code Playgroud)
那么问题就变成了如何追踪负责创建这些额外课程的一方?
编辑3
不确定这是否是问题所在,但不知何故,我们最终会遇到疯狂的类加载器.跑jmap -permstat PID了但得到了:
class_loader classes bytes parent_loader alive? type
total = 1320 135748 947431296 N/A alive=1, dead=1319 N/A
Run Code Online (Sandbox Code Playgroud)
这看起来有点过分了.大多数有三种类型的类加载器的一个:sun.reflect.DelegatingClassLoader,org.jruby.util.JRubyClassLoader或org.jruby.util.ClassCache$OneShotClassLoader.再次,样本输出来自jmap -permstat:
class_loader classes bytes parent_loader alive? …Run Code Online (Sandbox Code Playgroud) 虽然我不是一个完整的Ruby/Rails newb,但我仍然很绿,我正在试图弄清楚如何构建一些模型关系.我能想到的最简单的例子是烹饪"食谱"的想法.
配方由一种或多种成分和每种成分的相关数量组成.假设我们在数据库中有所有成分的主列表.这表明两个简单的模型:
class Ingredient < ActiveRecord::Base
# ingredient name,
end
class Recipe < ActiveRecord::Base
# recipe name, etc.
end
Run Code Online (Sandbox Code Playgroud)
如果我们只是想用配方原料联系起来,这是因为作为simpling添加适当的belongs_to和has_many.
但是,如果我们想将其他信息与该关系联系起来呢?每个Recipe都有一个或多个Ingredients,但我们想要指出的数量Ingredient.
什么是Rails模型的方式?这是一个什么样的线has_many through?
class Ingredient < ActiveRecord::Base
# ingredient name
belongs_to :recipe_ingredient
end
class RecipeIngredient < ActiveRecord::Base
has_one :ingredient
has_one :recipe
# quantity
end
class Recipe < ActiveRecord::Base
has_many :recipe_ingredients
has_many :ingredients, :through => :recipe_ingredients
end
Run Code Online (Sandbox Code Playgroud) jruby ×2
jrubyonrails ×2
activerecord ×1
classpath ×1
has-many ×1
memory-leaks ×1
permgen ×1
tomcat ×1