-
Notifications
You must be signed in to change notification settings - Fork 134
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
Memory optimization Shlyapnikov #116
base: master
Are you sure you want to change the base?
Memory optimization Shlyapnikov #116
Conversation
usernaimandrey
commented
Feb 2, 2025
- Полностью перевел программу на потоковую обработку
- Написал перформенс тест
- Изменил юнит-тест котроый теперь проверяет значения полей
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.
Всё супер, спасибо за работу!
2025-02-01 15:18:08 +0300: 245 MB | ||
2025-02-01 15:18:09 +0300: 256 MB | ||
2025-02-01 15:18:10 +0300: 274 MB | ||
2025-02-01 15:18:12 +0300: 290 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.
👍 супер, сразу всё понятно
|
||
1. Сформировал короткие удобные алиаасы, что бы быстро получать обратную связь | ||
2. Быстро запустил профилировщики(`make all_reports`) -> посмотрел отчеты, нашел точку роста -> внес изменения и снова запусти профилировщик | ||
3. Создал отдельный вотчер, который запускается в отделном треде и проверяет количество используемой памяти(пишет лог), если оно привышает пороговое значение то выбрасывает исключение |
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.
👍
### Ваша находка №5 | ||
1. отчет `memory pro` и вотчер показывает что осноную память программа расходует когда накапливает данные и десеарилизует их затем в JSON(на большых данных 1340 MB) | ||
2. Решил сделать программу полностью потоковой, то есть сразу писать в результирующий отчет и максимум накапливать данные по одному пользователю | ||
3. Потребление памяти снизилось до константног - на полный отчет тратится всего 27 MB, так же увеличилась скорость 12.9!!!!! c за полный отчет |
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 = "%d" % (`ps -o rss= -p #{process_pid}`.to_i / 1024) | ||
f.write("#{Time.now}: #{memory} MB \n") | ||
raise LongMemoryUsageError, "usage memory to long #{memory}" if memory.to_i > limit | ||
# sleep(1) |
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.
м? sleep же нужен?
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.
Со sleep иногда бывало так что вотчер не успевал перехватить последний скачек памяти когда записывался json в файл и программа посто завершалась как будто все хорошо, вот я его и решил закоментить
end | ||
end | ||
|
||
file.write("}, ") |
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.
Так тоже норм, но есть ещё вот такая апишка у oj для работы с потоковым json: https://www.rubydoc.info/gems/oj/2.17.3/Oj/StreamWriter
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.
Здорово, спасибо такой гем знал но что у него стриминг есть нет)
- как изменился отчёт профилировщика | ||
|
||
### Ваша находка №5 | ||
1. отчет `memory pro` и вотчер показывает что осноную память программа расходует когда накапливает данные и десеарилизует их затем в JSON(на большых данных 1340 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.
👍
- как изменилась метрика | ||
- как изменился отчёт профилировщика | ||
|
||
### Ваша находка №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.
отлично, что сделали несколько итераций прежде чем переписывать! максимум пользы