我开始使用bundler并且在使用它时遇到一些问题.我有以下gemfile:
source "http://rubygems.org"
gem "rack", "~>1.1"
gem 'pg','>= 0.8.0'
gem 'rails','2.3.8'
gem 'authlogic','2.1.3'
gem 'ajaxful_rating','2.2.3'
gem 'will_paginate','2.3.12'
gem 'right_aws','1.10.0'
gem 'aws-s3','0.6.2'
gem 'declarative_authorization','0.4.1'
gem 'timeline_fu','0.3.0'
gem 'friendly_id','>= 3.1'
Run Code Online (Sandbox Code Playgroud)
请注意,我具体说我想使用rack 1.1(1.1.0).
我运行瘦时遇到以下错误(Webrick工作正常):
thin start
>> Using rails adapter
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.3/lib/bundler/runtime.rb:27:in `setup': You have already activated rack 1.2.1, but your Gemfile requires rack 1.1.0. Consider using bundle exec. (Gem::LoadError)
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.3/lib/bundler/spec_set.rb:12:in `each'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.3/lib/bundler/spec_set.rb:12:in `each'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.3/lib/bundler/runtime.rb:17:in `setup'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.3/lib/bundler.rb:100:in `setup'
from /home/vmplanet/Documents/maga/config/../config/preinitializer.rb:16
from /home/vmplanet/Documents/maga/config/boot.rb:28:in `load'
from /home/vmplanet/Documents/maga/config/boot.rb:28:in `preinitialize'
from /home/vmplanet/Documents/maga/config/boot.rb:10:in `boot!'
from …Run Code Online (Sandbox Code Playgroud) 首先,如果可以,我会切换到Linux,但由于第三方依赖,我不能.
我正在完成并将rails应用程序部署到Windows 2008服务器上.在服务器上进行测试时,该应用程序被证明非常缓慢,请求每次需要2-5秒.在我的开发机器上,这远不是那么慢,而且据我所知,Rails本身的缓慢,即.我看到Completed 200 OK in 1859ms (Views: 1687.5ms)服务器上的日志记录与Completed 200 OK in 347ms (Views: 298.0ms)我的开发机器上的日志记录相比.
我知道Rails在Windows上应该比在Linux上慢,但是为什么它在Windows服务器上比在我的Windows 7开发机器上慢?
在开发中我运行WEBrick,在服务器上我在apache下运行瘦.我也试过在我的开发机器上运行瘦,如果不是WEBrick,它会更快.有没有人对可能造成如此大幅减速的事情有什么建议?任何事情都会非常感激.
更新:似乎Ruby本身在服务器上显着变慢.在irb中运行以下命令需要0.6秒,但在服务器上平均需要3秒以上:
n = Time.now ; x = 0 ; 10000000.times { x += 1 } ; puts Time.now - n
Run Code Online (Sandbox Code Playgroud)
什么可能导致Ruby在服务器上运行得如此之慢(超过3倍)?可能是Windows版本?或者是其他东西?Ruby版本完全相同:ruby 1.9.2p290 (2011-07-09) [i386-mingw32].
再次更新:
因为之前没有提到这个而感到愚蠢,但这是一个VPS.然而,虽然我愿意接受这会让它减慢一点 - 实际上慢了3倍?
在我的prod服务器上,我Missing template有时会得到例外.
设置是带有CentOS5,ruby 1.9.2,Rails 3.2.1,8个nginx实例,6个瘦实例的VPN
所以,这发生在两个主要观点,很少发生,约.每1000次请求1次,但确实如此
据我所知,瘦接收请求只是处理真正的异常,但我无法理解为什么,因为1000其他请求的999是好的,他们一定是好的.
这是文件系统问题吗?还是来自机器人的地方?
异常示例在这里:
From: Exception Notifier <myhost>
Subject: [myhost Exception] controllername#actionname (ActionView::MissingTemplate) "Missing
template controllername/actionname, application/actionname with {:locale=>[...
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Gm-Message-State: ALoCoQn4St5gK1z...
A ActionView::MissingTemplate occurred in controllername#actionname:
Missing template controllername/actionname, application/actionname with {:locale=3D>[:en], :fo=
rmats=3D>[:html], :handlers=3D>[:erb, :builder, :coffee, :haml]}. Searche=
d in:
* "/..mypath../releases/20120205001108/app/views"
actionpack (3.2.1) lib/action_view/path_set.rb:58:in `find'
-------------------------------
Request:
-------------------------------
* URL : http://myhost/actionurl
* IP address: 74.208.8.48
* Parameters: {"utf8"=3D>"=E2=9C=93", "authenticity_token"=3D>"Ffkm6Bd8=
wi3+Got7uTeLhzj86hJNDpFYRjG4Yrqx4yQ=3D", "video_link"=3D>"", "controller"=
=3D>"controllername", …Run Code Online (Sandbox Code Playgroud) 我看到了我能找到的所有地方,但似乎无法找到解决方案.我在Lion 10.8.2上使用xcode 4.5.1 - 我正在尝试为一个rails项目运行bundle而且它一直在干扰它.我正在使用宝石'瘦'用于heroku.现在我不得不做 - 没有人找到解决方案?
Bolanos@Jeremys-Mac-mini ?-1.9.3 fishfarm $ sudo gem install eventmachine
Password:
Building native extensions. This could take a while...
ERROR: Error installing eventmachine:
ERROR: Failed to build gem native extension.
/Users/Bolanos/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for rb_trap_immediate in ruby.h,rubysig.h... no
checking for rb_thread_blocking_region()... yes
checking for inotify_init() in sys/inotify.h... no
checking for __NR_inotify_init in sys/syscall.h... no
checking for writev() in sys/uio.h... yes
checking for rb_thread_check_ints()... yes
checking for rb_time_new()... yes
checking for sys/event.h... yes
checking for sys/queue.h... …Run Code Online (Sandbox Code Playgroud) 由于Thin/Unicorn是单线程的,您如何处理Thread.current/per-request存储?
刚刚运行了一个简单的测试 - 在一个会话中设置一个密钥,从另一个会话中读取它 - 看起来它始终从同一个地方写入/读取.但不会发生在WEBrick上.
class TestController < ApplicationController
def get
render text: Thread.current[:xxx].inspect
end
def set
Thread.current[:xxx] = 1
render text: "SET to #{Thread.current[:xxx]}"
end
end
Run Code Online (Sandbox Code Playgroud)
尝试添加config.threadsafe!到application.rb,没有变化.
存储每个请求数据的正确方法是什么?
为什么有使用Thread.current进行存储的宝石(包括Rails本身和倾斜)?他们如何克服这个问题?
可能是Thread.current 对于每个请求是安全的,但是在请求之后不能清除,我需要自己做吗?
总结下面与@skalee和@JesseWolgamott的讨论以及我的发现 -
Thread.current取决于运行应用程序的服务器.虽然服务器可能确保在同一个Thread.current上没有同时运行两个请求,但是此哈希中的值可能不会在请求之间被清除,因此在使用情况下 - 必须将初始值设置为覆盖最后一个值.
有一些众所周知的宝石使用Thread.current,如Rails,倾斜和draper.我想如果它被禁止或不安全,他们就不会使用它.在使用散列上的任何键之前,它们似乎都设置了一个值(甚至在请求结束后将其设置回原始值).
但总的来说,Thread.current并不是每个请求存储的最佳实践.对于大多数情况,更好的设计会做,但在某些情况下,使用env可以帮助.它可以在控制器中使用,也可以在中间件中使用,并且可以注入应用程序中的任何位置.
更新2 - 似乎现在,draper错误地使用Thread.current.请参阅https://github.com/drapergem/draper/issues/390
更新3 - 修正了漏斗错误.
如何在不需要重新启动服务器的情况下有效处理生产轨道环境中的更改资产?
我们遇到的问题是,我们必须重新启动运行应用程序的瘦服务器才能提供更新的javascript文件.
现在我们每小时从一些长时间运行的任务生成数据到javascript文件,所以我们可以在我们的Rails应用程序中使用它.
为了清楚起见,我们更新/覆盖现有文件,而不是添加新文件.
生成后,我们运行这些命令以重新预编译所有资产.
bundle exec rake assets:precompile
bundle exec rake rails_group=assets assets:clean RAILS_ENV=production
在清除浏览器缓存并重新加载页面后,我们仍在为旧资产提供服务.
你们有没有做过类似的经历; 你做了什么来解决它?
PS.祝大家节日快乐!
部署我的第一个Web应用程序.我一直在使用薄,简单易用.我只需要一个配置文件.
但是很多人使用nginx并在后面放置了一些瘦实例.为什么?为什么不单独使用瘦身?为什么使用nginx而不是在一个瘦实例后面放置3个瘦实例?谢谢
我有一个非常简单的应用程序托管在EC2上使用Sinatra构建,在nginx背后提供服务.问题是,使用Chrome,会话变量在Sinatra中"丢失".它不会发生在Firefox中.
这是使用Rack :: Session :: Cookie.这与此问题类似:Sinatra不会在Chrome上使用重定向来保持会话
任何有关如何在Chrome中解决此问题的见解将不胜感激.
I have a Rails app that is configured to only use SSL. I also have free SSL certificates from StartSSL.
I use thin as my web server with this command:
thin start -p 80 & thin start -p 443 --ssl --ssl-key-file ./.ssl/sslkey.key --ssl-cert-file ./.ssl/sslcert.cert &
Run Code Online (Sandbox Code Playgroud)
从技术上讲这是可行的-访问我网站的http版本会将其重定向到https版本。但是,当我访问该站点时,Chrome和Safari都会提示我从本地钥匙串中“选择证书”以对服务器进行验证。
此行为是不希望的。如何以不显示此对话框的方式设置SSL精简?
我整合兔子创业板的RabbitMQ使用Rails,我应该开始兔子线程Rails所用的应用程序开始启动或做在一个单独的rake任务,所以我可以在一个单独的进程中启动它的初始化?
我想如果我只生成消息,那么我需要在Rails初始化程序中执行它,这样它可以在应用程序中使用,但如果我正在消耗我应该在单独的rake任务中执行,这是正确的吗?
thin ×10
ruby ×5
nginx ×2
bundler ×1
bunny ×1
eventmachine ×1
heroku ×1
performance ×1
production ×1
rabbitmq ×1
rack ×1
sinatra ×1
ssl ×1
unicorn ×1