SlideShare una empresa de Scribd logo
1 de 25
Descargar para leer sin conexión
Work Queueing with Redis.pm
B. Estrade
http://houston.pm.org/
August 8th, 2013
What is Redis?
● a keyed (shared) data structures server
● supports its own protocol
● supports: scalar, hash, list, set
● “in memory” + optional bin logging
● “single threaded, except when it’s not”
● publish/subscribe “channels”
Demo requires set up time if you wish to run
it yourself.
Now’s a good time to start the Vagrant
process if you have not yet done so.
https://github.com/estrabd/houston-pm-redis-talk
Redis.pm
● “official” Redis client for Perl
● wrapper around Redis protocol, methods
use Redis;
my $redis = Redis->new(server =>
'192.168.2.3');
$redis->ping;
vagrant@precise64:/vagrant$ telnet 192.168.3.2 6379
Trying 192.168.3.2...
Connected to 192.168.3.2.
Escape character is '^]'.
ping
+PONG
Perl Script
Telnet Session
A Work Queue (FIFO)
What is Work Queueing? Why?
● a method of distributing tasks to a pool of
worker processes
● useful for massively scaling web applications
● decouples requests from resource intensive
interactions (e.g., with a DB)
● more secure, workers can be in a private net
● # of workers can be tuned based on load
Redis as a Queue?
● use the “list” data structure
● non-blocking:
○ lpush, rpush, lpop, rpop, rpoplpush*
● blocking
○ blpop, brpop, brpoplpush*
● necessarily implements atomic pop’ing
● other structures can be used for meta data* provides for “reliable” queues
Why Not MySQL as a Queue
● list operations must be emulated
● inefficient table locking req’d for atomic pops
Why Not Memcached as Queue
● federation would be a nice feature of a
queue
● but, memcached supports only scalar
key/val
● back to implementing atomic pops (idk
how?)
● MemcachedQ, based on MemcachedBD
exists, but languishing
Other options
● beanstalkd - not mature, not stable enough
● RabbitMQ - overkill (but not for HA
messaging?)
● NoSQL option? Not sure.
Simple Queue Client using Redis.pm
● submit_task
● get_task
● bget_task
Supporting hooks for serialization/deserialization:
● _encode_task
● _decode_task
Task.pm
● send/receive blessed Task references
● fields: type ($pkg), id, payload (‘HASH’)
● Sending:
○ serialize blessed ref (encode as JSON)
○ lpush string onto Redis list
● Receiving
○ pop off of list, parse decode with JSON::XS
○ re-bless with $task->{type}
Ping Pong
● Synchronize
● Ponger waits for Ping
● Pinger sends Ping, waits for ACK via Pong
● Repeat in turn until $rounds complete
Ping Pong
MxN Producer-Consumer, 1 Queue
● M Producers
● N Consumers
● Producers “fire and forget” - asynchronous
task submit
● Consumers pull from Queue in first come
first serve order
MxN Producer-Consumer, 1 Queue
Sync’d MxN Produce-Consume
● M Producers
● N Consumers
● Producer blocks on submit until it gets a
response from whichever Consumer got it
● Requires use of “private” queues for ACKs
Sync’d MxN Produce-Consume
Other Patterns
● Scaling out synchronous produce/consume
○ M producers, N consumers, P queues
○ best implemented with forking consumers,
○ with each child watching a different queue
● Circuitous messaging and routing
○ tasks beget other tasks to other consumers
○ chain reaction like
○ heavy use of private queus
○ useful for something?
Redis Failover Options?
● Master/Slave replication via binary log
● Redis HA Cluster in development
● Craigslist uses sharding & “federated” Redis,
which is not supported natively (here & here)
● Could use a pool of Redis instances/queues
○ Sharing/Federation is often overkill for just queuing
○ Producers will try to submit until successful
○ Available queue assumed to have at least one consumer
Note on General Messaging
● Redis is not the best foundation for “reliable”
2-way messaging
● Redis “cluster”, sharding/federating is best
here for reliability
● RabbitMQ seems to a fine, if heavy solution
for this
● ...which segues nicely into Failover
Tips
● treat Redis instances as ephemeral
● turn off binary logging for high throughput
● not convinced it’s a good durable data store
● Redis seems highly stable/reliable
● 1 machine can support many Redis daemons
● it’s smart to wrap blocking calls with alarm
Demo
● Reproducible using Vagrant manifest (KMA,
Murphy! ;)
● Ping Pong
● Asynchronous M Producer x N Consumer
● Synchronous M Producer x N Consumer
Conclusion
● Redis shines for work queueing
● Lots of potential to make w-q patterns scale
● Similarly, it can be highly available/reliable
● Open Questions -
○ leveraging other data structures for meta data
○ e.g., implement “queue” state -
■ accepting
■ draining
■ offline
Resources
● https://github.com/estrabd/houston-pm-redis-talk
● https://github.com/melo/perl-redis
● http://blog.zawodny.com/2011/02/26/redis-sharding-at-craigslist/
● Vagrant
● http://houston.pm.org/
● http://www.cpanel.net

