Caching Workshop
What
Organise a workshop for GitLab team members to discuss caching techniques and implementations in the context of the GitLab Rails application.
Who
Presenter
Me
Attendees
- Anyone who can attend live - I'm not opposed to running it in multiple timezones
- Recordings for viewing later on and for people outside of GitLab
When
Friday 4th of June
Session events
- Session 1 recording, 2-3pm GMT
- Session 2, 4-5:30pm GMT
Session 1
Slide Deck
Recordings
Session 2
Q&A/Suggestions Issue
Recordings
Content
Background information and setup
- Why use caching?
- A little of my background in caching
- Include some old slides and repositories
- Setting your environment up for caching
- Enable caching in development with
rake dev:cache
- Testing caches and our test helpers for caching
- Enable caching in development with
- Why we, and pretty much everyone, use Redis-pretending-to-be-memcached rather than memcached itself, and a few pros/cons of this
Caching methodology
- Cache levels
- Probably not official names but how I think of them:
- High-level caching
- HTTP caching
- HTTP caching in a reverse proxy cache
- HTML page caching
- View caching
- Fragment caching
- Low-level caching
- Method caching
- Request caching
- Read-through/write-through SQL caching
- Novelty caches for specific use-cases
- High-level caching
- Probably not official names but how I think of them:
- Rails' built-in caching helpers
- How memcached/Redis expire keys
- How Rails expires keys
- Explicit deletes vs cache key rotation vs TTL (Time to Live)
- Existing GitLab-specific low-level caches
- Repository method caches and the stores behind them
- Request caching
- Use gitlab!55184 (diffs) as an example of using
RequestStore
- Use gitlab!55184 (diffs) as an example of using
Caching "gotchas"
- Common problems
- What to look for when adding new caching
- How it can go slightly wrong (stale data)
- How it can go very wrong (showing user-specific data to someone else)
View-level caching (main focus)
- Benefits of view-level caching
- Use examples from previous applications I've built if possible
- Existing examples from GitLab
- Performance issues with Rails templates
- Difficulties associated with view-level caching
- Multiple caches and network latency
- Touch on the workarounds for this
- Cache keys
- Cache expiry
- User-specific data
- GitLab-specific issues
- Lack of
cache_key
rotation - Lots of user-specific data
- Ownership of the view layer
- Lack of
- Multiple caches and network latency
- Why ERB is oddly easier to cache than HAML
- Hacks and unusual techniques
- multi-fetching
- chunky_cache
- Adding awkward stuff to cache keys
- Using JavaScript to get around limitations
Case studies
- Look at a known endpoint where caching has improved it
- Analyse why it was effective
- Explain techniques used
- Crowd-source an endpoint or view to investigate live on the workshop (live coding
🙀 )- Might take a couple of attempts to find something with viable improvements
- Attempt to put together a draft MR that improves the view rendering
Materials
- Slides for explaining background info and existing implementations
- Example merge requests
- Other example projects
- Previous materials from performance workshops at GitLab (internal only)
- Issue to collect suggestions for endpoints from attendees
- Recordings of live sessions for later reference or for those who can't attend
- Handbook page (?) with links to the resources
- Links to cool libraries that I find useful
- identity_cache
- multi_fetch_fragments (interesting even though the functionality was merged into Rails)
- redis-objects
- chunky_cache (my own library that solves a specific problem, will probably touch on it in the workshop to explain why it exists)
- Links to other presentations/slides
Edited by Sean Carroll