Skip to content

Instantly share code, notes, and snippets.

@shved
Last active May 30, 2023 06:22
Show Gist options
  • Save shved/dc1252f97658ed2cac1308b13b2275f4 to your computer and use it in GitHub Desktop.
Save shved/dc1252f97658ed2cac1308b13b2275f4 to your computer and use it in GitHub Desktop.
Simple RSS limit test
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