Top Banner
High Performance Redis Tague Griffith
39

HIgh Performance Redis- Tague Griffith, GoPro

Jan 16, 2017

Download

Technology

Redis Labs
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: HIgh Performance Redis- Tague Griffith, GoPro

High Performance RedisTague Griffith

Page 2: HIgh Performance Redis- Tague Griffith, GoPro

DevelopmentqProgrammingqData restructuringqTransactions

High Performance RedisHolistic understanding of some techniques and tricks for building out high performance Redis systems.

Agenda

TechnologyqRedis 2.xqTwemproxyqLinux

OperationsqClusteringqFailoverqOS TuningqRedis Tuning

Page 3: HIgh Performance Redis- Tague Griffith, GoPro

Introductions

Page 4: HIgh Performance Redis- Tague Griffith, GoPro

• Software Architect with GoPro

• 10+ years building distributed systems

• 4+ years building with Redis

• Built multiple high performing Redis apps

• Previously: Apple, Netscape, Flickr

Who Am I

Page 5: HIgh Performance Redis- Tague Griffith, GoPro

Who Are You?

Loki The Wolfdog

Page 6: HIgh Performance Redis- Tague Griffith, GoPro

What is High Performance

Page 7: HIgh Performance Redis- Tague Griffith, GoPro

• Large number of clients

• High transaction rate

• Low response time

• Highly Available

System Features

Page 8: HIgh Performance Redis- Tague Griffith, GoPro

Main Techniques

ü Large number of clientsü High transaction rateü Low response timeü High Availability

ü Low Response time

ü High transaction rateü Low response time

Clustering and Failover

System Tuning

Programming Techniques

Page 9: HIgh Performance Redis- Tague Griffith, GoPro

Clustering

Page 10: HIgh Performance Redis- Tague Griffith, GoPro

• Large number of clients

• High transaction rate

• Low response time

• Pre-requisite to high availability

Features

Page 11: HIgh Performance Redis- Tague Griffith, GoPro

Basic Sharding

ClientClientClientClientClient

Shard-0

Shard-1

Shard-n

• Read/Writessamenode• Uniformworkloads• Keybasedpartitioning

Page 12: HIgh Performance Redis- Tague Griffith, GoPro

• Needs a uniform work load

• Great for single key operations

• Traversals are expensive

• Node loss – roughly 1/N complete outage

• Hot keys are an issue

Trade-offs

Page 13: HIgh Performance Redis- Tague Griffith, GoPro

Read/Write Replicas

ClientClientClientClientClient

WriteMaster

ReadSecondary

ReadSecondary

• Read/Writessplit• HighReadworkloads• DifferentthanFailoverReplicas

Page 14: HIgh Performance Redis- Tague Griffith, GoPro

• Works well for high read workload

• Replication delay

• Lose read your writes consistency

• Node loss - depends on the node

• Easy to scale up hot keys

Trade-offs

Page 15: HIgh Performance Redis- Tague Griffith, GoPro

Duplicate Nodes

ClientClientClientClientWriteClient

Node-0

Node-1

ClientClientClientClientReadClient

Read

Read

1stResult

Page 16: HIgh Performance Redis- Tague Griffith, GoPro

• High performance reads

• Significant client coding

• Consistency goes out the window

• Node loss – depends on your approach

• Double the cost

Trade-offs

Page 17: HIgh Performance Redis- Tague Griffith, GoPro

• Clustering techniques can be combined

• Sharding + R/W Replicas

• Sharding + Multi-Node

• Multi-node is a technique of last resort

Hybrids

Page 18: HIgh Performance Redis- Tague Griffith, GoPro

• Scale horizontally not vertically

• Use multiple Redis instances per host

• R/W replicas or dedicated shards for hot

keys

• Automate deployment and configuration

Scaling Up

Page 19: HIgh Performance Redis- Tague Griffith, GoPro

Happily Ever After

ü LargeNumberofClientsü HighTransactionRateq HighlyAvailableq LowResponseTime

Let’sParty

