ruby-on-rails-3 – 独角兽!和PostgreSQL

我正在将旧的Rails和Postgresql应用程序从2.1升级到Rails 3(通过成功的中间2.3.11步骤).

最后,当我让所有Rspecs顺利运行时,我安装了Mongrel 1.2.0.pre2并启动并运行 – 一切正常.即使是具有100个并发用户的JMeter测试用例也通过了OK.

但是当我和Unicorn一起尝试的时候!服务器,我自己使用它时工作正常,但当我用JMeter加载它时,它开始给出100%的错误,JMeter尝试POST登录.在我查看某个特定页面的同时,它给出了我这样的奇怪错误

undefined method `eq' for nil:NilClass

在终端,我得到以下输出(但只有几次):

message type 0x43 arrived from server while idle
message type 0x5a arrived from server while idle
WARNING:  there is already a transaction in progress

编辑:这似乎是共享PGconnect对象的问题,所以我删除了一些以前的文本

我发现PostgreSQL docs指定不能在进行并发请求的线程之间共享PGconn对象.

是独角兽!或AR混合来自同一PGconn对象中不同线程的请求?

database.yml的:

production:
  adapter: postgresql
  encoding: unicode
  database: ***
  username: ***
  password: ***
  host: 127.0.0.1

我甚至试图添加这个无济于事:

allow_concurrency: true

unicorn.conf:

worker_processes 8
working_directory "/full/path/to/app"
listen '/tmp/app.sock',:backlog => 512
timeout 30
pid "/full/path/to/app/tmp/pids/puppetmaster_unicorn.pid"

preload_app true
  if GC.respond_to?(:copy_on_write_friendly=)
  GC.copy_on_write_friendly = true
end

眼镜:

> Rails 3.0.6(因为部署环境)
>独角兽! 4.1.1
> Nginx 1.0.5
> pg gem 0.11.0
> Postgresql 9.0.4
> Mac OS X 10.7.2

如果Rails版本应该是罪魁祸首,当然我可以升级到最新版本.我刚刚开始了解服务提供商的工作.

解决方法

在进程之间共享数据库连接至关重要.当您使用preload_app运行Rails时,Rails将在unicorn master分叉工作者之前建立AR连接.示例unicorn.conf.rb建议断开before_fork挂钩中的AR连接. AR将自动重新建立新连接,因为每个工作人员都需要后叉.

摘自http://unicorn.bogomips.org/examples/unicorn.conf.rb

before_fork do |server,worker|
  # the following is highly recomended for Rails + "preload_app true"
  # as there's no need for the master process to hold a connection
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!
  # ...
end

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...