Más contenido relacionado

La actualidad más candente

Gluster d thread_synchronization_using_urcu_lca2016
Gluster d thread_synchronization_using_urcu_lca2016Gluster d thread_synchronization_using_urcu_lca2016
Gluster d thread_synchronization_using_urcu_lca2016Gluster.org
 
Gluster technical overview
Gluster technical overviewGluster technical overview
Gluster technical overviewGluster.org
 
GlusterD 2.0 - Managing Distributed File System Using a Centralized Store
GlusterD 2.0 - Managing Distributed File System Using a Centralized StoreGlusterD 2.0 - Managing Distributed File System Using a Centralized Store
GlusterD 2.0 - Managing Distributed File System Using a Centralized StoreAtin Mukherjee
 
Lcna example-2012
Lcna example-2012Lcna example-2012
Lcna example-2012Gluster.org
 
Scale out backups-with_bareos_and_gluster
Scale out backups-with_bareos_and_glusterScale out backups-with_bareos_and_gluster
Scale out backups-with_bareos_and_glusterGluster.org
 
Tiering barcelona
Tiering barcelonaTiering barcelona
Tiering barcelonaGluster.org
 
Druid beginner performance tips
Druid beginner performance tipsDruid beginner performance tips
Druid beginner performance tipsvishnu rao
 
Debugging with-wireshark-niels-de-vos
Debugging with-wireshark-niels-de-vosDebugging with-wireshark-niels-de-vos
Debugging with-wireshark-niels-de-vosGluster.org
 
Disperse xlator ramon_datalab
Disperse xlator ramon_datalabDisperse xlator ramon_datalab
Disperse xlator ramon_datalabGluster.org
 
StripeEu Twistedbytes Presentation
StripeEu Twistedbytes PresentationStripeEu Twistedbytes Presentation
StripeEu Twistedbytes Presentationtwistedbytes
 
Scalable Architecture 101
Scalable Architecture 101Scalable Architecture 101
Scalable Architecture 101ConFoo
 
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...confluent
 
Sdc challenges-2012
Sdc challenges-2012Sdc challenges-2012
Sdc challenges-2012Gluster.org
 
Challenges with Gluster and Persistent Memory with Dan Lambright
Challenges with Gluster and Persistent Memory with Dan LambrightChallenges with Gluster and Persistent Memory with Dan Lambright
Challenges with Gluster and Persistent Memory with Dan LambrightGluster.org
 
Cassandra Explained
Cassandra ExplainedCassandra Explained
Cassandra ExplainedEric Evans
 
Deploying containers and managing them on multiple Docker hosts, Docker Meetu...
Deploying containers and managing them on multiple Docker hosts, Docker Meetu...Deploying containers and managing them on multiple Docker hosts, Docker Meetu...
Deploying containers and managing them on multiple Docker hosts, Docker Meetu...dotCloud
 
GlusterFS Containers
GlusterFS ContainersGlusterFS Containers
GlusterFS ContainersMohamed Ashiq
 
OSBConf 2015 | Scale out backups with bareos and gluster by niels de vos
OSBConf 2015 | Scale out backups with bareos and gluster by niels de vosOSBConf 2015 | Scale out backups with bareos and gluster by niels de vos
OSBConf 2015 | Scale out backups with bareos and gluster by niels de vosNETWAYS
 

La actualidad más candente (20)

Gluster d thread_synchronization_using_urcu_lca2016
Gluster d thread_synchronization_using_urcu_lca2016Gluster d thread_synchronization_using_urcu_lca2016
Gluster d thread_synchronization_using_urcu_lca2016
 
Dedupe nmamit
Dedupe nmamitDedupe nmamit
Dedupe nmamit
 
Gluster technical overview
Gluster technical overviewGluster technical overview
Gluster technical overview
 