Page 20: HIgh Performance Redis- Tague Griffith, GoPro

Failover

Page 21: HIgh Performance Redis- Tague Griffith, GoPro

• Twemproxy

• Sentinel

Out of the Box Failover Systems

Page 22: HIgh Performance Redis- Tague Griffith, GoPro

Happily Ever After

ü LargeNumberofClientsü HighTransactionRateü HighlyAvailableq LowResponseTime

Let’sParty

Page 23: HIgh Performance Redis- Tague Griffith, GoPro

System Tuning

Page 24: HIgh Performance Redis- Tague Griffith, GoPro

• Network tuning

• Persistence settings

• Small Aggregate Data settings

Tuning

Page 25: HIgh Performance Redis- Tague Griffith, GoPro

• net.ipv4.ip_local_port_range• net.ipv4.tcp_tw_recycle• net.ipv4.tcp_tw_reuse• net.core.somaxconn

Network Tuning - Linux

Page 26: HIgh Performance Redis- Tague Griffith, GoPro

• tcp-backlog

• tcp-keepalive

Network Tuning - Redis

Page 27: HIgh Performance Redis- Tague Griffith, GoPro

• hash-max-zipmap-entries

• hash-max-zipmap-value

• list-max-ziplist-entries

• list-max-ziplist-value

• zset-max-ziplist-entries

• zset-max-ziplist-value

• set-max-intset-entries

Small Aggregate Data Switches

Page 28: HIgh Performance Redis- Tague Griffith, GoPro

• RDB

• Fork and Save

• AOF

• On “client” thread

• Fsync policy

Persistence

Page 29: HIgh Performance Redis- Tague Griffith, GoPro

Happily Ever After

ü LargeNumberofClientsü HighTransactionRateü HighlyAvailableq LowResponseTime

Let’sParty

Page 30: HIgh Performance Redis- Tague Griffith, GoPro

Programming Techniques

Page 31: HIgh Performance Redis- Tague Griffith, GoPro

• Connection Management

• Transaction Structure

• Data Layout

Key Areas to Consider

Page 32: HIgh Performance Redis- Tague Griffith, GoPro

Persistent Connections• Setup is expensive

• Reduced latency

• Server tuning maybe required

Connection Management

Operation Pipelining• Substantial speedup (ops/s)

• Failure harder to manage

• Client support required

Connection Pooling• Form of persistent

connections

• Reduced latency

• Client support required

Page 33: HIgh Performance Redis- Tague Griffith, GoPro

The structure of your Redis transactions can greatly effect the performance of your app.

Transaction Structure

Smaller• Lower latency• Improved responsiveness• Reduced throughput• Negative impact on AOF

Larger• Higher latency• Reduced responsiveness• Increased throughput• Less impact on AOF

Page 34: HIgh Performance Redis- Tague Griffith, GoPro

Main Techniques

• Smaller Structures faster• Pops off of long lists slow• Internally “shard” data if possible

• replace strings with denser coding (bit vector, map, etc)

• Moderate sized structures

• Reduce size of modifications• Drop keys v. mutating• Reduce impact on AOF

Structured Types

Memory Usage

Isolate Modifications

Page 35: HIgh Performance Redis- Tague Griffith, GoPro

Happily Ever After

ü LargeNumberofClientsü HighTransactionRateü HighlyAvailableü LowResponseTime

Let’sParty

Page 36: HIgh Performance Redis- Tague Griffith, GoPro

Hey,WhataboutMySystem?

Page 37: HIgh Performance Redis- Tague Griffith, GoPro

• Allenvironmentsaredifferent• Unexpectedlatencywillmakeyoucry• Forperformance,scalehorizontally• MonitoringandToolsareEssential• Connectionsareexpensive• RedundancyandFailoverneedstobe

automatic• AOFisafairweatherfriend

Take Aways

Page 38: HIgh Performance Redis- Tague Griffith, GoPro

Questions?

Page 39: HIgh Performance Redis- Tague Griffith, GoPro

Thanks!