-
Notifications
You must be signed in to change notification settings - Fork 136
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
Оптимизация использования памяти при обработке файла #119
base: master
Are you sure you want to change the base?
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!
|
||
На этапе отладки потокового варианта использовала sample, к-й позволял оценить работоспособность в пределах пары секунд. | ||
|
||
Далее подобрала sample, с к-м фидбек можно было получить за 5-20 секунд. |
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.
👍
|
||
Подумала, раз `File`, то не открывать/закрывать его для каждого юзера, а открыть на запись 1 раз. | ||
|
||
Переписала - по памяти ничего не поменялось, но программа стала быстрее отрабатывать (27 => 21 секунд, если проверять на большом файле без профилирования) |
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.
да-да, надо не забывать разделять профилирование и замеры
|
||
Далее снова посмотрела с помощью memory_profiler: | ||
|
||
Увидела, что String ест много памяти, причём на месте `split(',')` |
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.
тут лучше быть более точным, ест много памяти => аллоцируется много объектов типа String или что-то ещё (потому что так не совсем понятно что конкретно это значит)
``` | ||
|
||
Можно оптимизировать `User` => `OptimizedUser` | ||
+ увидела, что не используются id и age, их убираем из объекта. |
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 | ||
|
||
Увидела много объектов `','`, завела константу `DELIMITER = ','` (omg, чем я занимаюсь) |
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.
))
по идее с # frozen_string_literal: true
можно оставлять просто строковые литералы
MEMORY USAGE: 334 MB | ||
MEMORY USAGE: 334 MB | ||
MEMORY USAGE: 334 MB | ||
MEMORY USAGE: 334 MB |
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.
в принципе видно было сразу по вот этим строкам, что сразу же идёт накопление памяти, а далее стоит на месте. (можно предположить что исходный файл читается в память целиком)
|
||
## Результаты | ||
В результате проделанной оптимизации удалось обработать файл с данными. | ||
Удалось улучшить метрику системы с использования 2444 MB и 30с до обработки целевого файла за 6-7 секунд и 29mb памяти, но не удалось уложиться в заданный бюджет. |
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.
Забыла отредактировать с прошлой версии ))
end | ||
|
||
describe 'Performance' do | ||
it 'uses under 30MB of memory' 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.
это не совсем uses, это allocates
у нас тут речь шла именно про MAX RSS
end.to perform_allocation(31457280).bytes | ||
end | ||
|
||
it 'performs under 7 seconds' 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.
cool!
Из-за дурацкой ошибки закопалась в микрооптимизации и до истины дошла только в конце.
Но case study оставила, как есть.