Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Ruby

Profile Gem Memory Usage ใน Rails ด้วย Derailed: วิธีมีประสิทธิภาพ

Rails app ใช้ RAM มาก แต่อาจไม่ได้แค่ "เป็นแบบนี้" อาจเป็น gems ที่ bloated ทำให้ memory footprint ใหญ่ขึ้น

ผมเจอ project cool ของ Richard Schneeman ชื่อ derailed - automatic benchmarking tools ชุดนึง GitHub repo ที่นี่

เพิ่มใน Gemfile:

gem 'derailed', group: :development gem "stackprof", group: :development 

แล้วดูว่าแต่ละ gem ใช้ memory เท่าไหร่ตอน compile time:

Profile Gem Memory Usage ใน Rails ด้วย Derailed: วิธีมีประสิทธิภาพ ใช้ bundle:mem ดู RAM ที่แต่ละ gem ใช้ตอน compile time

ดู objects allocated โดย gems ตอน load time ได้อีกด้วย:

Profile Gem Memory Usage ใน Rails ด้วย Derailed: วิธีมีประสิทธิภาพ ใช้ bundle:objects ดู object allocation ตอน load time

ยังมี tools วัด memory usage ขณะ app รันอยู่ ยังไม่ได้ลองเพราะต้องรัน app ใน production mode บน development machine