-
Notifications
You must be signed in to change notification settings - Fork 195
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
Optimize task 1 #152
base: master
Are you sure you want to change the base?
Optimize task 1 #152
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!
before do | ||
`head -n #{8000} data_large.txt > data_small.txt` | ||
end | ||
it 'works under 1 ms' 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.
👍
|
||
let(:measurement_time_seconds) { 1 } | ||
let(:warmup_seconds) { 0.2 } | ||
it 'works faster than 1 ips' 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.
👍
}.to perform_at_least(1).within(measurement_time_seconds).warmup(warmup_seconds).ips | ||
end | ||
|
||
it 'works with data_large under 35sec' 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.
для реального теста конечно слишком много; сейчас пришла идея, что в принципе можно даже закомитить что-то подобное в рабочую репу, но добавить например ENV-переменную вроде PERF_TEST
и запускать такие тесты только если ENV[PERF_TEST] == 'true'
Я решил исправить эту проблему, оптимизировав эту программу. | ||
|
||
## Формирование метрики | ||
Для того, чтобы понимать, дают ли мои изменения положительный эффект на быстродействие программы я придумал использовать такую метрику: Файл размером 3250940 строк должен обрабатываться за 30 секунд. |
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.
Это не совсем метрика, это финальный бюджет скорее
Этот вопрос в данном случае tricky. По факту нет простого одного ответа на всю работу. У нас на каждую итерацию оптимизации новая метрика - время работы на файлах разного размера. Когда мы не можем посчитать общую метрику на всю систему / исходную проблему, то мы можем воспользоваться промежуточными метриками. Их функция получается в том, чтобы помочь нам понять, была ли оптимизация успешна на данной итерации.
### Ваша находка №1 | ||
- Все отчеты показали главную точку роста Array#select (59.64% по ruby-prof flat) | ||
- Вместо перебора сессий в select создала массив sessins_hash c ключом user_id | ||
- На 16000 строк ips увеличился с 0.236 до 2.581 |
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.
главное, что асимптотику поправили
|
||
### Ваша находка №3 | ||
- callstack отчет показывает точку роста в collect_stats_from_users, а конкретно в Date#parse | ||
- Я решила сделать сортировку даты без парсинга |
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.84%) | ||
|
||
На этом моменте я решила использовать для бенчмаркинга и профилирования большие величины, чтобы увеличить точность. | ||
На 128_000 строк ips - 0.867i/s |
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.
ips лучше подходит для микро-бенчмарков, где много итераций в секунду
у нас тут скорее ситуация, когда надо много секунд на одну итерацию, поэтому проще в секундах считать
|
||
### Ваша находка №7 | ||
- ruby-prof flat показывает точку роста в Array#map | ||
- Несколько раз вызываются лишние map, убрала их. Так же заменила метод поиска уникальных браузеров на 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.
👍
|
||
## Результаты | ||
В результате проделанной оптимизации наконец удалось обработать файл с данными. | ||
Удалось улучшить метрику системы с до 33.65 что почти укладывается в заданный бюджет. |
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.
это конечно от компа зависит; в целом вроде у вас основное всё сделано чего обычно хватает для победы
есть шанс что во втором задании при подходе к этой проблеме с другой стороны получиться уложиться в 30 сек!
No description provided.