duktape icon indicating copy to clipboard operation
duktape copied to clipboard

How to get memory used by a Duktape context?

Open carlosabalde opened this issue 5 years ago • 3 comments

I've just added preliminary support for JavaScript execution inside Varnish Cache using Duktape and a Varnish Cache VMOD. That's going to be complementary to Lua support and lots of testing and benchmarking are still pending (high performance is critical in a Varnish Cache environment).

Since Lua / LuaJIT were already supported and Duktape takes a lot of inspiration from them, adding support for Duktape has been pretty simple. However, I've not been able to find the equivalent Duktape call for lua_gc(L, LUA_GCCOUNT, 0). That returns the current amount of memory (in Kbytes) used by a Lua context. Is there something similar for Duktape? It would be very handy for metrics, benchmarking, etc.

P.S.: please, add https://github.com/carlosabalde/libvmod-cfg/ to the list of projects using Duktape if you want :)

carlosabalde avatar Jun 25 '19 21:06 carlosabalde

There's currently no such binding, but it's been requested several times. It's a bit tedious but not complicated to implement, so I'll try to see if I can find the time this week to get an experimental API into master.

svaarala avatar Jun 25 '19 21:06 svaarala

Forgot to add that such an API can add together the requested allocation size for each heap object, but it cannot easily account for allocation overhead. This is one of the reasons I haven't needed such a binding myself -- I usually try to measure memory usage with e.g. valgrind massif or an instrumented custom pool allocator.

svaarala avatar Jun 25 '19 21:06 svaarala

Thanks a lot for the quick feedback! Of course I'm assuming allocation overhead won't be included. In any case, if the feature is not available at the moment, I'd keep it low priority.

carlosabalde avatar Jun 25 '19 22:06 carlosabalde