sony / v8eval

Multi-language bindings to JavaScript engine V8
MIT License
403 stars 37 forks source link

Get V8 Heap Usage #20

Closed paetling closed 8 years ago

paetling commented 8 years ago

If you are running long running v8 applications and are giving them lots of memory, it is often very useful to be able to inspect how much memory / heap each v8 isolate is using.

I propose that we add a simple method to v8.go on the v8 struct and the V8 interface that gives you back a struct where the attributes are uint64 values representing information about the isolates heap usage.

Will send a pr with my proposal shortly.

YoshiyukiMineo commented 8 years ago

Thank you for your proposal. I think it's better to introduce built-in heap() function like gc(). In the JS world, you can both check heap usage by calling heap() and do gc(). It does not change the v8eval interface and keeps it simple. What do you think?

paetling commented 8 years ago

Well it would seem like v8 / the javascript world disagrees. Right now you can check memory in both node and chrome but both of those use this isolate heap memory stuff. There does not seem to be a clear path to getting javascript / the ecmascript standard to implement a heap() method.

While I agree that not adding a method to expose the V8 heap usage keeps v8eval simple, it does leave what I would argue an important, powerful feature (that already exists in v8) out. I think if your concern is keeping v8eval simple for new users there are better ways to do that. For instance we can put this function in a different file called advanced.go and make it more clear this is just for inspecting memory.

At the end of the day if the goal of v8eval is just to provide a simple interface to v8 and nothing else that might be a reason to leave off heap memory usage. But I do not think that waiting for a v8 or an ecmascript heap() function is a real alternative. It seems like it is either expose a function like this through v8eval or do not expose it at all.

YoshiyukiMineo commented 8 years ago

I think it's not so difficult to implement heap() method using V8 APIs. I'll try to implement heap() and let you know the result.

YoshiyukiMineo commented 8 years ago

I have released v8eval 0.2.6 that introduces heap() experimentally. Currently you can use heap() only in Go version of v8eval. See https://github.com/sony/v8eval/blob/master/go/v8eval/v8_test.go#L112-L136. If you have any more problems, please feel free to let me know.