Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes RamUsageEstimator performance issue in tiered caching framework #16

Open
wants to merge 1 commit into
base: feature/tiered-caching
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public final class IndicesRequestCache implements TieredCacheEventListener<Indic
private final IndicesService indicesService;
private final Settings settings;
private final ClusterSettings clusterSettings;
protected final static long keyInstanceSize = RamUsageEstimator.shallowSizeOfInstance(Key.class);

IndicesRequestCache(Settings settings, IndicesService indicesService, ClusterSettings clusterSettings) {
this.size = INDICES_CACHE_QUERY_SIZE.get(settings);
Expand Down Expand Up @@ -459,7 +460,7 @@ interface CacheEntity extends Accountable, Writeable {
* @opensearch.internal
*/
class Key implements Accountable, Writeable {
private final long BASE_RAM_BYTES_USED = RamUsageEstimator.shallowSizeOfInstance(Key.class);
private final long BASE_RAM_BYTES_USED = IndicesRequestCache.keyInstanceSize;

public final CacheEntity entity; // use as identity equality
public final String readerCacheKeyId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,11 @@ public class IndicesService extends AbstractLifecycleComponent

private final SearchRequestStats searchRequestStats;

// Moved this computation out here to prevent recomputing the size over and over when initializing cache entities,
// now that IndexShardCacheEntity has to be non-static for serialization purposes
// (this was having significant performance impact)
protected static long indexShardCacheEntitySize = RamUsageEstimator.shallowSizeOfInstance(IndexShardCacheEntity.class);

@Override
protected void doStart() {
// Start threads that will manage cleaning the field data and request caches periodically
Expand Down Expand Up @@ -1864,7 +1869,7 @@ private BytesReference cacheShardLevelResult(
* @opensearch.internal
*/
public final class IndexShardCacheEntity extends AbstractIndexShardCacheEntity {
private final long BASE_RAM_BYTES_USED = RamUsageEstimator.shallowSizeOfInstance(IndexShardCacheEntity.class);
private final long BASE_RAM_BYTES_USED = IndicesService.indexShardCacheEntitySize;
private final IndexShard indexShard;

public IndexShardCacheEntity(IndexShard indexShard) {
Expand Down