-
Notifications
You must be signed in to change notification settings - Fork 140
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
Homework solution #122
base: master
Are you sure you want to change the base?
Homework solution #122
Conversation
araslanov-e
commented
Feb 9, 2025
- Оптимизировал программу для обработки больших данных потребляя менее 70 Мб
- Добавил тест производительности
- Описал этапы оптимизации
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`: Создавал файл с N строк, чтобы программа могла выполнятся 10-20 секунд. | ||
|
||
## Вникаем в детали системы, чтобы найти главные точки роста | ||
Для того, чтобы найти "точки роста" для оптимизации я воспользовался memory_profiler, в котором смотрел какой код создает больше всего объектов, stackprof для большей детальности. Так же дополнительно был написан скрипт запускающий код в 2 потока, один из которых раз в секунду печатал потребление памяти. |
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`, который позволил мне получать обратную связь по эффективности сделанных изменений за за 10-20 секунд. | ||
|
||
Вот как я построил `feedback_loop`: Создавал файл с N строк, чтобы программа могла выполнятся 10-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.
👍
|
||
https://github.com/fastruby/fast-ruby?tab=readme-ov-file#date рекомендуют использовать Date.iso8601. | ||
Потребление памяти не сильно изменилось, осталось 504 MB, `211530 (9.7%) Date.iso8601` | ||
Попробовал Date.strftime, потребление памяти снизилось до `MEMORY USAGE: 356 MB`, `126921 (6.3%) Date.strptime`, оставил это решение. |
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.
с датой вообще ничего не надо делать, она сразу в нужном формате
296135 ( 40.3%) Object#parse_session | ||
46170 ( 6.3%) Object#parse_user | ||
``` | ||
Изучив код, принял решение отказаться от использования в данном месте метода split, а определять принадлежность к сущности user/session по началу строки. |
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.
по первой букве кстати даже можно
puts "Используемая память: #{memory_usage/1024} MB" | ||
|
||
if memory_usage > memory_limit | ||
puts "Превышен лимит памяти! Завершаем процесс..." |
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.
👍
puts "MEMORY USAGE: %d MB" % (`ps -o rss= -p #{Process.pid}`.to_i / 1024) | ||
memory = (`ps -o rss= -p #{Process.pid}`.to_i / 1024) | ||
puts "MEMORY USAGE: #{memory} MB" | ||
memory |
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.
👍 удобно