为什么 Rails 响应在开发模式下需要一分钟?



无法理解为什么我的 rails 应用程序变得超慢 - 在 1 分钟内!

正如我所看到的总时间 Rails 应该是:视图 0.2ms + 活动记录 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

找到速度变慢的原因。 我们团队中的某个人将延迟服务添加到控制器中。

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(在 RestClient 超时后一分钟内引发)。

Completed 401 Unauthorized in 62562ms (ActiveRecord: 191.5ms)
RestClient::Exceptions::ReadTimeout (Timed out reading data from server):

最新更新