SlideShare ist ein Scribd-Unternehmen logo
1 von 45
Downloaden Sie, um offline zu lesen
REDIS
EVERYWHERE
HELLO WORLD
• Ricard

Clau, born and grown up in Barcelona

• Software

engineer at Hailo in London

• Symfony2

lover and PHP believer

• Open-source
• Twitter

contributor, sometimes I give talks

@ricardclau / Gmail ricard.clau@gmail.com
WHAT IS REDIS?
• REmote
• Created
• Open

DIctionary Server

in 2009 by Salvatore Sanfilipo (@antirez)

source

• Advanced

in-memory key-value data-structure server

• Part

of the NoSQL movement

• Stop

thinking SQL, think back to structures!
TO ME REDIS IS LIKE...
REDIS EVERYWHERE?
Redis is not a silver bullet... so let´s rephrase that with...
The amazing story on how we gradually introduced Redis
in a social videogaming company... and it saved us!
AGENDA
• REDIS

introduction

• Getting

started with PHP / Symfony2: sessions, caching

• Recipes

and comparison with other technologies

• Sharding

data. And some criticism!

• War

Stories from a 7.5M DAU project

• Final

thoughts
INTRODUCTION TO REDIS
And some demystifications
DATA TYPES
• Strings
• Lists

up to 512 Mb

of elements sorted by insertion order (max 2^32 - 1)

• Sets

unordered collection of elements supporting unions,
intersections and differences (max 2^32 - 1)

• Hashes

key-value pairs (max 2^32 - 1)

• Sorted

sets automatically ordered by score (max 2^32 - 1)
ONLY IN-MEMORY?
• Your

data needs to fit in your memory

has configurable persistence: RDB snapshots, AOF
persistence logs, combine both or no persistence at all

• It

• Think

like memcached on steroids with persistence

• http://redis.io/topics/persistence
• “Memory

is the new disk, disk is the new tape”
INTERESTING FEATURES
• Master-slave
• Pipelining

replication
to improve performance

• Transactions
• Publisher
• Scripting

(kind of with MULTI ... EXEC)

/ Subscriber

with LUA (~stored procedures)

• Predictable

performance (check commands complexity)
HARDWARE TIPS
is single-threaded, so a 2 core machine is enough

• Redis

using EC2, maybe m1.large (7.5Gb) is the most suitable,
but if it is not enough you might consider any m2 memory
optimized type

• If

• Amazon
• CPU
• Read

ElastiCache finally supports Redis!

is rarely the bottleneck with Redis

carefully the doc to maximize performance!
NEW IN REDIS 2.8
• CONFIG

REWRITE and IPv6 support

• Improvements

in scripting and key expiring algorithm

• Keyspace

notifications via PUB / SUB. (~Triggered events)

• Partial

resynchronization with slaves

• Better
•A

consistency support (allow writes only when N slaves)

fully rewritten Redis Sentinel
ALSO IN 2.8 (H|Z|S)?SCAN
• Ability

to iterate the data structures

• SCAN

cursor [MATCH pattern] [COUNT count]

• (H|Z|S)SCAN
• Cursor
• Count
• When

key cursor [MATCH pattern] [COUNT count]

is kind of a pointer that we send back and forth

is NOT the number of elements but the complexity

using MATCH some steps in iteration may return nil
GETTING STARTED WITH PHP
It is easier than you may think!
PHP CLIENTS
• Predis

(PHP) vs phpredis (PHP extension)

• Predis

is very mature, actively maintained, feature complete,
extendable, composer friendly and supports all Redis versions

• Phpredis

is faster, but not backwards compatible

• Network

latency is the biggest performance killer

• http://redis.io/clients
REDIS-CLI AND MONITOR
• Redis-cli

to connect to a Redis instance

• Experiment

with http://redis.io/commands

• With

Monitor we can watch live activity!
SESSIONS, CACHING
• Super-easy

to implement with commercial frameworks

used: GET <session-id>, SETEX <session-id>
<expires> <serialized-data>

• Commands

• Fast

performance and also persistent!

• Caching
• Be

and temp-data storage work exactly equal

careful with temp-data storage and memory usage!
SYMFONY2 INTEGRATION
• There

must be a bundle for that...

• https://github.com/snc/SncRedisBundle

of the box: Session management, Monolog handler,
Swiftmailer spooling, Doctrine caching

• Out

• Full

integration with Symfony2 profiler
REDIS EVERYWHERE!
COOKBOOK
And comparisons with other technologies
REDIS AS A QUEUE
• Using
• We

Lists and LPUSH / RPOP instructions

can have different languages accessing data

used that to send OpenGraph requests to Facebook
(REALLY slow API) with Python daemons

• We

• ~80k
• If

messages/minute processed with 1 m1.large EC2

you need some advanced message queuing features check
RabbitMQ (and Álvaro Videla´s talk) and others
REAL-TIME ANALYTICS
• We

can use hashes to group many stats under one key

• Most

of the times we have counters:
HINCRBY “stats" <key> <increment>

• HMGET “stats” <key1>

<key2> ... to retrieve values and
HMSET “stats” “stat1” <value1> “stat2” <value2> to set them

• HGETALL

to get the full hash
LEADERBOARDS
• Super-easy
• Each

with Redis, heavy consuming with other systems

board with a single key, using sorted sets

• ZINCRBY “rankXXX” <increment>

<userId>

• Top

N ZREVRANGE “rankXXX” 0 N [WITHSCORES]

• We

stored several milions of members under 1 key
WHO IS ONLINE? (I)
can use SETS to achieve it!

• We

• One

set for every minute, SADD <minute> <userId>

Time

+1m

5

+2m

2

+3m
1

4

2

1

5
4

1
3

SUNION

1

7

3
1

2

3
7

2
WHO IS ONLINE? (II)
• Online

users == everyone active in the last N minutes

• SUNION

<now> <now-1> <now-2> ...

• SUNIONSTORE “online” <now>
• Number
• Obtain

<now-1> <now-2> ...

of users: SCARD “online”

online users with SMEMBERS “online”
FRIENDS ONLINE?
• If

we store user´s friends in a SET with key friends-<user-id>

online: SINTERSTORE “friends-<userid>-online”
“online” “friends-<userid>”
10

4
2

1
3
7

SINTER

ONLINE

5
1

9
3

7

15

FRIENDS-12-ONLINE

• Imagine

how you would do it without Redis!

FRIENDS-12

• Friends
DISTRIBUTED LOCKING (I)
• Problem

in heavy-write applications: 2 almost concurrent
requests trying to update same records

• SELECT

FOR UPDATE? Easy to create deadlocks!
R1read

R1 updates
are lost!!!!!

R2read

timeline
R1

R2

R1save

R2save
DISTRIBUTED LOCKING (II)
• Locking
• SET
• And
•8

can be solved with Redis with Exclusive SET

<lock> 1 NX EX <seconds>

keep retrying until a specific timeout

m1.xlarge instances to lock 7.5M Daily Active Users

Zookeeper, perhaps better for scaling
or if we need different locking patterns

• Alternatives: Apache
SHARDING DATA
Hopefully, you get there at some point
Resharding: a painful experience
NEEDS TO FIT IN MEMORY
• Redis
• Proxy

Cluster will be available in 3.0 (delayed many times)

servers: Twemproxy (also for memcached)

• Client-side
• Sharding

partitioning (supported in many clients)

strategies (range vs hash partitioning)

• Presharding
• Memory

can help scaling horizontally

is cheaper every day but this is a real need!
100000-199999

id % 4 == 0

id % 4 == 1

200000-299999 300000-399999

id % 4 == 2

id % 4 == 3

1-99999

Easy to predict scale
Load not properly distributed

Load distributed ok
Fairly easy to reshard

RANGE PARTITIONING
May work in some cases, not a silver bullet
HASH
hash(key) % 4 == 0

hash(key) % 4 == 1

CRC16
CRC32
MD5
SHA1
MURMUR3

DIST
hash(key) % 4 == 2

hash(key) % 4 == 3

MODULUS
KETAMA

Distribution also depending on hash algorithm
Complicated resharding

HASH PARTITIONING
Better distribution... but still issues
If few keys, it also becomes useless
Many Redis instances in one
initial server
When needed, just split it
into more servers and you
don´t need resharding!!!
Be careful configuring
memory limits

PRESHARDING
Maybe overengineered
CRITICISM IN THE NET
Sometimes unfair... sometimes they have a point
VS OTHER DATABASES
• Cassandra

or RIAK reshard automatically (at a big cost)

• Complicated

to fully automate failovers (Sentinel problems)

• Severe
• Tricky

• All

issues when slaves get out of sync, getting better

to inspect big sets and hashes prior to 2.8

NoSQL have issues, check aphyr.com “Call me maybe”
ABOUT REDIS CLUSTER
• CAP Theorem: Consistency, Availability, Partition
• Purists
• CAP

tolerance

blame it to not properly respect the principles

theorem is... a theorem and it comes with a cost

• The

goal is to provide some consistency and some failure
resistance without sacrificing other practical qualities

• We

could debate for hours around that point!
WAR STORIES
https://apps.facebook.com/dragoncity/
(~7.5M DAU Facebook Game)
PROGRESSIVE USAGE
• DragonCity
• First

had ~2M DAU when we introduced Redis

usages: Queues PHP-Python and Temporary storage

• Introduced
• Used

Locking with Redis -> End of deadlocks

for temporary contests involving rankings

• Session
• About

tracking, cheat detection and many others

7.5M DAU and similar amount of servers
REDIS IS SUPER-FAST
• Your

network gets killed much before Redis is down

• Always

increase your ulimit values in Redis servers

• We

had Gigabit network connectivity between machines but
it was not enough to handle the data sent and retrieved

• Redis
• Do

was just at 20% of CPU

some heavy-load tests before launching!
SURPRISES WITH MEMORY
documentation: “Sets of binary-safe strings”so,
we changed values in sets from being just numbers to number
+ :<char> to add some info to values

• Redis

• We

expected ~20% memory increase but in was 500%

• https://github.com/antirez/redis/blob/unstable/src/t_set.c#L55
• If

value can be represented as long, it is stored more efficiently

• http://alonso-vidales.blogspot.co.uk/2013/06/not-all-redis-

values-are-strings.html
FINAL THOUGHTS
When and when not to consider Redis
REDIS IS PERFECT FOR...
• Intensive

read-write data applications

• Temporary
• Data

stored data

that fits in memory

• Problems

that fit Redis built-in data types

• Predictability

in performance needed (all commands
complexity documented)
BUT IS NOT SUITABLE WHEN..
• Big

data sets, archive data

• Relational
• We

data (RDBMS are absolutely fine to scale)

don´t know how we will access data

• Reporting
• It

applications (no where clauses)

gets tricky for distributed applications (replication, clustering)

• ALWAYS

choose the right tool for the job!
SPECIAL THANKS
• Ronny

López (@ronnylt) & Alonso Vidales (@alonsovidales)

• All

backend and systems engineers at @socialpoint

• Of

course, to all of you for being here today!

our open-source project Redtrine, PR welcome:
https://github.com/redtrine/redtrine

• Check
QUESTIONS?
• Twitter:

@ricardclau

• E-mail:

ricard.clau@gmail.com

• Github:

https://github.com/ricardclau

• Blog

about PHP and Symfony2: http://www.ricardclau.com

• Please, rate

this talk at https://joind.in/talk/view/10531

Weitere ähnliche Inhalte

Was ist angesagt?

Scaling High Traffic Web Applications
Scaling High Traffic Web ApplicationsScaling High Traffic Web Applications
Scaling High Traffic Web ApplicationsAchievers Tech
 
High Availability Perl DBI + MySQL
High Availability Perl DBI + MySQLHigh Availability Perl DBI + MySQL
High Availability Perl DBI + MySQLSteve Purkis
 
Innovating faster with SBT, Continuous Delivery, and LXC
Innovating faster with SBT, Continuous Delivery, and LXCInnovating faster with SBT, Continuous Delivery, and LXC
Innovating faster with SBT, Continuous Delivery, and LXCkscaldef
 
MHA: Getting started & moving past quirks percona live santa clara 2013
MHA: Getting started & moving past quirks percona live santa clara 2013MHA: Getting started & moving past quirks percona live santa clara 2013
MHA: Getting started & moving past quirks percona live santa clara 2013Colin Charles
 
Profiling and Tuning a Web Application - The Dirty Details
Profiling and Tuning a Web Application - The Dirty DetailsProfiling and Tuning a Web Application - The Dirty Details
Profiling and Tuning a Web Application - The Dirty DetailsAchievers Tech
 
Performance Benchmarking: Tips, Tricks, and Lessons Learned
Performance Benchmarking: Tips, Tricks, and Lessons LearnedPerformance Benchmarking: Tips, Tricks, and Lessons Learned
Performance Benchmarking: Tips, Tricks, and Lessons LearnedTim Callaghan
 
Handling 1 Billion Requests/hr with Minimal Latency Using Docker
Handling 1 Billion Requests/hr with Minimal Latency Using DockerHandling 1 Billion Requests/hr with Minimal Latency Using Docker
Handling 1 Billion Requests/hr with Minimal Latency Using DockerMatomy
 
Scalable and Available, Patterns for Success
Scalable and Available, Patterns for SuccessScalable and Available, Patterns for Success
Scalable and Available, Patterns for SuccessDerek Collison
 
The Wix Microservice Stack
The Wix Microservice StackThe Wix Microservice Stack
The Wix Microservice StackTomer Gabel
 
Thousands of Threads and Blocking I/O
Thousands of Threads and Blocking I/OThousands of Threads and Blocking I/O
Thousands of Threads and Blocking I/OGeorge Cao
 
MySQL in the Hosted Cloud - Percona Live 2015
MySQL in the Hosted Cloud - Percona Live 2015MySQL in the Hosted Cloud - Percona Live 2015
MySQL in the Hosted Cloud - Percona Live 2015Colin Charles
 
GoSF Summerfest - Why Go at Apcera
GoSF Summerfest - Why Go at ApceraGoSF Summerfest - Why Go at Apcera
GoSF Summerfest - Why Go at ApceraDerek Collison
 
Bootstrapping Using Free Software
Bootstrapping Using Free SoftwareBootstrapping Using Free Software
Bootstrapping Using Free SoftwareColin Charles
 
Real-world Experiences in Scala
Real-world Experiences in ScalaReal-world Experiences in Scala
Real-world Experiences in ScalaAmir Karimi
 
ActiveMQ 5.9.x new features
ActiveMQ 5.9.x new featuresActiveMQ 5.9.x new features
ActiveMQ 5.9.x new featuresChristian Posta
 
Cassandra Summit 2014: Deploying Cassandra for Call of Duty
Cassandra Summit 2014: Deploying Cassandra for Call of DutyCassandra Summit 2014: Deploying Cassandra for Call of Duty
Cassandra Summit 2014: Deploying Cassandra for Call of DutyDataStax Academy
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsJonas Bonér
 
High Performance Systems in Go - GopherCon 2014
High Performance Systems in Go - GopherCon 2014High Performance Systems in Go - GopherCon 2014
High Performance Systems in Go - GopherCon 2014Derek Collison
 

Was ist angesagt? (20)

Scaling High Traffic Web Applications
Scaling High Traffic Web ApplicationsScaling High Traffic Web Applications
Scaling High Traffic Web Applications
 
High Availability Perl DBI + MySQL
High Availability Perl DBI + MySQLHigh Availability Perl DBI + MySQL
High Availability Perl DBI + MySQL
 
Innovating faster with SBT, Continuous Delivery, and LXC
Innovating faster with SBT, Continuous Delivery, and LXCInnovating faster with SBT, Continuous Delivery, and LXC
Innovating faster with SBT, Continuous Delivery, and LXC
 
MHA: Getting started & moving past quirks percona live santa clara 2013
MHA: Getting started & moving past quirks percona live santa clara 2013MHA: Getting started & moving past quirks percona live santa clara 2013
MHA: Getting started & moving past quirks percona live santa clara 2013
 
Profiling and Tuning a Web Application - The Dirty Details
Profiling and Tuning a Web Application - The Dirty DetailsProfiling and Tuning a Web Application - The Dirty Details
Profiling and Tuning a Web Application - The Dirty Details
 
Performance Benchmarking: Tips, Tricks, and Lessons Learned
Performance Benchmarking: Tips, Tricks, and Lessons LearnedPerformance Benchmarking: Tips, Tricks, and Lessons Learned
Performance Benchmarking: Tips, Tricks, and Lessons Learned
 
Handling 1 Billion Requests/hr with Minimal Latency Using Docker
Handling 1 Billion Requests/hr with Minimal Latency Using DockerHandling 1 Billion Requests/hr with Minimal Latency Using Docker
Handling 1 Billion Requests/hr with Minimal Latency Using Docker
 
Scalable and Available, Patterns for Success
Scalable and Available, Patterns for SuccessScalable and Available, Patterns for Success
Scalable and Available, Patterns for Success
 
The Wix Microservice Stack
The Wix Microservice StackThe Wix Microservice Stack
The Wix Microservice Stack
 
Thousands of Threads and Blocking I/O
Thousands of Threads and Blocking I/OThousands of Threads and Blocking I/O
Thousands of Threads and Blocking I/O
 
MySQL in the Hosted Cloud - Percona Live 2015
MySQL in the Hosted Cloud - Percona Live 2015MySQL in the Hosted Cloud - Percona Live 2015
MySQL in the Hosted Cloud - Percona Live 2015
 
GoSF Summerfest - Why Go at Apcera
GoSF Summerfest - Why Go at ApceraGoSF Summerfest - Why Go at Apcera
GoSF Summerfest - Why Go at Apcera
 
Bootstrapping Using Free Software
Bootstrapping Using Free SoftwareBootstrapping Using Free Software
Bootstrapping Using Free Software
 
Stackato v2
Stackato v2Stackato v2
Stackato v2
 
Real-world Experiences in Scala
Real-world Experiences in ScalaReal-world Experiences in Scala
Real-world Experiences in Scala
 
ActiveMQ 5.9.x new features
ActiveMQ 5.9.x new featuresActiveMQ 5.9.x new features
ActiveMQ 5.9.x new features
 
Cassandra Summit 2014: Deploying Cassandra for Call of Duty
Cassandra Summit 2014: Deploying Cassandra for Call of DutyCassandra Summit 2014: Deploying Cassandra for Call of Duty
Cassandra Summit 2014: Deploying Cassandra for Call of Duty
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability Patterns
 
Be faster then rabbits
Be faster then rabbitsBe faster then rabbits
Be faster then rabbits
 
High Performance Systems in Go - GopherCon 2014
High Performance Systems in Go - GopherCon 2014High Performance Systems in Go - GopherCon 2014
High Performance Systems in Go - GopherCon 2014
 

Andere mochten auch

Redis everywhere - PHP London
Redis everywhere - PHP LondonRedis everywhere - PHP London
Redis everywhere - PHP LondonRicard Clau
 
Slide Seminar PHP Indonesia - NoSQL Redis
Slide Seminar PHP Indonesia - NoSQL RedisSlide Seminar PHP Indonesia - NoSQL Redis
Slide Seminar PHP Indonesia - NoSQL Redisrifqi alfian
 
MySQL & NoSQL from a PHP Perspective
MySQL & NoSQL from a PHP PerspectiveMySQL & NoSQL from a PHP Perspective
MySQL & NoSQL from a PHP PerspectiveTim Juravich
 
Redis in Practice: Scenarios, Performance and Practice with PHP
Redis in Practice: Scenarios, Performance and Practice with PHPRedis in Practice: Scenarios, Performance and Practice with PHP
Redis in Practice: Scenarios, Performance and Practice with PHPChen Huang
 
Beyond relational database - Building high performance websites using Redis a...
Beyond relational database - Building high performance websites using Redis a...Beyond relational database - Building high performance websites using Redis a...
Beyond relational database - Building high performance websites using Redis a...Dinh Pham
 
MOSC2012 - Building High-Performance Web-Application with PHP & MongoDB
MOSC2012 - Building High-Performance Web-Application with PHP & MongoDBMOSC2012 - Building High-Performance Web-Application with PHP & MongoDB
MOSC2012 - Building High-Performance Web-Application with PHP & MongoDBr1dotmy
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redisjimbojsb
 
Scaling PHP to 40 Million Uniques
Scaling PHP to 40 Million UniquesScaling PHP to 40 Million Uniques
Scaling PHP to 40 Million UniquesJonathan Klein
 
PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016
PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016
PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016Alexandre Brandão Lustosa
 
Speed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with RedisSpeed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with RedisRicard Clau
 

Andere mochten auch (10)

Redis everywhere - PHP London
Redis everywhere - PHP LondonRedis everywhere - PHP London
Redis everywhere - PHP London
 
Slide Seminar PHP Indonesia - NoSQL Redis
Slide Seminar PHP Indonesia - NoSQL RedisSlide Seminar PHP Indonesia - NoSQL Redis
Slide Seminar PHP Indonesia - NoSQL Redis
 
MySQL & NoSQL from a PHP Perspective
MySQL & NoSQL from a PHP PerspectiveMySQL & NoSQL from a PHP Perspective
MySQL & NoSQL from a PHP Perspective
 
Redis in Practice: Scenarios, Performance and Practice with PHP
Redis in Practice: Scenarios, Performance and Practice with PHPRedis in Practice: Scenarios, Performance and Practice with PHP
Redis in Practice: Scenarios, Performance and Practice with PHP
 
Beyond relational database - Building high performance websites using Redis a...
Beyond relational database - Building high performance websites using Redis a...Beyond relational database - Building high performance websites using Redis a...
Beyond relational database - Building high performance websites using Redis a...
 
MOSC2012 - Building High-Performance Web-Application with PHP & MongoDB
MOSC2012 - Building High-Performance Web-Application with PHP & MongoDBMOSC2012 - Building High-Performance Web-Application with PHP & MongoDB
MOSC2012 - Building High-Performance Web-Application with PHP & MongoDB
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redis
 
Scaling PHP to 40 Million Uniques
Scaling PHP to 40 Million UniquesScaling PHP to 40 Million Uniques
Scaling PHP to 40 Million Uniques
 
PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016
PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016
PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016
 
Speed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with RedisSpeed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with Redis
 

Ähnlich wie Redis Everywhere - Sunshine PHP

Big Data Developers Moscow Meetup 1 - sql on hadoop
Big Data Developers Moscow Meetup 1  - sql on hadoopBig Data Developers Moscow Meetup 1  - sql on hadoop
Big Data Developers Moscow Meetup 1 - sql on hadoopbddmoscow
 
Redis - The Universal NoSQL Tool
Redis - The Universal NoSQL ToolRedis - The Universal NoSQL Tool
Redis - The Universal NoSQL ToolEberhard Wolff
 
What's new with enterprise Redis - Leena Joshi, Redis Labs
What's new with enterprise Redis - Leena Joshi, Redis LabsWhat's new with enterprise Redis - Leena Joshi, Redis Labs
What's new with enterprise Redis - Leena Joshi, Redis LabsRedis Labs
 
New York REDIS Meetup Welcome Session
New York REDIS Meetup Welcome SessionNew York REDIS Meetup Welcome Session
New York REDIS Meetup Welcome SessionAleksandr Yampolskiy
 
NoSQL for great good [hanoi.rb talk]
NoSQL for great good [hanoi.rb talk]NoSQL for great good [hanoi.rb talk]
NoSQL for great good [hanoi.rb talk]Huy Do
 
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNAFirst Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNATomas Cervenka
 
MySQL in the Hosted Cloud
MySQL in the Hosted CloudMySQL in the Hosted Cloud
MySQL in the Hosted CloudColin Charles
 
Quick-and-Easy Deployment of a Ceph Storage Cluster
Quick-and-Easy Deployment of a Ceph Storage ClusterQuick-and-Easy Deployment of a Ceph Storage Cluster
Quick-and-Easy Deployment of a Ceph Storage ClusterPatrick Quairoli
 
Technologies for Data Analytics Platform
Technologies for Data Analytics PlatformTechnologies for Data Analytics Platform
Technologies for Data Analytics PlatformN Masahiro
 
Databases in the hosted cloud
Databases in the hosted cloudDatabases in the hosted cloud
Databases in the hosted cloudColin Charles
 
Apache Thrift, a brief introduction
Apache Thrift, a brief introductionApache Thrift, a brief introduction
Apache Thrift, a brief introductionRandy Abernethy
 
AWS Webcast - Backup & Restore for ElastiCache/Redis: Getting Started & Best ...
AWS Webcast - Backup & Restore for ElastiCache/Redis: Getting Started & Best ...AWS Webcast - Backup & Restore for ElastiCache/Redis: Getting Started & Best ...
AWS Webcast - Backup & Restore for ElastiCache/Redis: Getting Started & Best ...Amazon Web Services
 
Fixing twitter
Fixing twitterFixing twitter
Fixing twitterRoger Xia
 
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...smallerror
 
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...xlight
 

Ähnlich wie Redis Everywhere - Sunshine PHP (20)

Big Data Developers Moscow Meetup 1 - sql on hadoop
Big Data Developers Moscow Meetup 1  - sql on hadoopBig Data Developers Moscow Meetup 1  - sql on hadoop
Big Data Developers Moscow Meetup 1 - sql on hadoop
 
Redis - The Universal NoSQL Tool
Redis - The Universal NoSQL ToolRedis - The Universal NoSQL Tool
Redis - The Universal NoSQL Tool
 
What's new with enterprise Redis - Leena Joshi, Redis Labs
What's new with enterprise Redis - Leena Joshi, Redis LabsWhat's new with enterprise Redis - Leena Joshi, Redis Labs
What's new with enterprise Redis - Leena Joshi, Redis Labs
 
New York REDIS Meetup Welcome Session
New York REDIS Meetup Welcome SessionNew York REDIS Meetup Welcome Session
New York REDIS Meetup Welcome Session
 
Scaling tappsi
Scaling tappsiScaling tappsi
Scaling tappsi
 
NoSQL for great good [hanoi.rb talk]
NoSQL for great good [hanoi.rb talk]NoSQL for great good [hanoi.rb talk]
NoSQL for great good [hanoi.rb talk]
 
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNAFirst Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
 
Redis in 20 minutes
Redis in 20 minutesRedis in 20 minutes
Redis in 20 minutes
 
Why ruby and rails
Why ruby and railsWhy ruby and rails
Why ruby and rails
 
MySQL in the Hosted Cloud
MySQL in the Hosted CloudMySQL in the Hosted Cloud
MySQL in the Hosted Cloud
 
Quick-and-Easy Deployment of a Ceph Storage Cluster
Quick-and-Easy Deployment of a Ceph Storage ClusterQuick-and-Easy Deployment of a Ceph Storage Cluster
Quick-and-Easy Deployment of a Ceph Storage Cluster
 
Redis Labcamp
Redis LabcampRedis Labcamp
Redis Labcamp
 
Technologies for Data Analytics Platform
Technologies for Data Analytics PlatformTechnologies for Data Analytics Platform
Technologies for Data Analytics Platform
 
Databases in the hosted cloud
Databases in the hosted cloudDatabases in the hosted cloud
Databases in the hosted cloud
 
Apache Thrift, a brief introduction
Apache Thrift, a brief introductionApache Thrift, a brief introduction
Apache Thrift, a brief introduction
 
AWS Webcast - Backup & Restore for ElastiCache/Redis: Getting Started & Best ...
AWS Webcast - Backup & Restore for ElastiCache/Redis: Getting Started & Best ...AWS Webcast - Backup & Restore for ElastiCache/Redis: Getting Started & Best ...
AWS Webcast - Backup & Restore for ElastiCache/Redis: Getting Started & Best ...
 
Fixing twitter
Fixing twitterFixing twitter
Fixing twitter
 
Fixing_Twitter
Fixing_TwitterFixing_Twitter
Fixing_Twitter
 
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
 
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
 

Mehr von Ricard Clau

NoEresTanEspecial-PulpoCon22.pdf
NoEresTanEspecial-PulpoCon22.pdfNoEresTanEspecial-PulpoCon22.pdf
NoEresTanEspecial-PulpoCon22.pdfRicard Clau
 
DevOps & Infraestructura como código: Promesas Rotas
DevOps & Infraestructura como código: Promesas RotasDevOps & Infraestructura como código: Promesas Rotas
DevOps & Infraestructura como código: Promesas RotasRicard Clau
 
DevOps Barcelona Conference 2018 - Intro
DevOps Barcelona Conference 2018 - IntroDevOps Barcelona Conference 2018 - Intro
DevOps Barcelona Conference 2018 - IntroRicard Clau
 
Hashicorp at holaluz
Hashicorp at holaluzHashicorp at holaluz
Hashicorp at holaluzRicard Clau
 
What we talk about when we talk about DevOps
What we talk about when we talk about DevOpsWhat we talk about when we talk about DevOps
What we talk about when we talk about DevOpsRicard Clau
 
Escalabilidad y alto rendimiento con Symfony2
Escalabilidad y alto rendimiento con Symfony2Escalabilidad y alto rendimiento con Symfony2
Escalabilidad y alto rendimiento con Symfony2Ricard Clau
 
Betabeers Barcelona - Buenas prácticas
Betabeers Barcelona - Buenas prácticasBetabeers Barcelona - Buenas prácticas
Betabeers Barcelona - Buenas prácticasRicard Clau
 
Desymfony - Servicios
Desymfony  - ServiciosDesymfony  - Servicios
Desymfony - ServiciosRicard Clau
 

Mehr von Ricard Clau (10)

devopsbcn23.pdf
devopsbcn23.pdfdevopsbcn23.pdf
devopsbcn23.pdf
 
devopsbcn22.pdf
devopsbcn22.pdfdevopsbcn22.pdf
devopsbcn22.pdf
 
NoEresTanEspecial-PulpoCon22.pdf
NoEresTanEspecial-PulpoCon22.pdfNoEresTanEspecial-PulpoCon22.pdf
NoEresTanEspecial-PulpoCon22.pdf
 
DevOps & Infraestructura como código: Promesas Rotas
DevOps & Infraestructura como código: Promesas RotasDevOps & Infraestructura como código: Promesas Rotas
DevOps & Infraestructura como código: Promesas Rotas
 
DevOps Barcelona Conference 2018 - Intro
DevOps Barcelona Conference 2018 - IntroDevOps Barcelona Conference 2018 - Intro
DevOps Barcelona Conference 2018 - Intro
 
Hashicorp at holaluz
Hashicorp at holaluzHashicorp at holaluz
Hashicorp at holaluz
 
What we talk about when we talk about DevOps
What we talk about when we talk about DevOpsWhat we talk about when we talk about DevOps
What we talk about when we talk about DevOps
 
Escalabilidad y alto rendimiento con Symfony2
Escalabilidad y alto rendimiento con Symfony2Escalabilidad y alto rendimiento con Symfony2
Escalabilidad y alto rendimiento con Symfony2
 
Betabeers Barcelona - Buenas prácticas
Betabeers Barcelona - Buenas prácticasBetabeers Barcelona - Buenas prácticas
Betabeers Barcelona - Buenas prácticas
 
Desymfony - Servicios
Desymfony  - ServiciosDesymfony  - Servicios
Desymfony - Servicios
 

Kürzlich hochgeladen

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Kürzlich hochgeladen (20)

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 

Redis Everywhere - Sunshine PHP

  • 2. HELLO WORLD • Ricard Clau, born and grown up in Barcelona • Software engineer at Hailo in London • Symfony2 lover and PHP believer • Open-source • Twitter contributor, sometimes I give talks @ricardclau / Gmail ricard.clau@gmail.com
  • 3. WHAT IS REDIS? • REmote • Created • Open DIctionary Server in 2009 by Salvatore Sanfilipo (@antirez) source • Advanced in-memory key-value data-structure server • Part of the NoSQL movement • Stop thinking SQL, think back to structures!
  • 4. TO ME REDIS IS LIKE...
  • 5. REDIS EVERYWHERE? Redis is not a silver bullet... so let´s rephrase that with... The amazing story on how we gradually introduced Redis in a social videogaming company... and it saved us!
  • 6. AGENDA • REDIS introduction • Getting started with PHP / Symfony2: sessions, caching • Recipes and comparison with other technologies • Sharding data. And some criticism! • War Stories from a 7.5M DAU project • Final thoughts
  • 7. INTRODUCTION TO REDIS And some demystifications
  • 8. DATA TYPES • Strings • Lists up to 512 Mb of elements sorted by insertion order (max 2^32 - 1) • Sets unordered collection of elements supporting unions, intersections and differences (max 2^32 - 1) • Hashes key-value pairs (max 2^32 - 1) • Sorted sets automatically ordered by score (max 2^32 - 1)
  • 9. ONLY IN-MEMORY? • Your data needs to fit in your memory has configurable persistence: RDB snapshots, AOF persistence logs, combine both or no persistence at all • It • Think like memcached on steroids with persistence • http://redis.io/topics/persistence • “Memory is the new disk, disk is the new tape”
  • 10. INTERESTING FEATURES • Master-slave • Pipelining replication to improve performance • Transactions • Publisher • Scripting (kind of with MULTI ... EXEC) / Subscriber with LUA (~stored procedures) • Predictable performance (check commands complexity)
  • 11. HARDWARE TIPS is single-threaded, so a 2 core machine is enough • Redis using EC2, maybe m1.large (7.5Gb) is the most suitable, but if it is not enough you might consider any m2 memory optimized type • If • Amazon • CPU • Read ElastiCache finally supports Redis! is rarely the bottleneck with Redis carefully the doc to maximize performance!
  • 12. NEW IN REDIS 2.8 • CONFIG REWRITE and IPv6 support • Improvements in scripting and key expiring algorithm • Keyspace notifications via PUB / SUB. (~Triggered events) • Partial resynchronization with slaves • Better •A consistency support (allow writes only when N slaves) fully rewritten Redis Sentinel
  • 13. ALSO IN 2.8 (H|Z|S)?SCAN • Ability to iterate the data structures • SCAN cursor [MATCH pattern] [COUNT count] • (H|Z|S)SCAN • Cursor • Count • When key cursor [MATCH pattern] [COUNT count] is kind of a pointer that we send back and forth is NOT the number of elements but the complexity using MATCH some steps in iteration may return nil
  • 14. GETTING STARTED WITH PHP It is easier than you may think!
  • 15. PHP CLIENTS • Predis (PHP) vs phpredis (PHP extension) • Predis is very mature, actively maintained, feature complete, extendable, composer friendly and supports all Redis versions • Phpredis is faster, but not backwards compatible • Network latency is the biggest performance killer • http://redis.io/clients
  • 16. REDIS-CLI AND MONITOR • Redis-cli to connect to a Redis instance • Experiment with http://redis.io/commands • With Monitor we can watch live activity!
  • 17. SESSIONS, CACHING • Super-easy to implement with commercial frameworks used: GET <session-id>, SETEX <session-id> <expires> <serialized-data> • Commands • Fast performance and also persistent! • Caching • Be and temp-data storage work exactly equal careful with temp-data storage and memory usage!
  • 18. SYMFONY2 INTEGRATION • There must be a bundle for that... • https://github.com/snc/SncRedisBundle of the box: Session management, Monolog handler, Swiftmailer spooling, Doctrine caching • Out • Full integration with Symfony2 profiler
  • 20. COOKBOOK And comparisons with other technologies
  • 21. REDIS AS A QUEUE • Using • We Lists and LPUSH / RPOP instructions can have different languages accessing data used that to send OpenGraph requests to Facebook (REALLY slow API) with Python daemons • We • ~80k • If messages/minute processed with 1 m1.large EC2 you need some advanced message queuing features check RabbitMQ (and Álvaro Videla´s talk) and others
  • 22. REAL-TIME ANALYTICS • We can use hashes to group many stats under one key • Most of the times we have counters: HINCRBY “stats" <key> <increment> • HMGET “stats” <key1> <key2> ... to retrieve values and HMSET “stats” “stat1” <value1> “stat2” <value2> to set them • HGETALL to get the full hash
  • 23. LEADERBOARDS • Super-easy • Each with Redis, heavy consuming with other systems board with a single key, using sorted sets • ZINCRBY “rankXXX” <increment> <userId> • Top N ZREVRANGE “rankXXX” 0 N [WITHSCORES] • We stored several milions of members under 1 key
  • 24. WHO IS ONLINE? (I) can use SETS to achieve it! • We • One set for every minute, SADD <minute> <userId> Time +1m 5 +2m 2 +3m 1 4 2 1 5 4 1 3 SUNION 1 7 3 1 2 3 7 2
  • 25. WHO IS ONLINE? (II) • Online users == everyone active in the last N minutes • SUNION <now> <now-1> <now-2> ... • SUNIONSTORE “online” <now> • Number • Obtain <now-1> <now-2> ... of users: SCARD “online” online users with SMEMBERS “online”
  • 26. FRIENDS ONLINE? • If we store user´s friends in a SET with key friends-<user-id> online: SINTERSTORE “friends-<userid>-online” “online” “friends-<userid>” 10 4 2 1 3 7 SINTER ONLINE 5 1 9 3 7 15 FRIENDS-12-ONLINE • Imagine how you would do it without Redis! FRIENDS-12 • Friends
  • 27. DISTRIBUTED LOCKING (I) • Problem in heavy-write applications: 2 almost concurrent requests trying to update same records • SELECT FOR UPDATE? Easy to create deadlocks! R1read R1 updates are lost!!!!! R2read timeline R1 R2 R1save R2save
  • 28. DISTRIBUTED LOCKING (II) • Locking • SET • And •8 can be solved with Redis with Exclusive SET <lock> 1 NX EX <seconds> keep retrying until a specific timeout m1.xlarge instances to lock 7.5M Daily Active Users Zookeeper, perhaps better for scaling or if we need different locking patterns • Alternatives: Apache
  • 29. SHARDING DATA Hopefully, you get there at some point Resharding: a painful experience
  • 30. NEEDS TO FIT IN MEMORY • Redis • Proxy Cluster will be available in 3.0 (delayed many times) servers: Twemproxy (also for memcached) • Client-side • Sharding partitioning (supported in many clients) strategies (range vs hash partitioning) • Presharding • Memory can help scaling horizontally is cheaper every day but this is a real need!
  • 31. 100000-199999 id % 4 == 0 id % 4 == 1 200000-299999 300000-399999 id % 4 == 2 id % 4 == 3 1-99999 Easy to predict scale Load not properly distributed Load distributed ok Fairly easy to reshard RANGE PARTITIONING May work in some cases, not a silver bullet
  • 32. HASH hash(key) % 4 == 0 hash(key) % 4 == 1 CRC16 CRC32 MD5 SHA1 MURMUR3 DIST hash(key) % 4 == 2 hash(key) % 4 == 3 MODULUS KETAMA Distribution also depending on hash algorithm Complicated resharding HASH PARTITIONING Better distribution... but still issues If few keys, it also becomes useless
  • 33. Many Redis instances in one initial server When needed, just split it into more servers and you don´t need resharding!!! Be careful configuring memory limits PRESHARDING Maybe overengineered
  • 34. CRITICISM IN THE NET Sometimes unfair... sometimes they have a point
  • 35. VS OTHER DATABASES • Cassandra or RIAK reshard automatically (at a big cost) • Complicated to fully automate failovers (Sentinel problems) • Severe • Tricky • All issues when slaves get out of sync, getting better to inspect big sets and hashes prior to 2.8 NoSQL have issues, check aphyr.com “Call me maybe”
  • 36. ABOUT REDIS CLUSTER • CAP Theorem: Consistency, Availability, Partition • Purists • CAP tolerance blame it to not properly respect the principles theorem is... a theorem and it comes with a cost • The goal is to provide some consistency and some failure resistance without sacrificing other practical qualities • We could debate for hours around that point!
  • 38. PROGRESSIVE USAGE • DragonCity • First had ~2M DAU when we introduced Redis usages: Queues PHP-Python and Temporary storage • Introduced • Used Locking with Redis -> End of deadlocks for temporary contests involving rankings • Session • About tracking, cheat detection and many others 7.5M DAU and similar amount of servers
  • 39. REDIS IS SUPER-FAST • Your network gets killed much before Redis is down • Always increase your ulimit values in Redis servers • We had Gigabit network connectivity between machines but it was not enough to handle the data sent and retrieved • Redis • Do was just at 20% of CPU some heavy-load tests before launching!
  • 40. SURPRISES WITH MEMORY documentation: “Sets of binary-safe strings”so, we changed values in sets from being just numbers to number + :<char> to add some info to values • Redis • We expected ~20% memory increase but in was 500% • https://github.com/antirez/redis/blob/unstable/src/t_set.c#L55 • If value can be represented as long, it is stored more efficiently • http://alonso-vidales.blogspot.co.uk/2013/06/not-all-redis- values-are-strings.html
  • 41. FINAL THOUGHTS When and when not to consider Redis
  • 42. REDIS IS PERFECT FOR... • Intensive read-write data applications • Temporary • Data stored data that fits in memory • Problems that fit Redis built-in data types • Predictability in performance needed (all commands complexity documented)
  • 43. BUT IS NOT SUITABLE WHEN.. • Big data sets, archive data • Relational • We data (RDBMS are absolutely fine to scale) don´t know how we will access data • Reporting • It applications (no where clauses) gets tricky for distributed applications (replication, clustering) • ALWAYS choose the right tool for the job!
  • 44. SPECIAL THANKS • Ronny López (@ronnylt) & Alonso Vidales (@alonsovidales) • All backend and systems engineers at @socialpoint • Of course, to all of you for being here today! our open-source project Redtrine, PR welcome: https://github.com/redtrine/redtrine • Check
  • 45. QUESTIONS? • Twitter: @ricardclau • E-mail: ricard.clau@gmail.com • Github: https://github.com/ricardclau • Blog about PHP and Symfony2: http://www.ricardclau.com • Please, rate this talk at https://joind.in/talk/view/10531