Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby, Redis and Lua - Customised Scripts to Improve Performance

Ruby, Redis and Lua - Customised Scripts to Improve Performance

Redis, the famous NoSQL DB, have a nice feature to improve performance and compute more complex logic: Lua. The database have native support to this language to execute scripts and commands.

Due for atomic nature of some operations, you can use it on high concurrency applications.

Marcelo Pinheiro

October 08, 2016
Tweet

More Decks by Marcelo Pinheiro

Other Decks in Technology

Transcript

  1. Ruby, Redis and Lua - Customised Scripts to Improve Performance

    Marcelo Pinheiro http://salizzar.net - @salizzar
  2. $ 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
  3. Redis: not only K/V store NoSQL database • Beyond basic

    types with redis you can use: • Lists • Sets • Sorted Sets • Hashes • Bitmaps
  4. 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
  5. 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
  6. 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.
  7. 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
  8. 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.
  9. 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