GlusterD 2.0 - Managing Distributed File System Using a Centralized Store
GlusterD 2.0 - Managing Distributed File System Using a Centralized StoreGlusterD 2.0 - Managing Distributed File System Using a Centralized Store
GlusterD 2.0 - Managing Distributed File System Using a Centralized Store
 
Lcna example-2012
Lcna example-2012Lcna example-2012
Lcna example-2012
 
Scale out backups-with_bareos_and_gluster
Scale out backups-with_bareos_and_glusterScale out backups-with_bareos_and_gluster
Scale out backups-with_bareos_and_gluster
 
Tiering barcelona
Tiering barcelonaTiering barcelona
Tiering barcelona
 
Druid beginner performance tips
Druid beginner performance tipsDruid beginner performance tips
Druid beginner performance tips
 
Debugging with-wireshark-niels-de-vos
Debugging with-wireshark-niels-de-vosDebugging with-wireshark-niels-de-vos
Debugging with-wireshark-niels-de-vos
 
Disperse xlator ramon_datalab
Disperse xlator ramon_datalabDisperse xlator ramon_datalab
Disperse xlator ramon_datalab
 
StripeEu Twistedbytes Presentation
StripeEu Twistedbytes PresentationStripeEu Twistedbytes Presentation
StripeEu Twistedbytes Presentation
 
Scalable Architecture 101
Scalable Architecture 101Scalable Architecture 101
Scalable Architecture 101
 
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
 
Sdc challenges-2012
Sdc challenges-2012Sdc challenges-2012
Sdc challenges-2012
 
Challenges with Gluster and Persistent Memory with Dan Lambright
Challenges with Gluster and Persistent Memory with Dan LambrightChallenges with Gluster and Persistent Memory with Dan Lambright
Challenges with Gluster and Persistent Memory with Dan Lambright
 
Gluster d2
Gluster d2Gluster d2
Gluster d2
 
Cassandra Explained
Cassandra ExplainedCassandra Explained
Cassandra Explained
 
Deploying containers and managing them on multiple Docker hosts, Docker Meetu...
Deploying containers and managing them on multiple Docker hosts, Docker Meetu...Deploying containers and managing them on multiple Docker hosts, Docker Meetu...
Deploying containers and managing them on multiple Docker hosts, Docker Meetu...
 
GlusterFS Containers
GlusterFS ContainersGlusterFS Containers
GlusterFS Containers
 
OSBConf 2015 | Scale out backups with bareos and gluster by niels de vos
OSBConf 2015 | Scale out backups with bareos and gluster by niels de vosOSBConf 2015 | Scale out backups with bareos and gluster by niels de vos
OSBConf 2015 | Scale out backups with bareos and gluster by niels de vos
 

Similar a Work WIth Redis and Perl

PostgreSQL and Redis - talk at pgcon 2013
PostgreSQL and Redis - talk at pgcon 2013PostgreSQL and Redis - talk at pgcon 2013
PostgreSQL and Redis - talk at pgcon 2013Andrew Dunstan
 
Introduction to AWS Big Data
Introduction to AWS Big Data Introduction to AWS Big Data
Introduction to AWS Big Data Omid Vahdaty
 
Open stack HA - Theory to Reality
Open stack HA -  Theory to RealityOpen stack HA -  Theory to Reality
Open stack HA - Theory to RealitySriram Subramanian
 
Scaling Redis: Dmitry Polyakovsky
Scaling Redis: Dmitry PolyakovskyScaling Redis: Dmitry Polyakovsky
Scaling Redis: Dmitry PolyakovskyRedis Labs
 
Screaming Fast Wpmu
Screaming Fast WpmuScreaming Fast Wpmu
Screaming Fast Wpmudjcp
 
Ceph Day New York 2014: Future of CephFS
Ceph Day New York 2014:  Future of CephFS Ceph Day New York 2014:  Future of CephFS
Ceph Day New York 2014: Future of CephFS Ceph Community
 
An Introduction to Redis for .NET Developers.pdf
An Introduction to Redis for .NET Developers.pdfAn Introduction to Redis for .NET Developers.pdf
An Introduction to Redis for .NET Developers.pdfStephen Lorello
 
On Rails with Apache Cassandra
On Rails with Apache CassandraOn Rails with Apache Cassandra
On Rails with Apache CassandraStu Hood
 
Time to rethink /proc
Time to rethink /procTime to rethink /proc
Time to rethink /procKir Kolyshkin
 
