Skip to content

Conversation

@marcdumais-work
Copy link
Contributor

@marcdumais-work marcdumais-work commented May 6, 2025

What it does

This toy example was inspired by a real-life investigation, regarding a web-accessible application that had configurable caches, including a specific one whose performance came under scrutiny. That investigation produced some interesting traces, which we aim to approximately replicate with this example.

Related YouTube video:
https://www.youtube.com/watch?v=mSg8EO_FhuQ

Real life investigation - some info about that cache:

type: LRU (least recently used) - when the cache is full, the cache element that was the least recently used is evicted to make space for a new element to be inserted in its place.

configurable cache size: The number of elements it can hold is configurable by the app's admins

cache / cached data usage: The cache is used in a special way. Thought the cache-backed data can be accessed randomly, it's often accessed sequentially, from first element to the last, in order. The app is multi-threaded and often multiple reader threads would be reading the data through the cache, in parallel.

The app provides cache statistics, which seemed quite good (a high cache "hit" rate was reported).

Investigation:
The cache was configured to be slightly under-sized vs the data it was caching, which size (number of elements) was slowly but surely increasing. Given the good reported cache stats, was it an issue that it was a bit undersized (by ~15%)? Was the cache, as configured, potentially affecting performance?

Tracing to the rescue!
The cache and reader thread code were instrumented. From the generated traces, it was possible to distinguish cache hits vs misses. Capturing traces for a few scenarios, some surprising details started to emerge!

See the example's README for more details.

How to test

Follow the instructions in the example's README - try to visualize some of the captured traces. Comments welcome!

$ cd lrucacheexample
# Optionally edit pom.xml to change the simulation's parameters
$ mvn compile exec:exec
$ ../jsonify.py traces/trace.log traces/trace-cache.json
# Open `traces/trace-cache.json` in Trace Compass or using the `Trace Viewer for VSCode` extension

Here is what the generated traces look-like in Trace Compass:

  1. Cache big enough to contain all elements:
    Screenshot from 2025-05-07 08-55-20

  2. Cache slightly undersized (fits 95% of elements):
    Screenshot from 2025-05-07 08-55-33

Follow-ups

N/A

Review checklist

  • As an author, I have thoroughly tested my changes and carefully followed the instructions in this template

@marcdumais-work marcdumais-work force-pushed the lru-cache-example branch 17 times, most recently from ab3bddd to 31b7bee Compare May 8, 2025 18:18
@marcdumais-work marcdumais-work changed the title [example] Add Instrumented LRU cache example [example] Add Instrumented Loading LRU cache example May 9, 2025
@marcdumais-work marcdumais-work force-pushed the lru-cache-example branch 11 times, most recently from 578c452 to b3b2fb4 Compare May 13, 2025 19:31
@marcdumais-work marcdumais-work marked this pull request as ready for review May 14, 2025 17:20
@marcdumais-work marcdumais-work force-pushed the lru-cache-example branch 2 times, most recently from a54961a to 9e3dad2 Compare May 14, 2025 18:02
Copy link
Contributor

@bhufmann bhufmann left a comment

Choose a reason for hiding this comment

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

Would it be interesting to have some screenshots of the traces and show them in the readme? Interested people might not want to run it, but would like to see the results?


#### Leads

- How to explain the disproportional decrase in performance between the fully sized caches vs 95% sized results? It's a ~12x factor!
Copy link
Contributor

Choose a reason for hiding this comment

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

decase -> decrease

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -0,0 +1,96 @@
package org.eclipse.tracecompass.traceeventlogger.lrucachedemo;
Copy link
Contributor

Choose a reason for hiding this comment

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

should it have a copyright header

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -0,0 +1,249 @@
package org.eclipse.tracecompass.traceeventlogger.lrucachedemo;
Copy link
Contributor

Choose a reason for hiding this comment

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

should it have a copyright header

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -0,0 +1,240 @@
package org.eclipse.tracecompass.traceeventlogger.lrucachedemo;
Copy link
Contributor

Choose a reason for hiding this comment

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

should it have a copyright header?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@marcdumais-work marcdumais-work force-pushed the lru-cache-example branch 3 times, most recently from c47ee9e to bbb321b Compare May 14, 2025 19:09
Copy link
Contributor

@bhufmann bhufmann left a comment

Choose a reason for hiding this comment

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

I think the lrucacheexample should be under a folder with name examples. Then we can add other examples when we have them.

@marcdumais-work
Copy link
Contributor Author

I think the lrucacheexample should be under a folder with name examples. Then we can add other examples when we have them.

Done - will push new version momentarily

@marcdumais-work marcdumais-work force-pushed the lru-cache-example branch 4 times, most recently from c96774e to 246a4e4 Compare May 15, 2025 15:00
This toy example was inspired by a real-life investigation,
regarding a web-accessible application that had configurable
caches, including a specific one whose performance came under
scrutiny. That investigation produces some interesting traces,
which we aim to approximately replicate with this example.

Real life investigation - some info about that cache:

type: LRU (least recently used) - when the cache is full, the
cache element that was the least recently used is evicted to
make space for a new element to be inserted in its place.

configurable cache size: The number of elements it can hold
is configurable by the app's admins

cache / cached data usage: The cache is used in a special way.
Thought the cache-backed data can be accessed randomly, it's
often accessed sequentially, from first element to the last, in
order. The app is multi-threaded and often multiple reader
threads would be reading the data through the cache, in parallel.

The app provides cache statistics, which seemed quite good
(a high cache "hit" rate was reported).

Investigation:
The cache was configured to be slightly under-sized vs the
data it was caching, which size (number of elements) was
slowly but surely increasing. Given the good reported cache
stats, was it an issue that it was a bit undersized (by ~15%)?
Was the cache, as configured, potentially affecting performance?

Tracing to the rescue!
The cache and reader thread code were instrumented. From the
generated traces, it was possible to distinguish cache hits
vs misses. Capturing traces for a few scenarios, some surprising
details started to emerge!

See the example's README for more details.

Signed-off-by: Marc Dumais <marc.dumais@ericsson.com>
Copy link
Contributor

@bhufmann bhufmann left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks!

@MatthewKhouzam MatthewKhouzam merged commit c10569f into eclipse-tracecompass:main May 16, 2025
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants