admin: add /memory for inspection of heap usage#4361
admin: add /memory for inspection of heap usage#4361htuch merged 8 commits intoenvoyproxy:masterfrom
Conversation
Signed-off-by: James Buckland <jbuckland@google.com>
|
|
||
| Http::Code AdminImpl::handlerMemory(absl::string_view, Http::HeaderMap&, Buffer::Instance& response, | ||
| AdminStream&) { | ||
| response.add( |
There was a problem hiding this comment.
Can you use proto format for this? See https://github.com/envoyproxy/envoy/tree/master/api/envoy/admin/v2alpha. This the direction we want to move the API to make it more programmatic and expressable as proto/JSON/etc.
There was a problem hiding this comment.
Sure, I will do this instead.
Signed-off-by: James Buckland <jbuckland@google.com>
|
|
||
| .. http:post:: /memory | ||
|
|
||
| Prints current memory allocation / heap usage, in bytes. Useful in lieu of printing all `/stats` and filtering to get the memory-related statistics. |
There was a problem hiding this comment.
I don't have a problem with this, but I think it would be not too hard, and pretty useful, to give stats a filtered view -- the filter being applied during map construction, which would have the same benefit but might be more generally . useful, and wouldn't involve adding a new API and proto which would need to live forever.
This is really a matter of taste, though, and I'm fine with this approach if others are.
There was a problem hiding this comment.
Agreed, having a filter for a single stat would be useful for stat inspection. But the contents of Memory::Stats aren't really statistics, they're just bundled in there at calltime from MallocExtension. So this seemed like a more direct way to get this bit of information.
Signed-off-by: James Buckland <jbuckland@google.com>
| message Memory { | ||
|
|
||
| // The number of bytes allocated by the heap for Envoy. | ||
| uint64 currently_allocated_bytes = 1; |
There was a problem hiding this comment.
Do you want to provide references back to the tcmalloc docs for folks who want to understand some of these metrics more deeply?
There was a problem hiding this comment.
Sure, I will link them to http://gperftools.github.io/gperftools/tcmalloc.html and try to standardize the field names everywhere.
| AdminStream&) { | ||
| envoy::admin::v2alpha::Memory memory; | ||
| memory.set_currently_allocated_bytes(Memory::Stats::totalCurrentlyAllocated()); | ||
| memory.set_heap_size_bytes(Memory::Stats::totalCurrentlyReserved()); |
There was a problem hiding this comment.
Should we use the same field names as tcmalloc to minimize any semantic gap?
There was a problem hiding this comment.
Those values are already exposed in /stats as:
server.memory_allocated: 70379952
server.memory_heap_size: 74448896
so I'd rather re-use the existing names (either memory_allocated and memory_heap_size or just allocated and heap_size) than introducing new ones.
There was a problem hiding this comment.
Why not make a fresh start here? There are no legacy deps and we can aim for alignment with the underlying data source?
There was a problem hiding this comment.
I like the idea of allocated and heap_size to match the existing values.
There was a problem hiding this comment.
- Using different names to represent the same thing only leads to confusion, i.e. is this the same value as the one in
/statsand if so why does it have different name? - I don't believe anybody cares that those values come from
tcmallocand not OS or another data source, so the alignment here doesn't seem to provide any value. - Are we forever committed to
tcmalloc? Other allocators (e.g.jemalloc) use different names for those stats.
But we're bike-shedding about using currently_allocated_bytes or allocated (since both tcmalloc and /stats use heap_size), so I'm not going to push too much against it.
There was a problem hiding this comment.
Arguable by renaming the tcmalloc stats names we are already violating (1). I think (2) is actually not quite right; every time I stare at tcmalloc stats, I need to remind myself specifically what they are measuring, as there is a lot of nuance on each of the different stats it emits (e.g. is this memory allocated, is it allocated but in thread-local cache, is this memory released but not back to the OS, etc.).
I would probably vote to make this a oneof and export based on allocator the specific detailed, allocator defined stats. This is the most useful to the end user, since we don't need to be overly abstract and hide differences.
We can merge this as v2alpha and worry about the bikeshed when we lock down the API. @ambuc can you put in a TODO to consider adding more tcmalloc stats and exploring the naming tradeoffs?
There was a problem hiding this comment.
Sounds good -- agreed that these names can be misleading and should be bikeshedded to some degree. I'll merge this as-is and add a TODO for later.
| Http::HeaderMapImpl header_map; | ||
| Buffer::OwnedImpl response; | ||
| EXPECT_EQ(Http::Code::OK, getCallback("/memory", header_map, response)); | ||
| std::string output_json = response.toString(); |
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland jbuckland@google.com
Description: Adds a
/memoryendpoint to the admin panel for fast inspection ofEnvoy::Memory's heap statistics, without needing to query stats.Risk Level: Low
Testing: Added a test to
admin_test.cc.Docs Changes: Added a description of the option to
admin.rst.Release Notes: N/A