Thanks Charles. This is just what I was looking for. I'll playing
around with setting the values. The default 1.5GB heap size would
On Mar 26, 8:28 pm, Charles Lowell <
cowb...@thefrontside.net> wrote:
> On Mar 26, 2013, at 6:10 PM, Mike Pearce wrote:
>
> > I am deploying some production code in a Rails app that is using
> > therubyracer is a high throughput usage. I read that the heap size
> > can be limited in v0.11:
> > Unfortunately, there is no indication on how to do it and it was not
> > clear to me looking at the code. Can anyone point me to a reference
> > or let me know how to do this?
>
> Mike,
>
> This is undocumented, uses a private interface, but here is some code to get you started. For some background info, V8 has a generational garbage collector which means that when objects are first allocated, they are in the young generation which is swept more aggressively. Objects that stay around longer are promoted to the old generation which are swept much less frequently. How much you should allocate for each generation depends on your app. To do so, you will instantiate a resource constraints and tell V8, in bytes, how much space to limit each memory arena. For example, here is one potential configuration that limits the memory to 144M. The default is 1.5G!
>
> constraints = V8::C::ResourceConstraints.new
> constraints.set_max_young_space_size 64 * 1024 * 1024 # 64M
> constraints.set_max_old_space_size 64 * 1024 * 1024 # 64M
> constraints.set_max_executable_size 16 * 1024 * 1024 # 16M
> V8::C::SetResourceConstraints(constraints)
>
> The max executable size I believe (although don't quote me) is the byte compiled and JITed code space. You can tweak these values to tune your app. Note, you need to do this *before* you initialize your very first V8::Context in order for it to have an effect.
>
> In order to see how much V8 has allocated, you can use yet another undocumented low-level interface:
>
> stats = V8::C::HeapStatistics.new
> V8::C::V8::GetHeapStatistics(stats)
> puts "total heap size: #{stats.total_heap_size}"
> puts "total heap executable size: #{stats.total_heap_executable_size}"
> puts "total physical size: #{stats.total_physical_size}"
> puts "used heap size: #{stats.used_heap_size}"
> puts "heap size limit: #{stats.heap_size_limit}"
>
> cheers,
> Charles
>
> > --
> > You received this message because you are subscribed to the Google Groups "The Ruby Racer" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to
therubyracer...@googlegroups.com.