-
Notifications
You must be signed in to change notification settings - Fork 195
Week_1 cpu (Shlyapnikov A.) #151
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
base: master
Are you sure you want to change the base?
Week_1 cpu (Shlyapnikov A.) #151
Conversation
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.
👍 nice work!
gzip -dk fixtures/data_large.txt.gz | ||
|
||
prepare_data: | ||
head -n 1000 fixtures/data_large.txt > fixtures/data1000.txt |
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.
лайк за makefile!
|
||
prepare_data: | ||
head -n 1000 fixtures/data_large.txt > fixtures/data1000.txt | ||
head -n 2000 fixtures/data_large.txt > fixtures/data2000.txt |
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.
fixtures лучше бы в gitignore добавить, чтобы не было 300к строк в PRе
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.
Fixed
@@ -12,45 +12,114 @@ | |||
Я решил исправить эту проблему, оптимизировав эту программу. | |||
|
|||
## Формирование метрики | |||
Для того, чтобы понимать, дают ли мои изменения положительный эффект на быстродействие программы я придумал использовать такую метрику: *тут ваша метрика* | |||
Для того, чтобы понимать, дают ли мои изменения положительный эффект на быстродействие программы я придумал использовать такую метрику: | |||
- обрабатывать 200_000 строк не больше чем за 1,5 сек, если я уложусь в это время, то обработка всего файла уложится в бюджет |
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.
в таких кейсах хорошо бы добавить чуть логики и арифметики - каким соотношением руководствуемся, какие числа и как получаем такой результат
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.
Наверное как то так?
Целевая метрика - мы хотим что бы полной отчет формировался(3250940) не более чем за 30 сек?
"Processing time from file 1000000 rows: 41.2784" // полный отчет | ||
``` | ||
|
||
Асимптотика финальная - видно что она почти линейная |
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.
ну она в принципе после первой итерации почти сразу и превращается в линейную
|
||
## Гарантия корректности работы оптимизированной программы | ||
Программа поставлялась с тестом. Выполнение этого теста в фидбек-лупе позволяет не допустить изменения логики программы при оптимизации. | ||
|
||
## Feedback-Loop | ||
Для того, чтобы иметь возможность быстро проверять гипотезы я выстроил эффективный `feedback-loop`, который позволил мне получать обратную связь по эффективности сделанных изменений за *время, которое у вас получилось* | ||
Для того, чтобы иметь возможность быстро проверять гипотезы я выстроил эффективный `feedback-loop`, который позволил мне получать обратную связь по эффективности сделанных изменений за 5 минут(внес изменеия -> запустил бенчмарк и профилировщик-> посмотрел результат) |
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.
👍
|
||
*Какими ещё результами можете поделиться* | ||
1. Пробовал запускать коллектинг данных по пользователям в несколько тредов(на кажый вызов `collect_stats_from_users(report, users_objects) do |user|` отдельный тред) - в моем случае это привело к регресу производительности с 37 сек. до 60 |
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.
с concurrency ещё будем разбираться в курсе
в целом в Ruby два треда не могут что-то считать одновременно; поэтому если задача именно в том чтобы что-то считать (а не ждать IO), то добавление треда не поможет, а скорее сделает хуже - как и произошло
но здорово, что проверили
file_lines_count = file_lines.count | ||
|
||
users_storage = {} | ||
unique_browsers = Set[] |
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.
👍
lib/task-1.rb
Outdated
|
||
# Даты сессий через запятую в обратном порядке в формате iso8601 | ||
collect_stats_from_users(report, users_objects) do |user| | ||
{ 'dates' => user.sessions.map{|s| s[:date]}.map {|d| Date.parse(d)}.sort.reverse.map { |d| d.iso8601 } } |
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.
тут есть пасхалочка, что дата изначально в нормальном формате, поэтому с ней можно ничего не делать
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.
Спасибо! Слона то и не заметил, плюс ко всему это довольно замедляет программу.
Попробовал убрать и сразу - 8 сек на больших данных, было 29 стало 21
@@ -0,0 +1,26 @@ | |||
require 'ruby-progressbar' | |||
|
|||
class ProgressBarFactory |
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.
👍
tests/task_perform_spec.rb
Outdated
let(:time) { 1.5 } | ||
let(:paths) { ['fixtures/data1000.txt', 'fixtures/data2000.txt', 'fixtures/data4000.txt', 'fixtures/data8000.txt'] } | ||
|
||
shared_examples 'when create report' do |
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.
чот как-то сложно, мб без shared examples просто
it 'creates the report in expected time' do
...
end
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.
Ага поправил!
No description provided.