question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Long overflow in cache statistics

See original GitHub issue

We use Guava caches inside a large enterprise application.

After a few days of runtime calling the stats() method on heavily-used caches throws an IllegalArgumentException at the equivalent line to CacheStats.java:87, presumably because the total load time has overflowed a long and looped back round to a negative value.

It looks like this is down to the load time stopwatch being started at the point that an entry is submitted for asynchronous refresh, i.e. added to the refresh queue. Our largest queues are drained in batches and end-up with usual sizes in the tens of thousands — so the nanosecond-precision load time increases very quickly under these circumstances.

I am aware that it is a design decision for the cache statistics to be monotonically increasing, so a reasonably sane solution might be to simply drop the non-negative validation as part of the CacheStats constructor, or try to somehow wrap back to zero instead of Long.MIN_VALUE. Metrics systems using similar to Graphite’s nonNegativeDerivative should handle that gracefully anyway.

NB: I think this issue also affects Caffeine caches in the same way.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:25 (23 by maintainers)

github_iconTop GitHub Comments

1reaction
ben-manescommented, Jul 3, 2019

LongAccumulator would work, as you can push the saturatedAdd as the accumulation function.

Class {@link LongAdder} provides analogs of the functionality of this class for the common special case of maintaining counts and sums. The call {@code new LongAdder()} is equivalent to {@code new LongAccumulator((x, y) -> x + y, 0L)}.

I think if we consider overflow non-deterministic and only promise to avoid exceptions, then it is not our responsibility to make counts correct. That means either is okay, and better handling is the user’s responsibility by providing an alternative StatsCounter (note - Guava doesn’t allow that currently).

1reaction
lowassercommented, Jul 3, 2019

We could possibly use LongAccumulator with LongMath.saturatedAdd?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to read large amounts of data without contaminating the ...
1 Answer 1 ... The way to do exactly what you want is to use the MOVNTDQA instruction in conjunction with the WC...
Read more >
Buffer Overflow, Caching - Providence - Brown CS
Buffer Overflow, contd. Consider the code in checksummer.cc . This program computes checksums of strings provided to it as command line ...
Read more >
Stack Overflow: How We Do App Caching - 2019 Edition
So…caching. What is it? It's a way to get a quick payoff by not re-calculating or fetching things over and over, resulting in...
Read more >
CacheMetrics (Ignite 2.14.0)
Cache metrics used to obtain statistics on cache itself. Use IgniteCache.metrics() ... Gets count of write buffer overflow events in progress at the...
Read more >
15 Cache Configurations by Example
In-memory Cache with Disk Based Overflow ... Partitioned Cache with Overflow ... External caches are generally used for temporary storage of large data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found