无法理解为什么我的 Rails 应用程序的响应变得超慢 - 1 分钟内!
据我所知,Rails 的总时间应该是:Views 0.2ms + ActiveRecord 219.5ms + Solr 379.7ms = 599.4ms
但是它需要 62615ms,剩下的 62015.6ms 花在什么地方了?
Started POST "/applications/135" for ::1 at 2019-08-05 17:59:04 +0300
Processing by ApplicationController#create as JS
...
Completed 200 OK in 62615ms (Views: 0.2ms | ActiveRecord: 219.5ms | Solr: 379.7ms)
config/environments/development.rb
:
# frozen_string_literal: true
require 'sidekiq/testing/inline'
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Verifies that versions and hashed value of the package contents in the project's package.json
config.webpacker.check_yarn_integrity = false
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = false
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
# SMTP configuration
config.action_mailer.default_url_options = {
host: ENV['HOST']
}
config.action_mailer.delivery_method = :letter_opener
config.action_mailer.perform_deliveries = true
# Care if the mailer can't send.
config.action_mailer.raise_delivery_errors = true
end
最佳答案
找到减速的原因。 我们团队中有人在 Controller 中添加了延迟服务。
在config/environments/development.rb
中注释#require 'sidekiq/testing/inline'
并运行单独的sidekiq -C config/sidekiq。 yml
它解决了问题,现在服务正在异步运行。
但问题出在服务内部调用 RestClient.post(endpoint, payload.to_json, 'api-key': api_key)
的地方,它被包装到 begin rescue end
block 捕获错误(在一分钟内由 RestClient 超时引发)。
Completed 401 Unauthorized in 62562ms (ActiveRecord: 191.5ms)
RestClient::Exceptions::ReadTimeout (Timed out reading data from server):
关于ruby-on-rails - 为什么 Rails 响应在开发模式下需要一分钟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57361664/