elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
69.68k stars 24.66k forks source link

Duplicate mappers consume too much heap memory #86440

Open original-brownbear opened 2 years ago

original-brownbear commented 2 years ago

Even with recent fixes to the heap consumption of field mappers, large frozen nodes require a lot of heap memory for duplicate mappers. An example from benchmarking today's master branch shows 67 different mappings taking up only ~100kb compressed in the cluster state on a data node holding ~16k indices/shards. On the other hand the actual MappingLookup instances (and thus the mapper service instances) consume 6.8G of heap.

image

(not that these are all beats mappings, so lots of fields and many keywords but I think it's a representative use case)

In fact, in the many shards benchmark that this is extracted from (that has this data node run indexing and searching at the time the dump was taken), the MappingLookup instances are the single largest consumer of heap. It seems to me there's no technical reason why we should not be able to massively deduplicate objects here when all the mappings are the same. We already do a lot of deduplication via tricks like https://github.com/elastic/elasticsearch/pull/86301 that helped bring down the consumption a lot recently but it seems we should go a little further here and tackle this at a higher level given the numbers?

Marking/suggesting this as ">bug" since it diminishes the scalability of frozen/warm/cold nodes greatly and should be somewhat straigh-forward to fix hopefully that classification is obviously debatable.

elasticmachine commented 2 years ago

Pinging @elastic/es-search (Team:Search)

joegallo commented 2 years ago

Related to https://github.com/elastic/elasticsearch/issues/77466

ywelsch commented 2 years ago

I've looked at bit deeper at the memory usage here. MappingLookup is indeed holding onto the majority of memory when having lots of indices on a frozen node. I've analyzed where and why so much memory is being spent there. What plays a factor here is:

What can we do to reduce the amount of memory taken by the lookup structures as well as the MappedFieldType and Mapper objects?

romseygeek commented 2 years ago

As we're targeting frozen indices here, where indexation isn't happening anyway, we could live with this limitation.

Would another option for frozen indices be just not to store the FieldMappers? From a quick look we would have to rework a couple of things around vector codecs and get, and the GetFieldMappings action wouldn't work, but these might be acceptable trade-offs.

elasticsearchmachine commented 2 months ago

Pinging @elastic/es-search-foundations (Team:Search Foundations)