Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

usernaimandrey
Copy link

  1. Полностью перевел программу на потоковую обработку
  2. Написал перформенс тест
  3. Изменил юнит-тест котроый теперь проверяет значения полей

Шляпников Андрей Николаевич added 2 commits February 2, 2025 16:34
Copy link
Collaborator

@spajic spajic left a 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
Copy link
Collaborator

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. Создал отдельный вотчер, который запускается в отделном треде и проверяет количество используемой памяти(пишет лог), если оно привышает пороговое значение то выбрасывает исключение
Copy link
Collaborator

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 за полный отчет
Copy link
Collaborator

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

м? sleep же нужен?

Copy link
Author

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("}, ")
Copy link
Collaborator

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

Copy link
Author

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

- как изменилась метрика
- как изменился отчёт профилировщика

### Ваша находка №5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

отлично, что сделали несколько итераций прежде чем переписывать! максимум пользы

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants