Ruby 精简服务器多次记录相同的请求

Ruby 精简服务器多次记录相同的请求,ruby,logging,heroku,sinatra,thin,Ruby,Logging,Heroku,Sinatra,Thin,我正在使用瘦web服务器,为Ruby/Sinatra应用程序提供服务。引起我注意的是,当我跑步时: RACK_ENV=production rackup 每个请求都记录了5次,并且有不同的时间戳 vagrant@lucid32:/app$ RACK_ENV=production rackup ** Building /assets/application.js... ** Building /assets/screen.css... >> Thin web server (v1.4

我正在使用瘦web服务器,为Ruby/Sinatra应用程序提供服务。引起我注意的是,当我跑步时:

RACK_ENV=production rackup
每个请求都记录了5次,并且有不同的时间戳

vagrant@lucid32:/app$ RACK_ENV=production rackup
** Building /assets/application.js...
** Building /assets/screen.css...
>> Thin web server (v1.4.1 codename Chromeo)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:9292, CTRL+C to stop
10.0.2.2 - - [12/Aug/2012 03:54:56] "GET / HTTP/1.1" 200 4 0.0024
10.0.2.2 - - [12/Aug/2012 03:54:56] "GET / HTTP/1.1" 200 4 0.0034
10.0.2.2 - - [12/Aug/2012 03:54:56] "GET / HTTP/1.1" 200 4 0.0044
10.0.2.2 - - [12/Aug/2012 03:54:56] "GET / HTTP/1.1" 200 4 0.0054
10.0.2.2 - - [12/Aug/2012 03:54:56] "GET / HTTP/1.1" 200 4 0.0065
10.0.2.2 - - [12/Aug/2012 03:54:56] "GET / HTTP/1.1" 200 4 0.0076
10.0.2.2 - - [12/Aug/2012 03:54:56] "GET / HTTP/1.1" 200 4 0.0094
10.0.2.2 - - [12/Aug/2012 03:54:56] "GET / HTTP/1.1" 200 - 0.0102
这让我相信,不知何故,这个请求被多次提出。或者只是记录了很多次

当我跑的时候

rackup
并尝试相同的请求。这是我得到的

vagrant@lucid32:/app$ rackup
>> Thin web server (v1.4.1 codename Chromeo)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:9292, CTRL+C to stop
10.0.2.2 - - [12/Aug/2012 03:56:42] "GET / HTTP/1.1" 200 - 0.1228
区别基本上是状态代码后面的“-”,如生产服务器中的最后一行日志。但我真的不知道那是什么意思

我想知道,在生产过程中,该请求是否被多次处理。 我用的是Sinatra这样的路线

class Project::Base < Sinatra::Application
  ..configs here
end

class Project::Routes::Home < Project::Base
  get '/'
    "something"
  end
end
./config/boot.rb

require 'rubygems'
gem 'psych'

# Require default environment config
require File.join(File.dirname(__FILE__), 'env')

# Bundler setup check 
require 'bundler'
begin
  Bundler.setup
rescue Bundler::BundlerError => e
  $stderr.puts e.message
  $stderr.puts "Run 'bundle install' to install missing gems"
  exit e.status_code
end


# Sinatra
require 'sinatra/base'
require 'sinatra/flash'
require 'json'

RACK_ENV = ENV['RACK_ENV'] ||= 'development' unless defined? RACK_ENV
ROOT_DIR = File.dirname(__FILE__).gsub(/config/,'')  unless defined? ROOT_DIR

# Path helper methods 
# root_path("config", "settings.yml")
def root_path(*args)
  File.join(ROOT_DIR, *args)
end

# relative_from_root_path("~/projects/project_name/config/settings.yml") #=> "config/settings.yml"
def relative_from_root_path(path)
  Pathname.new(path).relative_path_from(Pathname.new(ROOT_DIR)).to_s
end

# public_path("images") #=> "public/images"
def public_path(*args)
  root_path('public', *args)
end

# Module containers for autoloaded helpers and routes
module GRBTV
  module Helpers
  end
  module Routes
  end
end

# Attempts to require all dependencies with bundler, if this fails, bundle and then try again
require 'bundler'
Bundler.setup(:default)
Bundler.require(:default)

# Dependencies contains all required gems and core configuration
require root_path('config', 'dependencies.rb')

def app() GRBTV::Main end
./config/dependencies.rb

require File.join(File.dirname(__FILE__), './loader')

initializers = []
# Requires initializers
Loader.load_files('config/initializers/*.rb') do |file|
  require file
  begin
    # Save Initializer module in the initializers array
    file_class = File.basename(file, '.rb').camelize
    initializers << "#{file_class}Initializer".constantize
  rescue NameError
  end
end

require 'yaml'
YAML::ENGINE.yamler = 'psych'

# Load app components
['lib/*.rb', 'app/uploaders/*.rb', 'app/models/*.rb'].each do |glob|
  Loader.load_files(glob)
end


# Basic Sinatra::Application settingss
class GRBTV::Base < Sinatra::Application
  def options() settings end

  set :root, root_path
  set :views, root_path('app', 'views')
  set :public_folder, root_path('public')
  set :environment, RACK_ENV.to_sym if defined? RACK_ENV
    set :protection, :except => :frame_options

  use Rack::MethodOverride
  enable :sessions
  register Sinatra::NamedRoutes
  register MongoMapper
  helpers Sinatra::FieldBuilder
  helpers Sinatra::Warden::Helpers

  # Require all helpers
  Loader.load_files("app/helpers/**/*.rb") do |file|
    relative_path = relative_from_root_path(file).gsub(/\.rb$/, '').gsub('app/helpers/', '')
    module_name = "GRBTV::Helpers::#{relative_path.camelize}"
    Loader.define_namespaces(module_name)
    require file
    helpers module_name.constantize
  end


  # Sets the default layout for every route
  before do
    @default_layout = :'layout'
  end

  before '/assets/*' do
    headers['Cache-Control'] = 'public, max-age=86400'
  end
end

# Load mailers
Loader.load_files('app/mailers/*.rb')


class GRBTV::Main < GRBTV::Base
  # Requiring routes after extending path helpers
  Loader.load_files("app/routes/**/*.rb") do |file|
    relative_path= relative_from_root_path(file).gsub(/\.rb$/, '').gsub('app/routes/', '')
    module_name = "GRBTV::Routes::#{relative_path.camelize}"
    Loader.define_namespaces(module_name)
    require file
    use module_name.constantize
  end
end

# Load all initializers after setup is done
initializers.each do |initializer|
  GRBTV::Base.register initializer
end
require File.join(File.dirname(\uuuuu File\uuuuu),“./loader”)
初始值设定项=[]
#需要初始值设定项
Loader.load_文件('config/initializers/*.rb')do|文件|
需要文件
开始
#将初始值设定项模块保存在初始值设定项数组中
file_class=file.basename(文件'.rb').camelize
初始值设定项:帧_选项
使用Rack::MethodOverride
启用:会话
注册Sinatra::NameDrootes
寄存器MongoMapper
helpers Sinatra::FieldBuilder
帮手西纳特拉::典狱长::帮手
#需要所有助手
Loader.load_文件(“app/helpers/***.rb”)do|文件|
相对路径=根路径(文件).gsub(/\.rb$/,'').gsub('app/helpers/,'')的相对路径
module_name=“GRBTV::Helpers::{relative_path.camelize}”
Loader.define_名称空间(module_name)
需要文件
助手模块\u name.constantize
终止
#设置每条管线的默认布局
在做之前
@默认布局=:“布局”
终止
在“/assets/*”之前
头文件['Cache-Control']='public,最大使用年限=86400'
终止
终止
#邮递员
Loader.load_文件('app/mailers/*.rb')
类GRBTV::Main
这是一个Sinatra/Thin错误,应该在Sinatra 1.3.3(昨天发布)中修复。

这是一个Sinatra/Thin错误,应该在Sinatra 1.3.3(昨天发布)中修复。

格式为,最后添加了请求的总时间。生产机架堆栈中似乎有多个
Rack::CommonLogger
中间件实例(这可以解释时间值的增加)。如何为生产配置应用程序(在应用程序文件和
config.ru
文件中)?(这可能与日志记录问题无关,但可能是)。matt,我刚刚添加了config.ru、/config/boot.rb和/config/dependencies.rb的信息。这些是我的主要启动文件,以及包含所有配置的文件。我真的不知道如何只拥有一个机架。而且,正如您在链接中指出的,我正在从Sinatra应用程序中进行子类化,因为我确实需要所有的助手,以及其他控制器上的东西。这有意义吗?谢谢你!格式为,最后加上请求的总时间。生产机架堆栈中似乎有多个
Rack::CommonLogger
中间件实例(这可以解释时间值的增加)。如何为生产配置应用程序(在应用程序文件和
config.ru
文件中)?(这可能与日志记录问题无关,但可能是)。matt,我刚刚添加了config.ru、/config/boot.rb和/config/dependencies.rb的信息。这些是我的主要启动文件,以及包含所有配置的文件。我真的不知道如何只拥有一个机架。而且,正如您在链接中指出的,我正在从Sinatra应用程序中进行子类化,因为我确实需要所有的助手,以及其他控制器上的东西。这有意义吗?谢谢你!
require File.join(File.dirname(__FILE__), './loader')

initializers = []
# Requires initializers
Loader.load_files('config/initializers/*.rb') do |file|
  require file
  begin
    # Save Initializer module in the initializers array
    file_class = File.basename(file, '.rb').camelize
    initializers << "#{file_class}Initializer".constantize
  rescue NameError
  end
end

require 'yaml'
YAML::ENGINE.yamler = 'psych'

# Load app components
['lib/*.rb', 'app/uploaders/*.rb', 'app/models/*.rb'].each do |glob|
  Loader.load_files(glob)
end


# Basic Sinatra::Application settingss
class GRBTV::Base < Sinatra::Application
  def options() settings end

  set :root, root_path
  set :views, root_path('app', 'views')
  set :public_folder, root_path('public')
  set :environment, RACK_ENV.to_sym if defined? RACK_ENV
    set :protection, :except => :frame_options

  use Rack::MethodOverride
  enable :sessions
  register Sinatra::NamedRoutes
  register MongoMapper
  helpers Sinatra::FieldBuilder
  helpers Sinatra::Warden::Helpers

  # Require all helpers
  Loader.load_files("app/helpers/**/*.rb") do |file|
    relative_path = relative_from_root_path(file).gsub(/\.rb$/, '').gsub('app/helpers/', '')
    module_name = "GRBTV::Helpers::#{relative_path.camelize}"
    Loader.define_namespaces(module_name)
    require file
    helpers module_name.constantize
  end


  # Sets the default layout for every route
  before do
    @default_layout = :'layout'
  end

  before '/assets/*' do
    headers['Cache-Control'] = 'public, max-age=86400'
  end
end

# Load mailers
Loader.load_files('app/mailers/*.rb')


class GRBTV::Main < GRBTV::Base
  # Requiring routes after extending path helpers
  Loader.load_files("app/routes/**/*.rb") do |file|
    relative_path= relative_from_root_path(file).gsub(/\.rb$/, '').gsub('app/routes/', '')
    module_name = "GRBTV::Routes::#{relative_path.camelize}"
    Loader.define_namespaces(module_name)
    require file
    use module_name.constantize
  end
end

# Load all initializers after setup is done
initializers.each do |initializer|
  GRBTV::Base.register initializer
end