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(因为部署环境) 如果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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |