Skip to content
Closed
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 @@ -28,11 +28,14 @@
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.Expiry;
import com.github.benmanes.caffeine.cache.Policy;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.binder.cache.CaffeineStatsCounter;
import jakarta.annotation.Nonnull;
import java.lang.ref.SoftReference;
import java.time.Duration;
import java.util.List;
import java.util.OptionalLong;
import org.projectnessie.versioned.storage.common.exceptions.ObjTooLargeException;
import org.projectnessie.versioned.storage.common.persist.Obj;
import org.projectnessie.versioned.storage.common.persist.ObjId;
Expand Down Expand Up @@ -105,16 +108,26 @@ public long expireAfterRead(
.ifPresent(
meterRegistry -> {
cacheBuilder.recordStats(() -> new CaffeineStatsCounter(meterRegistry, CACHE_NAME));
meterRegistry.gauge(
"cache_capacity_mb",
singletonList(Tag.of("cache", CACHE_NAME)),
"",
x -> config.capacityMb());
List<Tag> tags = singletonList(Tag.of("cache", CACHE_NAME));
meterRegistry.gauge("cache_capacity_mb", tags, "", x -> config.capacityMb());
meterRegistry.gauge("cache_weight_mb", tags, "", x -> weightedSizeMb());
});

this.cache = cacheBuilder.build();
}

private double weightedSizeMb() {
// Note: calling Policy.Eviction::weightedSize may actually perform evictions.
Copy link
Copy Markdown
Member Author

@dimas-b dimas-b Apr 3, 2025

Choose a reason for hiding this comment

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

I suppose evictions in this call may only happen in practice under load.

long w =
cache
.policy()
.eviction()
.map(Policy.Eviction::weightedSize)
.orElse(OptionalLong.empty())
.orElse(0L);
return (double) w / 1024L / 1024L;
}

@Override
public Persist wrap(@Nonnull Persist persist) {
ObjCacheImpl cache = new ObjCacheImpl(this, persist.config());
Expand Down