Skip to content

Instantly share code, notes, and snippets.

@lucianosousa
Created September 1, 2014 22:37
Show Gist options
  • Save lucianosousa/3398c9aa760aa113faa2 to your computer and use it in GitHub Desktop.
Save lucianosousa/3398c9aa760aa113faa2 to your computer and use it in GitHub Desktop.
stress test example from somewhere else
@retained = []
@rand = Random.new(999)
MAX_STRING_SIZE = 100
def stress(allocate_count, retain_count, chunk_size)
chunk = []
while retain_count > 0 || allocate_count > 0
if retain_count == 0 || (@rand.rand < 0.5 && allocate_count > 0)
chunk << " " * (@rand.rand * MAX_STRING_SIZE).to_i
allocate_count -= 1
if chunk.length > chunk_size
chunk = []
end
else
@retained << " " * (@rand.rand * MAX_STRING_SIZE).to_i
retain_count -= 1
end
end
end
start = Time.now
# simulate rails boot, 2M objects allocated 600K retained in memory
stress(2_000_000, 600_000, 200_000)
# simulate 100 requests that allocate 100K objects
stress(10_000_000, 0, 100_000)
puts "Duration: #{(Time.now - start).to_f}"
puts "RSS: #{`ps -eo rss,pid | grep #{Process.pid} | grep -v grep | awk '{ print $1; }'`}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment