rubyjs / therubyracer

Embed the V8 Javascript Interpreter into Ruby
1.66k stars 191 forks source link

Disposing context doesn't halt growth of heap #328

Closed koops closed 8 months ago

koops commented 9 years ago

Using TRR 0.12.1 on Mac and Linux with the same results.

I'm trying to solve runaway memory growth in my rails/trr application. When the v8 heap size (as reported by V8::C::V8::GetHeapStatistics) reaches a limit (such as 256 MB) my strategy is to dispose the context and create a new one. This seems to have no effect on memory usage. The heap size (and process size as reported by the OS) continues to grow. The overall process can reach 500 MB with what seems like light use.

I've tried setting constraints with V8::C::ResourceConstraints.new. However this seems to hit hard limits and throws exceptions.

I've also tried to prod v8 into garbage collection with V8::C::V8::IdleNotification(). It does reduce heap size, but doesn't stop allover growth.

I'm happy to come up with a test case if this is a bug. But first I'd like to know, is this a good strategy? Are there better ways? I'd rather not have monit regularly killing the process for excess memory usage.

cowboyd commented 9 years ago

@koops I'm adding specs to make sure that these types of errors are detected early, and don't make it into the upcoming 1.0 release. If this is still an issue, as of 0.12.2 I can include any reproduction you have into the regression suite of memory tests.