我正在使用瘦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

区别基本上是状态代码后面的“-”,就像生产服务器中的最后一行日志一样但我真的不知道那是什么意思。
我想知道在生产中是否多次处理了请求。
我用的是这种西纳特拉,这条路线。
class Project::Base < Sinatra::Application
  ..configs here
end

class Project::Routes::Home < Project::Base
  get '/'
    "something"
  end
end

配置ru
RACK_ENV = ENV["RACK_ENV"] ||= "development" unless defined? RACK_ENV
require 'sprockets'
map '/assets' do
  environment = Sprockets::Environment.new
  environment.append_path 'app/assets/javascripts'
  environment.append_path 'app/assets/stylesheets'

  run environment
end
require File.dirname(__FILE__) + '/config/boot.rb'
use Rack::Deflater
run GRBTV::Main

./config/启动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/依赖项.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

最佳答案

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

10-05 18:17
查看更多