Skip to content

admin: add /memory for inspection of heap usage#4361

Merged
htuch merged 8 commits intoenvoyproxy:masterfrom
ambuc:memory-admin
Sep 7, 2018
Merged

admin: add /memory for inspection of heap usage#4361
htuch merged 8 commits intoenvoyproxy:masterfrom
ambuc:memory-admin

Conversation

@ambuc
Copy link
Copy Markdown
Contributor

@ambuc ambuc commented Sep 6, 2018

Signed-off-by: James Buckland jbuckland@google.com

Description: Adds a /memory endpoint to the admin panel for fast inspection of Envoy::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

Signed-off-by: James Buckland <jbuckland@google.com>
@ambuc ambuc changed the title Add /memory for via-API inspection of heap usage admin: add /memory for inspection of heap usage Sep 6, 2018
Comment thread source/server/http/admin.cc Outdated

Http::Code AdminImpl::handlerMemory(absl::string_view, Http::HeaderMap&, Buffer::Instance& response,
AdminStream&) {
response.add(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will do this instead.

@htuch htuch self-assigned this Sep 6, 2018
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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some nits.

Comment thread api/envoy/admin/v2alpha/memory.proto Outdated
message Memory {

// The number of bytes allocated by the heap for Envoy.
uint64 currently_allocated_bytes = 1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to provide references back to the tcmalloc docs for folks who want to understand some of these metrics more deeply?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will link them to http://gperftools.github.io/gperftools/tcmalloc.html and try to standardize the field names everywhere.

Comment thread source/server/http/admin.cc Outdated
AdminStream&) {
envoy::admin::v2alpha::Memory memory;
memory.set_currently_allocated_bytes(Memory::Stats::totalCurrentlyAllocated());
memory.set_heap_size_bytes(Memory::Stats::totalCurrentlyReserved());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use the same field names as tcmalloc to minimize any semantic gap?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not make a fresh start here? There are no legacy deps and we can aim for alignment with the underlying data source?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of allocated and heap_size to match the existing values.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@htuch:

  1. Using different names to represent the same thing only leads to confusion, i.e. is this the same value as the one in /stats and if so why does it have different name?
  2. I don't believe anybody cares that those values come from tcmalloc and not OS or another data source, so the alignment here doesn't seem to provide any value.
  3. 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread test/server/http/admin_test.cc Outdated
Http::HeaderMapImpl header_map;
Buffer::OwnedImpl response;
EXPECT_EQ(Http::Code::OK, getCallback("/memory", header_map, response));
std::string output_json = response.toString();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: const std::string

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>
Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@htuch htuch merged commit b5ba7f8 into envoyproxy:master Sep 7, 2018
@ambuc ambuc deleted the memory-admin branch September 7, 2018 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants