其实是新项目,功能不太多,但是访问的速度有些慢,请问如何优化?
#1 楼 @miclle #2 楼 @kgen 服务器 2G 内存,1 个 cpu 我使用的是 nginx+unicorn 部署的项目 nginx:
upstream myapp_mimas {
server unix:/tmp/unicorn.mimas.sock fail_timeout=0;
}
server {
listen 9001;
#server_name demo.kanbing365.com;
#index index.html;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
try_files /system/maintenance.html $uri $uri/index.html $uri.html @ruby;
}
location @ruby {
proxy_pass http://myapp_mimas;
}
}
unicorn:
worker_processes 1
APP_PATH = "/home/ubuntu/deploy/current"
working_directory APP_PATH
listen "/tmp/unicorn.mimas.sock", :backlog => 64
pid APP_PATH + "/tmp/pids/unicorn.pid"
stderr_path APP_PATH + "/log/unicorn.stderr.log"
stdout_path APP_PATH + "/log/unicorn.stderr.log"
登陆首页面没有太多数据 另外我设置 production.rb:中的
config.assets.compile = true
config.assets.compile = true
设置为 true,会对页面渲染影像大吗 帮忙分析一下,谢谢
服务器重启后浏览器第一次访问时间特别慢将近 6 秒!但有的时候是 2 秒或者会少一些!,或者又会是 6 秒!:
I, [2014-01-08T02:11:15.225794 #1378] INFO -- : Started GET "/" for 127.0.0.1 at 2014-01-08 02:11:15 -0500
I, [2014-01-08T02:11:15.229076 #1378] INFO -- : Processing by HomeController#index as HTML
I, [2014-01-08T02:11:20.728990 #1378] INFO -- : Rendered sessions/_login_form.html.erb (1.8ms)
I, [2014-01-08T02:11:20.732002 #1378] INFO -- : Rendered home/index.html.erb within layouts/application (5.4ms)
I, [2014-01-08T02:11:21.225513 #1378] INFO -- : Rendered layouts/_shim.html.erb (0.1ms)
I, [2014-01-08T02:11:21.230549 #1378] INFO -- : Rendered navigations/navigation_list.html.erb (4.1ms)
I, [2014-01-08T02:11:21.230740 #1378] INFO -- : Rendered layouts/_header.html.erb (5.0ms)
I, [2014-01-08T02:11:21.231202 #1378] INFO -- : Completed 200 OK in 6002ms (Views: 505.2ms | ActiveRecord: 0.0ms)
I, [2014-01-08T02:11:21.445972 #1378] INFO -- : Started GET "/assets/body-bg.png" for 127.0.0.1 at 2014-01-08 02:11:21 -0500
I, [2014-01-08T02:11:21.455303 #1378] INFO -- : Started GET "/assets/icon.jpg" for 127.0.0.1 at 2014-01-08 02:11:21 -0500
开发环境:
Processing by HomeController#test2 as HTML
Rendered sessions/_login_form.html.erb (13.5ms)
Rendered home/test2.html.erb within layouts/application (21.3ms)
{"id"=>6, "name"=>"3307", "password_digest"=>"$2a$10$kFc5o5BpUSQpOfNlST13OuW/z8AwIYHR9nzW2/xIbl0sLa7PqK7U2", "patient_id"=>nil, "doctor_id"=>nil, "nurse_id"=>1, "is_enabled"=>true, "remember_token"=>""}
Rendered layouts/_shim.html.erb (0.3ms)
Rendered navigations/navigation_list.html.erb (24.0ms)
Rendered layouts/_header.html.erb (29.4ms)
Completed 200 OK in 161ms (Views: 157.6ms | ActiveRecord: 0.0ms)
config.assets.compile = false
然后你部署的时候,要 assets:precompile,否则会在加载页面的时候,即时 compile assets,就会慢。
deploy.rb 以前是这么写的,没起作用
deploy do
# Put things that will set up an empty directory into a fully set-up
# instance of your project.
invoke :'git:clone'
invoke :'deploy:link_shared_paths'
invoke :'bundle:install'
invoke :'rails:db_migrate'
invoke :'rails:assets_precompile'
to :launch do
queue! %[mkdir -p "#{deploy_to}/current/tmp/pids"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/current/tmp/pids"]
end
end
要改成这样么:
invoke :'rails:assets:precompile'
谢谢