ruby-on-rails – 我是否正确地在Heroku Unicorn中预加载应用程
发布时间:2020-12-16 19:05:50 所属栏目:百科 来源:网络整理
导读:在Heroku上使用Unicorn时.向上扩展会产生问题,因为当它仍在加载应用程序时,请求可以访问新扩展的web dyno.这主要导致超时错误. 我在http://codelevy.com/2010/02/09/getting-started-with-unicorn.html和https://github.com/blog/517-unicorn做了一些阅读 这
在Heroku上使用Unicorn时.向上扩展会产生问题,因为当它仍在加载应用程序时,请求可以访问新扩展的web dyno.这主要导致超时错误.
我在http://codelevy.com/2010/02/09/getting-started-with-unicorn.html和https://github.com/blog/517-unicorn做了一些阅读 这两篇文章建议使用preload_app true.还有一个after_fork和before_fork块. 在Rails 3中,还是需要before_block中的代码吗?我在某处读,否则.任何经历过这种情况并且想要分享的人? 我错过了什么吗?我是否正确加载了应用程序? # config/initializers/unicorn.rb # Read from: # http://michaelvanrooijen.com/articles/2011/06/01-more-concurrency-on-a-single-heroku-dyno-with-the-new-celadon-cedar-stack/ worker_processes 3 # amount of unicorn workers to spin up timeout 30 # restarts workers that hang for 90 seconds # Noted from http://codelevy.com/2010/02/09/getting-started-with-unicorn.html # and https://github.com/blog/517-unicorn preload_app true after_fork do |server,worker| ActiveRecord::Base.establish_connection end before_fork do |server,worker| ## # When sent a USR2,Unicorn will suffix its pidfile with .oldbin and # immediately start loading up a new version of itself (loaded with a new # version of our app). When this new Unicorn is completely loaded # it will begin spawning workers. The first worker spawned will check to # see if an .oldbin pidfile exists. If so,this means we've just booted up # a new Unicorn and need to tell the old one that it can now die. To do so # we send it a QUIT. # # Using this method we get 0 downtime deploys. old_pid = Rails.root + '/tmp/pids/unicorn.pid.oldbin' if File.exists?(old_pid) && server.pid != old_pid begin Process.kill("QUIT",File.read(old_pid).to_i) rescue Errno::ENOENT,Errno::ESRCH # someone else did our job for us end end end 解决方法
你在这里看到的是预期的.在你通过dyno扩展的那一刻,Heroku平台将把那个slu to部署到一个新的dyno,它与你的其他dynos(即另一个独角兽大师)完全隔离.
一旦该dyno被部署并运行(有效启动),路由网格将开始向该dyno发送请求,这是Rails将在Unicorn或其他任何服务器上启动时启动. 但是,一旦该请求到达,您将有30秒的窗口返回您的数据,或者请求将在路由网格上超时(错误H12). 因此,总而言之,您的问题与分叉无关,而是您的应用程序无法在30秒内启动,因此早期超时.担心分叉和PID文件不是你需要在Heroku平台上担心的事情. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Flex+Java+Eclipse开发环境搭建
- oracle恢复误删除数据,解除锁定等非常经典实用方法
- dojo.byId() dijit.byId() & jsId的区别与联系
- 5.1 Swift的枚举(enum)类型及遍历 [Swift原创教程]
- 如何在C中拒绝套接字连接?
- C对于游戏开发以及像VirtualBox这样的应用程序,对.NET有什么
- ruby-on-rails – Rails pixelarity模板(skel)
- ArcGIS API for Flex制作程序发布后出现错误:"访问 UR
- 重写ajax方法实现异步请求session过期时跳转登录页
- ruby-on-rails – 如何干掉Rails所需的ruby条件结构