forked from hardcode-dev/rails-optimization-task4
-
Notifications
You must be signed in to change notification settings - Fork 0
Task 4 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AKrutik
wants to merge
3
commits into
master
Choose a base branch
from
task_4
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Task 4 #1
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| web: bin/rails s -p 3000 | ||
| webpacker: ./bin/webpack-dev-server | ||
| job: bin/rake jobs:work | ||
| prometheus_exporter: bundle exec prometheus_exporter -a prometheus/custom_collector.rb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| web: bin/rails s -p 3000 -e profile | ||
| webpacker: ./bin/webpack-dev-server | ||
| job: bin/rake jobs:work | ||
| prometheus_exporter: bundle exec prometheus_exporter -a prometheus/custom_collector.rb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| # Гипотеза | ||
|
|
||
| Все инструменты мониторинга показывают, что самой горячей точкой является главная страница, StoriesController#index. | ||
|
|
||
| В частности, заметное время занимает рендеринг partial-ов \_single_story.html.erb. | ||
|
|
||
| Рассмотрите гипотезу о том, что можно закешировать <%= render "articles/single_story", story: story %> в \_main_stories_feed.html.erb и это даст заметный эффект. | ||
|
|
||
| ## Benchmarking до оптимизации | ||
|
|
||
| ``` | ||
| Benchmarking 127.0.0.1 (be patient).....done | ||
|
|
||
| Server Software: | ||
| Server Hostname: 127.0.0.1 | ||
| Server Port: 3000 | ||
|
|
||
| Document Path: / | ||
| Document Length: 137084 bytes | ||
|
|
||
| Concurrency Level: 1 | ||
| Time taken for tests: 19.019 seconds | ||
| Complete requests: 100 | ||
| Failed requests: 0 | ||
| Total transferred: 13750700 bytes | ||
| HTML transferred: 13708400 bytes | ||
| Requests per second: 5.26 [#/sec] (mean) | ||
| Time per request: 190.187 [ms] (mean) | ||
| Time per request: 190.187 [ms] (mean, across all concurrent requests) | ||
| Transfer rate: 706.06 [Kbytes/sec] received | ||
|
|
||
| Connection Times (ms) | ||
| min mean[+/-sd] median max | ||
| Connect: 0 0 0.0 0 0 | ||
| Processing: 134 190 61.3 176 398 | ||
| Waiting: 134 190 61.3 176 398 | ||
| Total: 134 190 61.3 176 398 | ||
|
|
||
| Percentage of the requests served within a certain time (ms) | ||
| 50% 176 | ||
| 66% 192 | ||
| 75% 199 | ||
| 80% 205 | ||
| 90% 260 | ||
| 95% 366 | ||
| 98% 392 | ||
| 99% 398 | ||
| 100% 398 (longest request) | ||
| ``` | ||
|
|
||
| ## Проверка гипотезы | ||
|
|
||
| Добавила кэширование `story` в `app/views/stories/_main_stories_feed.html.erb` | ||
|
|
||
| ## Benchmarking после оптимизации | ||
|
|
||
| ``` | ||
| Benchmarking 127.0.0.1 (be patient).....done | ||
|
|
||
| Server Software: | ||
| Server Hostname: 127.0.0.1 | ||
| Server Port: 3000 | ||
|
|
||
| Document Path: / | ||
| Document Length: 137084 bytes | ||
|
|
||
| Concurrency Level: 1 | ||
| Time taken for tests: 5.803 seconds | ||
| Complete requests: 100 | ||
| Failed requests: 0 | ||
| Total transferred: 13750700 bytes | ||
| HTML transferred: 13708400 bytes | ||
| Requests per second: 17.23 [#/sec] (mean) | ||
| Time per request: 58.035 [ms] (mean) | ||
| Time per request: 58.035 [ms] (mean, across all concurrent requests) | ||
| Transfer rate: 2313.85 [Kbytes/sec] received | ||
|
|
||
| Connection Times (ms) | ||
| min mean[+/-sd] median max | ||
| Connect: 0 0 0.0 0 0 | ||
| Processing: 37 58 24.2 48 147 | ||
| Waiting: 37 58 24.1 48 146 | ||
| Total: 37 58 24.2 48 147 | ||
|
|
||
| Percentage of the requests served within a certain time (ms) | ||
| 50% 48 | ||
| 66% 53 | ||
| 75% 58 | ||
| 80% 72 | ||
| 90% 84 | ||
| 95% 128 | ||
| 98% 141 | ||
| 99% 147 | ||
| 100% 147 (longest request) | ||
| ``` | ||
|
|
||
| ## Выводы | ||
|
|
||
| Время загрузки страницы ускорилось в 3,2 раза | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| # rubocop:disable Metrics/BlockLength | ||
| # | ||
| def yarn_integrity_enabled? | ||
| ENV.fetch("YARN_INTEGRITY_ENABLED", "false") == "true" | ||
| end | ||
|
|
||
| Rails.application.configure do | ||
| # Verifies that versions and hashed value of the package contents in the project's package.json | ||
| config.webpacker.check_yarn_integrity = yarn_integrity_enabled? | ||
|
|
||
| # Settings specified here will take precedence over those in config/application.rb. | ||
|
|
||
| # 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 = true | ||
|
|
||
| # Do not eager load code on boot. | ||
| config.eager_load = true | ||
|
|
||
| # Show full error reports and disable caching. | ||
| config.consider_all_requests_local = true | ||
|
|
||
| # Enable/disable caching. By default caching is disabled. | ||
| if Rails.root.join("tmp/caching-dev.txt").exist? | ||
| config.action_controller.perform_caching = true | ||
|
|
||
| config.cache_store = :memory_store | ||
| config.public_file_server.headers = { | ||
| "Cache-Control" => "public, max-age=172800" | ||
| } | ||
| else | ||
| config.action_controller.perform_caching = false | ||
|
|
||
| config.cache_store = :null_store | ||
| end | ||
|
|
||
| # Don't care if the mailer can't send. | ||
| config.action_mailer.raise_delivery_errors = 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 = false | ||
|
|
||
| # Supress logger output for asset requests. | ||
| config.assets.quiet = true | ||
|
|
||
| # Do not fallback to assets pipeline if a precompiled asset is missed. | ||
| config.assets.compile = 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 | ||
|
|
||
| config.action_mailer.perform_caching = false | ||
|
|
||
| config.app_domain = "localhost:3000" | ||
|
|
||
| config.action_mailer.default_url_options = { host: "localhost:3000" } | ||
| config.action_mailer.delivery_method = :smtp | ||
| config.action_mailer.perform_deliveries = true | ||
| config.action_mailer.default_url_options = { host: config.app_domain } | ||
| config.action_mailer.smtp_settings = { | ||
| address: "smtp.gmail.com", | ||
| port: "587", | ||
| enable_starttls_auto: true, | ||
| user_name: '<%= ENV["DEVELOPMENT_EMAIL_USERNAME"] %>', | ||
| password: '<%= ENV["DEVELOPMENT_EMAIL_PASSWORD"] %>', | ||
| authentication: :plain, | ||
| domain: "localhost:3000" | ||
| } | ||
|
|
||
| config.action_mailer.preview_path = "#{Rails.root}/spec/mailers/previews" | ||
|
|
||
| # Raises error for missing translations | ||
| # config.action_view.raise_on_missing_translations = true | ||
|
|
||
| config.public_file_server.enabled = true | ||
|
|
||
| config.file_watcher = ActiveSupport::EventedFileUpdateChecker | ||
|
|
||
| # Install the Timber.io logger | ||
| send_logs_to_timber = ENV["SEND_LOGS_TO_TIMBER"] || "false" # <---- set to false to stop sending dev logs to Timber.io | ||
| log_device = send_logs_to_timber == "true" ? Timber::LogDevices::HTTP.new(ENV["TIMBER"]) : STDOUT | ||
| logger = Timber::Logger.new(log_device) | ||
| logger.level = config.log_level | ||
| config.logger = ActiveSupport::TaggedLogging.new(logger) | ||
| end | ||
|
|
||
| # rubocop:enable Metrics/BlockLength |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| if Rails.env != "test" | ||
| require "prometheus_exporter/middleware" | ||
|
|
||
| # This reports stats per request like HTTP status and timings | ||
| Rails.application.middleware.unshift PrometheusExporter::Middleware | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| if Rails.env.development? || Rails.env.profile? | ||
| require "rack-mini-profiler" | ||
|
|
||
| # The initializer was required late, so initialize it manually. | ||
| Rack::MiniProfilerRails.initialize!(Rails.application) | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