Performance Tuning
Redis performance tuning starts with pipelining, connection pooling, right-sized values, and eliminating slow commands — not buying bigger hardware first.
Introduction
Redis performance tuning starts with pipelining, connection pooling, right-sized values, and eliminating slow commands — not buying bigger hardware first. Default configs target dev laptops; production needs lazyfree, UNLINK, disabled THP, and co-located AZ placement.
Profile with redis-benchmark only as sanity check — real workloads need application-level tracing with realistic value sizes and concurrent clients.
Target p99 latency not average — one KEYS command spikes p99 for everyone.
Understanding the topic
Key concepts
- Pipelining — batch RTT.
- Connection pool max-active sizing.
- UNLINK async delete vs blocking DEL.
- lazyfree-lazy-user-del large key free.
- Disable transparent huge pages Linux.
- I/O threads help read/write not command CPU.
Step-by-step explanation
- Measure baseline ops/sec and p99 latency.
- Identify RTT-bound vs CPU-bound paths.
- Apply pipeline/MGET to RTT issues.
- Replace DEL with UNLINK on big keys.
- Tune pool and co-locate network.
- Re-measure under load test.
Syntax reference
Common commands
- UNLINK non-blocking delete large keys.
- activedefrag when mem_fragmentation_ratio high.
- LATENCY DOCTOR first tuning step.
CONFIG SET lazyfree-lazy-user-del yesCONFIG SET activedefrag yesUNLINK big:hash:keyINFO stats | grep instantaneous_opsLATENCY DOCTOR
Informative example
Enable lazy free and measure before/after large hash delete:
redis-cli CONFIG SET lazyfree-lazy-user-del yesredis-cli DEBUG SLEEP 0# Before: time redis-cli DEL huge:hash# After: time redis-cli UNLINK huge:hashredis-cli INFO stats | grep lazyfree_pending_objects
Spring: configure Lettuce pool max-active ~2× expected concurrent Redis users per pod.
Real-world use
Real-world use cases
- API p99 SLA breach on cache layer.
- Bulk delete migration without latency spike.
- Flash traffic event capacity planning.
- Reduce ElastiCache node size after optimization.
- Post-deploy regression detection.
Best practices
- Pipeline all batch read paths.
- Pool size from concurrency not guess.
- UNLINK not DEL for >1KB aggregates.
- Same AZ app and Redis.
- Disable THP; set overcommit_memory.
- Alert on slowlog growth.
Common mistakes
- Benchmark only SET GET 10 byte locally.
- Pool max-active=1 on high traffic pod.
- DEL million-field hash at peak.
- More Redis CPU without fixing hot key.
Advanced interview questions
Interview Prep
Practice concise answers, then expand each card for the explanation.
1BeginnerQuestionFirst Redis perf optimization?+
Answer
2BeginnerQuestionUNLINK vs DEL?+
Answer
3IntermediateQuestionlazyfree purpose?+
Answer
4IntermediateQuestionWhy disable THP?+
Answer
5AdvancedQuestionTune Spring Lettuce pool?+
Answer
Summary
Pipeline and pool sizing — first wins.