Shall we play a game
Shall we play a gameShall we play a game
Shall we play a gamejackpot201
 
We shall play a game....
We shall play a game....We shall play a game....
We shall play a game....Sadia Textile
 
Random tips that will save your project's life
Random tips that will save your project's lifeRandom tips that will save your project's life
Random tips that will save your project's lifeMariano Iglesias
 
Linux-HA with Pacemaker
Linux-HA with PacemakerLinux-HA with Pacemaker
Linux-HA with PacemakerKris Buytaert
 

Similar a Work WIth Redis and Perl (20)

PostgreSQL and Redis - talk at pgcon 2013
PostgreSQL and Redis - talk at pgcon 2013PostgreSQL and Redis - talk at pgcon 2013
PostgreSQL and Redis - talk at pgcon 2013
 
Introduction to AWS Big Data
Introduction to AWS Big Data Introduction to AWS Big Data
Introduction to AWS Big Data
 
Scale 10x 01:22:12
Scale 10x 01:22:12Scale 10x 01:22:12
Scale 10x 01:22:12
 
Strata - 03/31/2012
Strata - 03/31/2012Strata - 03/31/2012
Strata - 03/31/2012
 
The Accidental DBA
The Accidental DBAThe Accidental DBA
The Accidental DBA
 
Open stack HA - Theory to Reality
Open stack HA -  Theory to RealityOpen stack HA -  Theory to Reality
Open stack HA - Theory to Reality
 
Scaling Redis: Dmitry Polyakovsky
Scaling Redis: Dmitry PolyakovskyScaling Redis: Dmitry Polyakovsky
Scaling Redis: Dmitry Polyakovsky
 
Screaming Fast Wpmu
Screaming Fast WpmuScreaming Fast Wpmu
Screaming Fast Wpmu
 
Ceph Day New York 2014: Future of CephFS
Ceph Day New York 2014:  Future of CephFS Ceph Day New York 2014:  Future of CephFS
Ceph Day New York 2014: Future of CephFS
 
An Introduction to Redis for .NET Developers.pdf
An Introduction to Redis for .NET Developers.pdfAn Introduction to Redis for .NET Developers.pdf
An Introduction to Redis for .NET Developers.pdf
 
Block Storage For VMs With Ceph
Block Storage For VMs With CephBlock Storage For VMs With Ceph
Block Storage For VMs With Ceph
 
XenSummit - 08/28/2012
XenSummit - 08/28/2012XenSummit - 08/28/2012
XenSummit - 08/28/2012
 
On Rails with Apache Cassandra
On Rails with Apache CassandraOn Rails with Apache Cassandra
On Rails with Apache Cassandra
 
Time to rethink /proc
Time to rethink /procTime to rethink /proc
Time to rethink /proc
 
Shall we play a game
Shall we play a gameShall we play a game
Shall we play a game
 
Shall we play a game?
Shall we play a game?Shall we play a game?
Shall we play a game?
 
0507 057 01 98 * Adana Klima Servisleri
0507 057 01 98 * Adana Klima Servisleri0507 057 01 98 * Adana Klima Servisleri
0507 057 01 98 * Adana Klima Servisleri
 
We shall play a game....
We shall play a game....We shall play a game....
We shall play a game....
 
Random tips that will save your project's life
Random tips that will save your project's lifeRandom tips that will save your project's life
Random tips that will save your project's life
 
Linux-HA with Pacemaker
Linux-HA with PacemakerLinux-HA with Pacemaker
Linux-HA with Pacemaker
 

Último

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
"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
 
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
 
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
 
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
 
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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
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
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 

Último (20)

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
"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
 
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
 
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?
 
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
 
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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
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
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
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
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
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
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 

