Last active
May 30, 2023 06:22
-
-
Save shved/dc1252f97658ed2cac1308b13b2275f4 to your computer and use it in GitHub Desktop.
Simple RSS limit test
This file contains 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
class TestMemoryUsage | |
LIMIT_MB = 70 # the memory limit you want to test | |
def run | |
work_thread = Thread.new do | |
# your ruby code here | |
end | |
loop do | |
sleep(0.1) | |
usage = check_memory_usage | |
puts "#{usage}Mb" | |
if usage > LIMIT_MB | |
puts 'Memory usage got higher the limit' | |
Thread.exit | |
end | |
break if !work_thread.status | |
end | |
work_thread.join | |
end | |
def check_memory_usage | |
(`ps -o rss= -p #{Process.pid}`.to_i / 1024.0).round(2) | |
end | |
end | |
TestMemoryUsage.new.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment