-
Notifications
You must be signed in to change notification settings - Fork 50
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
ДЗ 7 #35
Open
hworoshch
wants to merge
2
commits into
hardcode-dev:master
Choose a base branch
from
hworoshch:master
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
ДЗ 7 #35
Changes from all commits
Commits
Show all changes
2 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 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,2 @@ | ||
.idea/ | ||
|
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,71 @@ | ||
## Подготовка | ||
|
||
- [x] Локальный запуск репозитория `dev.to`. | ||
- [x] Настройка `TICK stack`. | ||
|
||
## Оптимизация | ||
|
||
1. При первом прогоне время выполнения тестов составило: | ||
``` | ||
Total time: 397 s. | ||
``` | ||
2. Я установил значение `:fatal` для `log_level` и запустил тесты в параллельном режиме, время выполнения уменьшилось вдвое: | ||
``` | ||
Total time: 181 s. | ||
``` | ||
3. Далее я решил поэкспериментировать и увеличил количество потоков до 6: `parallel:spec[6]`, но многие тесты начали сыпаться и покрытие сократилось до 35% — виден провал в начале графика. После того как я устранил проблему, покрытие вновь вернулось к изначальному уровню, но прирост скорости был не таким значительным: | ||
``` | ||
Total time: 160 s. | ||
``` | ||
Такое значение прохождения полного сьюта меня устраивало, поэтому я решил заняться непосредственно оптимизацией. | ||
|
||
4. Я использовал `rspec --profile` для определения наиболее медленных тестов. | ||
``` | ||
Top 10 slowest example groups: | ||
Reading list | ||
4.48 seconds average (17.9 seconds / 4 examples) ./spec/features/user_views_a_reading_list_spec.rb:3 | ||
internal/users | ||
3.66 seconds average (25.64 seconds / 7 examples) ./spec/controllers/internal_users_controller_spec.rb:3 | ||
Creating Comment | ||
3.18 seconds average (9.53 seconds / 3 examples) ./spec/features/comments/user_fills_out_comment_spec.rb:3 | ||
... | ||
``` | ||
Основным кандидатом на оптимизацию стал тест `internal_users_controller_spec.rb`. Я изучил отчеты `stackprof` и увидел, что большую часть времени занимает вызов `BacktraceCleaner`, после отключения гема `honeycomb` в окружении `test` я получил следующие результаты: | ||
``` | ||
Top 10 slowest example groups: | ||
Creating Comment | ||
3.06 seconds average (9.17 seconds / 3 examples) ./spec/features/comments/user_fills_out_comment_spec.rb:3 | ||
Reading list | ||
2.73 seconds average (10.93 seconds / 4 examples) ./spec/features/user_views_a_reading_list_spec.rb:3 | ||
internal/users | ||
2.48 seconds average (17.39 seconds / 7 examples) ./spec/controllers/internal_users_controller_spec.rb:3 | ||
... | ||
``` | ||
``` | ||
[TEST PROF INFO] RSpecDissect report | ||
|
||
Total time: 00:17.107 | ||
``` | ||
Далее я удалил из спеки вызовы `Delayed::Worker`: | ||
``` | ||
[TEST PROF INFO] RSpecDissect report | ||
|
||
Total time: 00:04.699 | ||
``` | ||
И использовал хелперы `let_it_be` и `before_all`: | ||
``` | ||
[TEST PROF INFO] RSpecDissect report | ||
|
||
Total time: 00:01.073 | ||
``` | ||
|
||
Общее время выполнения тест-сьюта также уменьшилось: | ||
``` | ||
Total time: 102 s. | ||
``` | ||
|
||
## Результаты | ||
|
||
В результате проделанной работы мне удалось значительно уменьшить время прохождения тестов — с 397 до 102 секунд. | ||
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. ✅ 4x boost, nice |
||
|
||
 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
вот лучше не смешивать два шага в одну итерацию оптимизации
теперь не понятно что дало какой прирост, уровень логгирования или параллелизм