Work WIth Redis and Perl

  • 1. Work Queueing with Redis.pm B. Estrade http://houston.pm.org/ August 8th, 2013
  • 2. What is Redis? ● a keyed (shared) data structures server ● supports its own protocol ● supports: scalar, hash, list, set ● “in memory” + optional bin logging ● “single threaded, except when it’s not” ● publish/subscribe “channels”
  • 3. Demo requires set up time if you wish to run it yourself. Now’s a good time to start the Vagrant process if you have not yet done so. https://github.com/estrabd/houston-pm-redis-talk
  • 4. Redis.pm ● “official” Redis client for Perl ● wrapper around Redis protocol, methods use Redis; my $redis = Redis->new(server => '192.168.2.3'); $redis->ping; vagrant@precise64:/vagrant$ telnet 192.168.3.2 6379 Trying 192.168.3.2... Connected to 192.168.3.2. Escape character is '^]'. ping +PONG Perl Script Telnet Session
  • 5. A Work Queue (FIFO)
  • 6. What is Work Queueing? Why? ● a method of distributing tasks to a pool of worker processes ● useful for massively scaling web applications ● decouples requests from resource intensive interactions (e.g., with a DB) ● more secure, workers can be in a private net ● # of workers can be tuned based on load
  • 7. Redis as a Queue? ● use the “list” data structure ● non-blocking: ○ lpush, rpush, lpop, rpop, rpoplpush* ● blocking ○ blpop, brpop, brpoplpush* ● necessarily implements atomic pop’ing ● other structures can be used for meta data* provides for “reliable” queues
  • 8. Why Not MySQL as a Queue ● list operations must be emulated ● inefficient table locking req’d for atomic pops
  • 9. Why Not Memcached as Queue ● federation would be a nice feature of a queue ● but, memcached supports only scalar key/val ● back to implementing atomic pops (idk how?) ● MemcachedQ, based on MemcachedBD exists, but languishing
  • 10. Other options ● beanstalkd - not mature, not stable enough ● RabbitMQ - overkill (but not for HA messaging?) ● NoSQL option? Not sure.
  • 11. Simple Queue Client using Redis.pm ● submit_task ● get_task ● bget_task Supporting hooks for serialization/deserialization: ● _encode_task ● _decode_task
  • 12. Task.pm ● send/receive blessed Task references ● fields: type ($pkg), id, payload (‘HASH’) ● Sending: ○ serialize blessed ref (encode as JSON) ○ lpush string onto Redis list ● Receiving ○ pop off of list, parse decode with JSON::XS ○ re-bless with $task->{type}
  • 13. Ping Pong ● Synchronize ● Ponger waits for Ping ● Pinger sends Ping, waits for ACK via Pong ● Repeat in turn until $rounds complete
  • 15. MxN Producer-Consumer, 1 Queue ● M Producers ● N Consumers ● Producers “fire and forget” - asynchronous task submit ● Consumers pull from Queue in first come first serve order
  • 17. Sync’d MxN Produce-Consume ● M Producers ● N Consumers ● Producer blocks on submit until it gets a response from whichever Consumer got it ● Requires use of “private” queues for ACKs
  • 19. Other Patterns ● Scaling out synchronous produce/consume ○ M producers, N consumers, P queues ○ best implemented with forking consumers, ○ with each child watching a different queue ● Circuitous messaging and routing ○ tasks beget other tasks to other consumers ○ chain reaction like ○ heavy use of private queus ○ useful for something?
  • 20. Redis Failover Options? ● Master/Slave replication via binary log ● Redis HA Cluster in development ● Craigslist uses sharding & “federated” Redis, which is not supported natively (here & here) ● Could use a pool of Redis instances/queues ○ Sharing/Federation is often overkill for just queuing ○ Producers will try to submit until successful ○ Available queue assumed to have at least one consumer
  • 21. Note on General Messaging ● Redis is not the best foundation for “reliable” 2-way messaging ● Redis “cluster”, sharding/federating is best here for reliability ● RabbitMQ seems to a fine, if heavy solution for this ● ...which segues nicely into Failover
  • 22. Tips ● treat Redis instances as ephemeral ● turn off binary logging for high throughput ● not convinced it’s a good durable data store ● Redis seems highly stable/reliable ● 1 machine can support many Redis daemons ● it’s smart to wrap blocking calls with alarm
  • 23. Demo ● Reproducible using Vagrant manifest (KMA, Murphy! ;) ● Ping Pong ● Asynchronous M Producer x N Consumer ● Synchronous M Producer x N Consumer
  • 24. Conclusion ● Redis shines for work queueing ● Lots of potential to make w-q patterns scale ● Similarly, it can be highly available/reliable ● Open Questions - ○ leveraging other data structures for meta data ○ e.g., implement “queue” state - ■ accepting ■ draining ■ offline
  • 25. Resources ● https://github.com/estrabd/houston-pm-redis-talk ● https://github.com/melo/perl-redis ● http://blog.zawodny.com/2011/02/26/redis-sharding-at-craigslist/ ● Vagrant ● http://houston.pm.org/ ● http://www.cpanel.net