-
Notifications
You must be signed in to change notification settings - Fork 84
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
igor-arkhipov/performance-improvement-4 #136
Open
IgorArkhipov
wants to merge
6
commits into
hardcode-dev:master
Choose a base branch
from
IgorArkhipov:igor-arkhipov/performance-improvement-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.
+3,494
−20
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d4892a0
Initial commit
IgorArkhipov 7dd4d88
Add profilers
IgorArkhipov 77feba0
Update skylight and add NewRelic
IgorArkhipov abbf2fb
Add prometheus and grafana
IgorArkhipov 3aac662
Add local production ENV
IgorArkhipov 82d5aea
Optimise performance
IgorArkhipov 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 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,16 @@ | ||
env: | ||
browser: true | ||
node: true | ||
es6: true | ||
extends: 'eslint:recommended' | ||
globals: | ||
Atomics: readonly | ||
SharedArrayBuffer: readonly | ||
parserOptions: | ||
ecmaFeatures: | ||
jsx: true | ||
ecmaVersion: 2018 | ||
sourceType: module | ||
plugins: | ||
- react | ||
rules: {} |
This file contains 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 +1 @@ | ||
2.6.3 | ||
2.7.7 |
This file contains 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 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 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 |
This file contains 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 | ||
webpacker: ./bin/webpack-dev-server | ||
job: bin/rake jobs:work | ||
prometheus_exporter: bundle exec prometheus_exporter |
This file contains 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 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 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 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,105 @@ | ||
# Case-study оптимизации | ||
|
||
## Актуальная проблема | ||
|
||
Нужно оптимизировать механизм загрузки главной страницы проекта `StoriesController#index`. | ||
|
||
Я решил исправить эту проблему, оптимизировав рендеринг шаблонов. | ||
|
||
## Формирование метрики | ||
|
||
Для того, чтобы понимать, дают ли мои изменения положительный эффект на быстродействие программы я придумал использовать такую метрику: число секунд, требуемые для прохождения нагрузочного бенчмарка `ab` с 30 запросами к главной странице проекта. | ||
|
||
## Вникаем в детали системы, чтобы найти главные точки роста | ||
|
||
Для того, чтобы найти "точки роста" для оптимизации я воспользовался инструментами rack-mini-profiler, Prometheus, Grafana. | ||
|
||
Вот какие проблемы удалось найти и решить | ||
|
||
### Ваша находка №1 | ||
|
||
- какой отчёт показал главную точку роста | ||
|
||
- rack-mini-profiler: заметное время занимает рендеринг `partial`-ов `_single_story.html.erb`, делаются 11 вызовов. Rendering: stories/\_main_stories_feed.html.erb duration 3.3ms, with children 57.1ms | ||
- ``` | ||
Document Path: / | ||
Document Length: 139178 bytes | ||
Concurrency Level: 1 | ||
Time taken for tests: 2.373 seconds | ||
Complete requests: 30 | ||
Failed requests: 0 | ||
Total transferred: 4206630 bytes | ||
HTML transferred: 4175340 bytes | ||
Requests per second: 12.64 [#/sec] (mean) | ||
Time per request: 79.097 [ms] (mean) | ||
Time per request: 79.097 [ms] (mean, across all concurrent requests) | ||
Transfer rate: 1731.23 [Kbytes/sec] received | ||
Connection Times (ms) | ||
min mean[+/-sd] median max | ||
Connect: 0 0 0.2 0 1 | ||
Processing: 69 79 18.0 74 164 | ||
Waiting: 69 79 18.0 74 164 | ||
Total: 69 79 18.2 75 166 | ||
Percentage of the requests served within a certain time (ms) | ||
50% 75 | ||
66% 77 | ||
75% 79 | ||
80% 80 | ||
90% 89 | ||
95% 111 | ||
98% 166 | ||
99% 166 | ||
100% 166 (longest request) | ||
``` | ||
Нашей точкой роста будет число вызовов отдельных шаблонов `articles/_single_story.html.erb` | ||
- как вы решили её оптимизировать | ||
- Применил кэширование в шаблоне при работе с коллекциями stories. Гипотеза состоит в том, что в случае не частых обновлений постов на главной странице кэширование снизит время изначальной загрузки за счет переиспользования данных об уже имеющихся постах. | ||
- как изменилась метрика | ||
- Метрика снизилась с 2.37 сек до 1.42 сек | ||
``` | ||
Document Path: / | ||
Document Length: Variable | ||
Concurrency Level: 1 | ||
Time taken for tests: 1.423 seconds | ||
Complete requests: 30 | ||
Failed requests: 0 | ||
Total transferred: 4208029 bytes | ||
HTML transferred: 4176759 bytes | ||
Requests per second: 21.08 [#/sec] (mean) | ||
Time per request: 47.445 [ms] (mean) | ||
Time per request: 47.445 [ms] (mean, across all concurrent requests) | ||
Transfer rate: 2887.15 [Kbytes/sec] received | ||
Connection Times (ms) | ||
min mean[+/-sd] median max | ||
Connect: 0 0 0.2 0 1 | ||
Processing: 39 47 15.7 44 120 | ||
Waiting: 39 47 15.7 43 119 | ||
Total: 39 47 15.9 44 121 | ||
Percentage of the requests served within a certain time (ms) | ||
50% 44 | ||
66% 45 | ||
75% 45 | ||
80% 47 | ||
90% 49 | ||
95% 84 | ||
98% 121 | ||
99% 121 | ||
100% 121 (longest request) | ||
``` | ||
- как изменился отчёт профилировщика | ||
- Rendering: stories/\_main_stories_feed.html.erb duration 10.1ms, with children 10.2ms | ||
## Результаты | ||
В результате проделанной оптимизации удалось ускорить время рендеринга главной страницы более чем в полтора раза. | ||
This file contains 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 |
---|---|---|
|
@@ -53,5 +53,7 @@ class Application < Rails::Application | |
end | ||
ReservedWords.all = [ReservedWords::BASE_WORDS + top_routes].flatten.compact.uniq | ||
end | ||
|
||
config.skylight.environments << 'localproduction' if Rails.env.localproduction? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Можно наверно и без условия добавить |
||
end | ||
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.
👍