Memory optimization Shlyapnikov#116
Open
usernaimandrey wants to merge 2 commits intohardcode-dev:masterfrom
Open
Memory optimization Shlyapnikov#116usernaimandrey wants to merge 2 commits intohardcode-dev:masterfrom
usernaimandrey wants to merge 2 commits intohardcode-dev:masterfrom
Conversation
usernaimandrey
commented
Feb 2, 2025
- Полностью перевел программу на потоковую обработку
- Написал перформенс тест
- Изменил юнит-тест котроый теперь проверяет значения полей
spajic
approved these changes
Feb 4, 2025
Collaborator
spajic
left a comment
There was a problem hiding this comment.
Всё супер, спасибо за работу!
| 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 |
|
|
||
| 1. Сформировал короткие удобные алиаасы, что бы быстро получать обратную связь | ||
| 2. Быстро запустил профилировщики(`make all_reports`) -> посмотрел отчеты, нашел точку роста -> внес изменения и снова запусти профилировщик | ||
| 3. Создал отдельный вотчер, который запускается в отделном треде и проверяет количество используемой памяти(пишет лог), если оно привышает пороговое значение то выбрасывает исключение |
| ### Ваша находка №5 | ||
| 1. отчет `memory pro` и вотчер показывает что осноную память программа расходует когда накапливает данные и десеарилизует их затем в JSON(на большых данных 1340 MB) | ||
| 2. Решил сделать программу полностью потоковой, то есть сразу писать в результирующий отчет и максимум накапливать данные по одному пользователю | ||
| 3. Потребление памяти снизилось до константног - на полный отчет тратится всего 27 MB, так же увеличилась скорость 12.9!!!!! c за полный отчет |
| 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) |
Author
There was a problem hiding this comment.
Со sleep иногда бывало так что вотчер не успевал перехватить последний скачек памяти когда записывался json в файл и программа посто завершалась как будто все хорошо, вот я его и решил закоментить
| end | ||
| end | ||
|
|
||
| file.write("}, ") |
Collaborator
There was a problem hiding this comment.
Так тоже норм, но есть ещё вот такая апишка у oj для работы с потоковым json: https://www.rubydoc.info/gems/oj/2.17.3/Oj/StreamWriter
Author
There was a problem hiding this comment.
Здорово, спасибо такой гем знал но что у него стриминг есть нет)
| - как изменился отчёт профилировщика | ||
|
|
||
| ### Ваша находка №5 | ||
| 1. отчет `memory pro` и вотчер показывает что осноную память программа расходует когда накапливает данные и десеарилизует их затем в JSON(на большых данных 1340 MB) |
| - как изменилась метрика | ||
| - как изменился отчёт профилировщика | ||
|
|
||
| ### Ваша находка №5 |
Collaborator
There was a problem hiding this comment.
отлично, что сделали несколько итераций прежде чем переписывать! максимум пользы
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.