Skip to content

Instantly share code, notes, and snippets.

@SamSaffron
Last active December 20, 2016 22:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamSaffron/b8e06a9873034575dacef82f4123a604 to your computer and use it in GitHub Desktop.
Save SamSaffron/b8e06a9873034575dacef82f4123a604 to your computer and use it in GitHub Desktop.
@preallocate = []
500_000.times do
@preallocate << ""
end
def process_request
allocate = rand(80_000) + 20000
req = []
allocate.times do
req << " " * rand(1000)
end
end
def stats(i)
puts "Heap length: #{GC.stat[:heap_sorted_length]} iterations: #{i} slots #{GC.stat[:heap_available_slots]} GC counts: #{GC.stat[:minor_gc_count]}/#{GC.stat[:major_gc_count]} old_objects #{GC.stat[:old_objects]}"
end
i = 0
@heap_length = GC.stat[:heap_sorted_length]
stats(0)
while true
i += 1
process_request
#GC.start(full_mark: true)
if @heap_length < GC.stat[:heap_sorted_length]
@heap_length = GC.stat[:heap_sorted_length]
stats(i)
end
end
@SamSaffron
Copy link
Author

SamSaffron commented Dec 20, 2016

Ruby 2.3.3

sam@ubuntu tmp % RUBY_GC_HEAP_GROWTH_MAX_SLOTS=40000 ruby heap_bloater.rb
Heap length: 1299 iterations: 0 slots 511132 GC counts: 16/6 old_objects 489320
Heap length: 1590 iterations: 1 slots 647678 GC counts: 19/7 old_objects 577148
Heap length: 1784 iterations: 2 slots 726752 GC counts: 21/8 old_objects 572503
Heap length: 1881 iterations: 3 slots 732051 GC counts: 22/8 old_objects 606905
Heap length: 1978 iterations: 5 slots 772402 GC counts: 23/8 old_objects 606905
Heap length: 2014 iterations: 6 slots 801751 GC counts: 24/8 old_objects 606905
Heap length: 2065 iterations: 8 slots 816424 GC counts: 25/9 old_objects 510879
Heap length: 2162 iterations: 13 slots 842102 GC counts: 28/9 old_objects 510882

Ruby master (2.4)

sam@ubuntu tmp % RUBY_GC_HEAP_GROWTH_MAX_SLOTS=40000 ruby heap_bloater.rb
Heap length: 1288 iterations: 0 slots 510725 GC counts: 19/6 old_objects 484871
Heap length: 1484 iterations: 1 slots 582462 GC counts: 21/6 old_objects 510439
Heap length: 1680 iterations: 2 slots 645639 GC counts: 23/7 old_objects 605798
Heap length: 1778 iterations: 3 slots 703519 GC counts: 24/7 old_objects 606129
Heap length: 1876 iterations: 4 slots 731643 GC counts: 25/8 old_objects 510441

@funny-falcon
Copy link

@SamSaffron
Copy link
Author

good point, I should fix that @funny-falcon , I actually want to generate data that looks more like a real request, so I should get a more accurate sampling of a real req and then regenerate that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment