Skip to content

Conversation

@izeye
Copy link
Contributor

@izeye izeye commented Jun 15, 2015

EhCache's hit/miss ratio could be as follows:

  "cache.persons.hit.ratio" : 1.000019269809123,
  "cache.persons.miss.ratio" : -1.9269809123034776E-5,

We usually expect hit/miss ratio between 0 and 1 inclusive, not greater than 1 or negative.

You can reproduce it with ApplicationTests.test() in the following project:

https://github.com/izeye/samples-spring-boot-branches/tree/cache

@snicoll
Copy link
Member

snicoll commented Jun 15, 2015

Meh, why would that value be higher than 1? @lorban

@chrisdennis
Copy link
Contributor

The hitRatio is the ratio of two windowed rates that are calculated independently. They aren't updated or read transactionally, hence the ratio of the two can drift slightly from what might be expected. Does that make sense?

@snicoll
Copy link
Member

snicoll commented Jun 15, 2015

Thanks for the answer. What do you suggest of the proposed PR?

@chrisdennis
Copy link
Contributor

Assuming this is the best layer to sanitize things at (bearing in mind one potential sanitization layer is inside the users brain) then this looks fine. Personally I would have written:

//ratio is calculated 'racily' and can drift marginally above unity, so we cap it here
double hitRatio = Math.max(1.0, ehCacheStatistics.cacheHitRatio());

but that's obviously just personal preferences.

@snicoll snicoll added the type: enhancement A general enhancement label Jun 15, 2015
@snicoll snicoll added this to the 1.3.0.M2 milestone Jun 15, 2015
@snicoll snicoll self-assigned this Jun 15, 2015
@snicoll
Copy link
Member

snicoll commented Jun 16, 2015

well if you do that if the hitRatio is between 0 and 1, it become 1 :)

@snicoll snicoll closed this in 2b9775d Jun 16, 2015
snicoll added a commit that referenced this pull request Jun 16, 2015
* ehcache:
  Polish
  Fix EhCache hit/miss ratio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants