Slide 1

Slide 1 text

Ruby, Redis and Lua - Customised Scripts to Improve Performance Marcelo Pinheiro http://salizzar.net - @salizzar

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

$ whoami • Fireman / Problem Solver / Programmer since 2000 • Ruby, Python, Golang, Java, C#, Classic ASP, PHP, Coldfusion, Erlang and others • Fought, made coffee, negotiated deadlines • Software & DevOps Engineer

Slide 4

Slide 4 text

Not just K/V store NoSQL database O’rly?

Slide 5

Slide 5 text

Redis: not only K/V store NoSQL database • Beyond basic types with redis you can use: • Lists • Sets • Sorted Sets • Hashes • Bitmaps

Slide 6

Slide 6 text

Redis: not only K/V store NoSQL database • HyperLogLogs (available since 2.8.9) • WAT • Data structure based on approximation algorithm of the cardinality from a set • In practice, you can count elements of a set with minimal amount of memory

Slide 7

Slide 7 text

Redis for High Performance Some tips

Slide 8

Slide 8 text

Redis for High Performance • Based on your needs, Redis can be a good choice in a high performance system. • Pub/Sub messaging • Many Redis commands are O(1) • Fast, low RAM consumption

Slide 9

Slide 9 text

Redis for High Performance • It seems so good, but… • Captain Obvious: depends. • KNOW. YOUR. PROBLEM. SERIOUSLY. • Redis suffer from bad use because is a hype, as other tools; KNOW WHAT YOU WANT TO USE.

Slide 10

Slide 10 text

Redis Transactions Are totally different from relational database transactions.

Slide 11

Slide 11 text

Redis Transactions: WTF • Redis transaction commands: • MULTI: start a transaction, queueing following commands called after • EXEC: execute enqueued commands • DISCARD: obviously discard enqueued commands • WATCH: check-and-set behaviour to detect changes on a key; if watched key is changed from a concurrent connection between WATCH and EXEC command transaction will fail • UNWATCH: obviously stop to check changes on a key

Slide 12

Slide 12 text

Redis Transactions: WTF • If a Redis transaction started by MULTI contains a command failure, caused by wrong operation inside a structure per example, following commands will be called anyway when EXEC is executed. • Redis not have rollback mechanism. • Be careful using it.

Slide 13

Slide 13 text

Redis and Lua Runs fast.

Slide 14

Slide 14 text

Redis and Lua • Since 2.6.0 Redis have embedded support to Lua scripts • What is Lua? • Brazilian Scripting Programming Language • Fast, lightweight and simple • Famous on game development ecosystem • Ruby, Java, Python support

Slide 15

Slide 15 text

Is fast, believe me. https://github.com/salizzar/tdc-nosql-redis

Slide 16

Slide 16 text

Questions? It’s real?

Slide 17

Slide 17 text

Thank you! :)