SlideShare uma empresa Scribd logo
1 de 41
Baixar para ler offline
How to count at scale
What is Pusher Channels?
It’s like Redis Pub/Sub ...
It’s like Redis Pub/Sub ...

 with millionsof concurrentclients

 on the Internet

 using WebSocketconnections

 hosted at
pusher.com

 plus extra features (presence,
encryption, debug console 
)
<script src="//js.pusher.com/4.3/pusher.min.js"></script>
<script>
var pusher = new Pusher('abc123');
var channel = pusher.subscribe('donuts');
channel.bind('new-price',
price => alert('New price: ' + price));
</script>
<?php
$pusher = new Pusher('abc123', 'd34db33', '123456');
$pusher->trigger('donuts', 'new-price', '0.99');
$ pusher channels channel-info --channel donuts 
--app-id 180207
{
"Name": "donuts",
"occupied": true,
"subscription_count": 2
}
How to count subscriptions
We start with clients.
client client
These clients connect to a Channels service.
The clients get “socket ids”.
client 2345
Channels
client 234
Clients create subscriptions to channels.
client 2345
user-jim
Channels
donuts
client 234
donuts btc-usd
The Channels box must keep a map of
channel name to clients.
client 2345
user-jim
Channels
donuts
client 234
donuts btc-usd
user-jim
donuts
btc-usd
client 2345
user-jim
Channels
donuts
client 234
donuts btc-usd
user-jim
donuts
btc-usd
Let’s count subscriptions.
How many subscriptions are there for the
channel “donuts”?
Easy: find the “donuts” key of the map, then
count the number of connections.
(The answer is: 2.)
Scaling out
client 2345
user-jim
Channels
donuts
client 234
donuts btc-usd
user-jim
donuts
btc-usd
This is a monolith!
It can’t be scaled in this form.
client 123.2345
user-jim
socket 123 socket 124 socket 125
donuts
client 123.234
donuts
client 124.23
donuts btc-usd
client 125.1
donutsbtc-usd
user-jim
donuts
btc-usd
donuts
btc-usd
donuts
To scale out: add more processes!
We call these “socket processes”.
client 123.2345
user-jim
socket 123 socket 124 socket 125
donuts
client 123.234
donuts
client 124.23
donuts btc-usd
client 125.1
donutsbtc-usd
user-jim
donuts
btc-usd
donuts
btc-usd
donuts
redis-pubsub
After adding more processes, where
should you publish to?
These socket processes need to
communicate somehow.
For this, we use Redis.
client 123.2345
user-jim
socket 123 socket 124 socket 125
donuts
client 123.234
donuts
client 124.23
donuts btc-usd
client 125.1
donutsbtc-usd
user-jim
donuts
btc-usd
donuts
btc-usd
donuts
redis-pubsub
user-jim
donuts
btc-usd
Specifically, we use the Redis Pub/Sub
feature. Hence, we call this Redis
“redis-pubsub”.
Notice redis-pubsub looks a lot like a
socket process! Redis Pub/Sub provides a
very similar mapping from “channel
names” to connections.
Counting subscriptions across boxes
client 123.2345
user-jim
socket 123 socket 124 socket 125
donuts
client 123.234
donuts
client 124.23
donuts btc-usd
client 125.1
donutsbtc-usd
user-jim
donuts
btc-usd
donuts
btc-usd
donuts
redis-pubsub
user-jim
donuts
btc-usd
Let’s count subscriptions again.
How many subscriptions are there for the
channel “donuts”? We can ask Redis:
127.0.0.1:6381[2]> pubsub numsub donuts
1) "donuts"
2) "3"
Wrong! Socket 123 has two end-user
subscriptions for “donuts”, so the answer
should be “4”.
client 123.2345
user-jim
socket 123 socket 124 socket 125
donuts
client 123.234
donuts
client 124.23
donuts btc-usd
client 125.1
donutsbtc-usd
user-jim
donuts
btc-usd
donuts
btc-usd
donuts
redis-pubsub
user-jim
donuts
btc-usd
Instead of counting connections to socket
processes, we must keep separate counters
for the number of connections to clients.
Unfortunately, Redis Pub/Sub doesn’t
provide this hypothetical feature, so ...
1 2 4
redis-main
client 123.2345
user-jim
socket 123 socket 124 socket 125
donuts
client 123.234
donuts
client 124.23
donuts btc-usd
client 125.1
donutsbtc-usd
user-jim
donuts
btc-usd
donuts
btc-usd
donuts
redis-pubsub
user-jim
donuts
btc-usd

 for subscription
counts, we have
another Redis we call
“redis-main”.
All socket processes
connect to this redis,
too.
redis-main
client 123.2345
user-jim
socket 123 socket 124 socket 125
donuts
client 123.234
donuts
client 124.23
donuts btc-usd
client 125.1
donutsbtc-usd
user-jim
donuts
btc-usd
donuts
btc-usd
donuts
redis-pubsub
user-jim
donuts
btc-usd
user-jim
donuts
btc-usd
1
4
2
channels:count:global
redis-main keeps the
per-channel subscription
counts in a Redis hash
“channels:count:global”.
When a subscription to
“donuts” is added or
removed on a socket
box, we do:
HINCRBY channels:count:global donuts 1
HINCRBY channels:count:global donuts -1
What happens when
a socket process goes away?
redis-main
client 123.2345
user-jim
socket 123 socket 124 socket 125
donuts
client 123.234
donuts
client 124.23
donuts btc-usd
client 125.1
donutsbtc-usd
user-jim
donuts
btc-usd
donuts
btc-usd
donuts
redis-pubsub
user-jim
donuts
btc-usd
user-jim
donuts
btc-usd
1
4
2
channels:count:global
Consider this situation.
redis-main
client 123.2345
user-jim
socket 123 socket 124 socket 125
donuts
client 123.234
donuts
client 124.23
donuts btc-usd
client 125.1
donutsbtc-usd
user-jim
donuts
btc-usd
donuts
btc-usd
donuts
redis-pubsub
user-jim
donuts
btc-usd
user-jim
donuts
btc-usd
1
4
2
channels:count:global
Suddenly, socket 123
goes away!
Along with all of its
clients ...
redis-main
socket 124 socket 125
client 124.23
donuts btc-usd
client 125.1
donuts
donuts
btc-usd
donuts
redis-pubsub
donuts
btc-usd
user-jim
donuts
btc-usd
1
4
2
channels:count:global
Redis-pubsub was able to
clean up, but what about
redis-main? Let’s count
subscriptions again.
How many subscriptions
are there for the channel
“donuts”?
Not four, but two! The
per-channel subscription
counters are wrong!
We need to subtract the
two client subscriptions to
“donuts” from the counter,
but that number is now
lost ...
redis-main
client 123.2345
user-jim
socket 123 socket 124 socket 125
donuts
client 123.234
donuts
client 124.23
donuts btc-usd
client 125.1
donutsbtc-usd
user-jim
donuts
btc-usd
donuts
btc-usd
donuts
redis-pubsub
user-jim
donuts
btc-usd
user-jim
donuts
btc-usd
1
4
2
channels:count:global
user-jim
donuts
btc-usd
1
2
1
channels:count:123
donuts
btc-usd
2
1
channels:count:124
donuts 1
channels:count:125
We must keep the
per-channel connection
counts for each socket
process, so that when
the socket process
dies, its counts can be
subtracted.
For each socket
process, we keep
another Redis hash of
its subscription counts.
For example, socket
process 123 has the
hash
“channels:count:123”.
MULTI
HINCRBY channels:count:global donuts 1
HINCRBY channels:count:123 donuts 1
EXEC
redis-main
client 123.2345
user-jim
socket 123 socket 124 socket 125
donuts
client 123.234
donuts
client 124.23
donuts btc-usd
client 125.1
donutsbtc-usd
user-jim
donuts
btc-usd
donuts
btc-usd
donuts
redis-pubsub
user-jim
donuts
btc-usd
user-jim
donuts
btc-usd
1
4
2
channels:count:global
user-jim
donuts
btc-usd
1
2
1
channels:count:123
donuts
btc-usd
2
1
channels:count:124
donuts 1
channels:count:125
Is this enough for
cleaning up? See what
happens when socket
123 goes away ...
redis-main
socket 124 socket 125
client 124.23
donuts btc-usd
client 125.1
donuts
donuts
btc-usd
donuts
redis-pubsub
donuts
btc-usd
user-jim
donuts
btc-usd
1
4
2
channels:count:global
user-jim
donuts
btc-usd
1
2
1
channels:count:123
donuts
btc-usd
2
1
channels:count:124
donuts 1
channels:count:125
Redis-pubsub is able to
clean up, as before.
But redis-main still
doesn’t do anything!
Why?
Unfortunately,
redis-main doesn’t
know the relationship
between the lost
connection and the id
“123”.
Instead, we must
detect dead socket
processes ourselves,
and clean up after
them.
Detecting dead socket processes
redis-main
client 123.2345
user-jim
socket 123 socket 124 socket 125
donuts
client 123.234
donuts
client 124.23
donuts btc-usd
client 125.1
donutsbtc-usd
user-jim
donuts
btc-usd
donuts
btc-usd
donuts
redis-pubsub
user-jim
donuts
btc-usd
125
123
124
17:35
17:35
17:35
socket:process:all
user-jim
donuts
btc-usd
1
4
2
channels:count:global
user-jim
donuts
btc-usd
1
2
1
channels:count:123
donuts
btc-usd
2
1
channels:count:124
donuts 1
channels:count:125
To identify
dead socket
processes, we
maintain a
“last seen”
time for each
socket
process id in a
Redis hash.
Each socket
process
continually
updates this
hash.
redis-main
socket 124 socket 125
client 124.23
donuts btc-usd
client 125.1
donuts
donuts
btc-usd
donuts
redis-pubsub
donuts
btc-usd
125
123
124
17:46
17:35
17:46
socket:process:all
user-jim
donuts
btc-usd
1
4
2
channels:count:global
user-jim
donuts
btc-usd
1
2
1
channels:count:123
donuts
btc-usd
2
1
channels:count:124
donuts 1
channels:count:125
When socket
123 goes
away, its “last
seen” time
gets older.
Then, after ten
minutes, we
consider it
dead.
client 123.2345
user-jim
socket 123
donuts
client 123.234
donuts btc-usd
user-jim
donuts
btc-usd
user-jim
redis-main
socket 124 socket 125
client 124.23
donuts btc-usd
client 125.1
donuts
donuts
btc-usd
donuts
redis-pubsub
donuts
btc-usd
125
123
124
17:46
17:35
17:46
socket:process:all
user-jim
donuts
btc-usd
1
4
2
channels:count:global
user-jim
donuts
btc-usd
1
2
1
channels:count:123
donuts
btc-usd
2
1
channels:count:124
donuts 1
channels:count:125
But still
nothing
happens!
Redis-main
doesn’t know
about our
socket
process list.
Instead, we
must check it
ourselves ...
redis-main
socket 124 socket 125
client 124.23
donuts btc-usd
client 125.1
donuts
donuts
btc-usd
donuts
redis-pubsub
donuts
btc-usd
cleanup-dead
125
123
124
17:46
17:35
17:46
socket:process:all
user-jim
donuts
btc-usd
1
4
2
channels:count:global
user-jim
donuts
btc-usd
1
2
1
channels:count:123
donuts
btc-usd
2
1
channels:count:124
donuts 1
channels:count:125
We do this with
a separate
process,
“cleanup-dead”.
redis-main
socket 124 socket 125
client 124.23
donuts btc-usd
client 125.1
donuts
donuts
btc-usd
donuts
redis-pubsub
donuts
btc-usd
cleanup-dead
125
124
17:46
17:46
socket:process:all
donuts
btc-usd
2
1
channels:count:global
donuts
btc-usd
2
1
channels:count:124
donuts 1
channels:count:125
Cleanup-dead
runs a job every
4 minutes. If a
socket has been
inactive for more
than 10 minutes,
it considers it
dead.
It decrements the
socket’s counts
from the global
counts. Then it
deletes the
socket’s counts.
Then it deletes
the socket from
the “last seen”
times.
TESTAMENT SET EVALSHA 123abc 1 socket:123
redis
Client C
Local set A
Partial
global index
Application code
Client B
Local set
Partial
global index
Application code
Set C
Set B
Client A
Application
State A
Global
indexes:
A + B + C
Application code
Important
State A
Global
indexes:
A + B + C
We’re hiring!
pusher.com/careers
jim@pusher.com

Mais conteĂșdo relacionado

Semelhante a RedisDay London 2018 - How to Count at Scale

NetScaler Web2.0 Push Technology Overview
NetScaler Web2.0 Push Technology OverviewNetScaler Web2.0 Push Technology Overview
NetScaler Web2.0 Push Technology Overviewkvamsi
 
Reactor, Reactive streams and MicroServices
Reactor, Reactive streams and MicroServicesReactor, Reactive streams and MicroServices
Reactor, Reactive streams and MicroServicesStéphane Maldini
 
Running Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docx
Running Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docxRunning Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docx
Running Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docxcowinhelen
 
Swift distributed tracing method and tools v2
Swift distributed tracing method and tools v2Swift distributed tracing method and tools v2
Swift distributed tracing method and tools v2zhang hua
 
Kauli SSPにおけるVyOSた氎慄äș‹äŸ‹
Kauli SSPにおけるVyOSた氎慄äș‹äŸ‹Kauli SSPにおけるVyOSた氎慄äș‹äŸ‹
Kauli SSPにおけるVyOSた氎慄äș‹äŸ‹Kazuhito Ohkawa
 
Why is My Stream Processing Job Slow? with Xavier Leaute
Why is My Stream Processing Job Slow? with Xavier LeauteWhy is My Stream Processing Job Slow? with Xavier Leaute
Why is My Stream Processing Job Slow? with Xavier LeauteDatabricks
 
Net Programming.ppt
Net Programming.pptNet Programming.ppt
Net Programming.pptEloAcubaOgardo
 
R bernardino hand_in_assignment_week_1
R bernardino hand_in_assignment_week_1R bernardino hand_in_assignment_week_1
R bernardino hand_in_assignment_week_1Raul Bernardino, BSc MSc
 
Deep dive in container service discovery
Deep dive in container service discoveryDeep dive in container service discovery
Deep dive in container service discoveryDocker, Inc.
 
Network Prog.ppt
Network Prog.pptNetwork Prog.ppt
Network Prog.pptEloOgardo
 
Etl, esb, mq? no! es Apache KafkaÂź
Etl, esb, mq?  no! es Apache KafkaÂźEtl, esb, mq?  no! es Apache KafkaÂź
Etl, esb, mq? no! es Apache KafkaÂźconfluent
 
The present and future of serverless observability (QCon London)
The present and future of serverless observability (QCon London)The present and future of serverless observability (QCon London)
The present and future of serverless observability (QCon London)Yan Cui
 
The present and future of Serverless observability
The present and future of Serverless observabilityThe present and future of Serverless observability
The present and future of Serverless observabilityYan Cui
 
The present and future of Serverless observability
The present and future of Serverless observabilityThe present and future of Serverless observability
The present and future of Serverless observabilityYan Cui
 
Code Red Security
Code Red SecurityCode Red Security
Code Red SecurityAmr Ali
 
Kafka Client-Broker Interactions – What You Don’t See With Tom Bentley | Curr...
Kafka Client-Broker Interactions – What You Don’t See With Tom Bentley | Curr...Kafka Client-Broker Interactions – What You Don’t See With Tom Bentley | Curr...
Kafka Client-Broker Interactions – What You Don’t See With Tom Bentley | Curr...HostedbyConfluent
 
CEPH侭的QOSæŠ€æœŻ
CEPH侭的QOSæŠ€æœŻCEPH侭的QOSæŠ€æœŻ
CEPH侭的QOSæŠ€æœŻsuncbing1
 
ql.io: Consuming HTTP at Scale
ql.io: Consuming HTTP at Scale ql.io: Consuming HTTP at Scale
ql.io: Consuming HTTP at Scale Subbu Allamaraju
 
Troubleshooting TCP/IP
Troubleshooting TCP/IPTroubleshooting TCP/IP
Troubleshooting TCP/IPvijai s
 

Semelhante a RedisDay London 2018 - How to Count at Scale (20)

NetScaler Web2.0 Push Technology Overview
NetScaler Web2.0 Push Technology OverviewNetScaler Web2.0 Push Technology Overview
NetScaler Web2.0 Push Technology Overview
 
Reactor, Reactive streams and MicroServices
Reactor, Reactive streams and MicroServicesReactor, Reactive streams and MicroServices
Reactor, Reactive streams and MicroServices
 
Running Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docx
Running Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docxRunning Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docx
Running Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docx
 
Swift distributed tracing method and tools v2
Swift distributed tracing method and tools v2Swift distributed tracing method and tools v2
Swift distributed tracing method and tools v2
 
Kauli SSPにおけるVyOSた氎慄äș‹äŸ‹
Kauli SSPにおけるVyOSた氎慄äș‹äŸ‹Kauli SSPにおけるVyOSた氎慄äș‹äŸ‹
Kauli SSPにおけるVyOSた氎慄äș‹äŸ‹
 
Why is My Stream Processing Job Slow? with Xavier Leaute
Why is My Stream Processing Job Slow? with Xavier LeauteWhy is My Stream Processing Job Slow? with Xavier Leaute
Why is My Stream Processing Job Slow? with Xavier Leaute
 
Net Programming.ppt
Net Programming.pptNet Programming.ppt
Net Programming.ppt
 
R bernardino hand_in_assignment_week_1
R bernardino hand_in_assignment_week_1R bernardino hand_in_assignment_week_1
R bernardino hand_in_assignment_week_1
 
Deep dive in container service discovery
Deep dive in container service discoveryDeep dive in container service discovery
Deep dive in container service discovery
 
Network Prog.ppt
Network Prog.pptNetwork Prog.ppt
Network Prog.ppt
 
Rpc
RpcRpc
Rpc
 
Etl, esb, mq? no! es Apache KafkaÂź
Etl, esb, mq?  no! es Apache KafkaÂźEtl, esb, mq?  no! es Apache KafkaÂź
Etl, esb, mq? no! es Apache KafkaÂź
 
The present and future of serverless observability (QCon London)
The present and future of serverless observability (QCon London)The present and future of serverless observability (QCon London)
The present and future of serverless observability (QCon London)
 
The present and future of Serverless observability
The present and future of Serverless observabilityThe present and future of Serverless observability
The present and future of Serverless observability
 
The present and future of Serverless observability
The present and future of Serverless observabilityThe present and future of Serverless observability
The present and future of Serverless observability
 
Code Red Security
Code Red SecurityCode Red Security
Code Red Security
 
Kafka Client-Broker Interactions – What You Don’t See With Tom Bentley | Curr...
Kafka Client-Broker Interactions – What You Don’t See With Tom Bentley | Curr...Kafka Client-Broker Interactions – What You Don’t See With Tom Bentley | Curr...
Kafka Client-Broker Interactions – What You Don’t See With Tom Bentley | Curr...
 
CEPH侭的QOSæŠ€æœŻ
CEPH侭的QOSæŠ€æœŻCEPH侭的QOSæŠ€æœŻ
CEPH侭的QOSæŠ€æœŻ
 
ql.io: Consuming HTTP at Scale
ql.io: Consuming HTTP at Scale ql.io: Consuming HTTP at Scale
ql.io: Consuming HTTP at Scale
 
Troubleshooting TCP/IP
Troubleshooting TCP/IPTroubleshooting TCP/IP
Troubleshooting TCP/IP
 

Mais de Redis Labs

Redis Day Bangalore 2020 - Session state caching with redis
Redis Day Bangalore 2020 - Session state caching with redisRedis Day Bangalore 2020 - Session state caching with redis
Redis Day Bangalore 2020 - Session state caching with redisRedis Labs
 
Protecting Your API with Redis by Jane Paek - Redis Day Seattle 2020
Protecting Your API with Redis by Jane Paek - Redis Day Seattle 2020Protecting Your API with Redis by Jane Paek - Redis Day Seattle 2020
Protecting Your API with Redis by Jane Paek - Redis Day Seattle 2020Redis Labs
 
The Happy Marriage of Redis and Protobuf by Scott Haines of Twilio - Redis Da...
The Happy Marriage of Redis and Protobuf by Scott Haines of Twilio - Redis Da...The Happy Marriage of Redis and Protobuf by Scott Haines of Twilio - Redis Da...
The Happy Marriage of Redis and Protobuf by Scott Haines of Twilio - Redis Da...Redis Labs
 
SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020
SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020
SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020Redis Labs
 
Rust and Redis - Solving Problems for Kubernetes by Ravi Jagannathan of VMwar...
Rust and Redis - Solving Problems for Kubernetes by Ravi Jagannathan of VMwar...Rust and Redis - Solving Problems for Kubernetes by Ravi Jagannathan of VMwar...
Rust and Redis - Solving Problems for Kubernetes by Ravi Jagannathan of VMwar...Redis Labs
 
Redis for Data Science and Engineering by Dmitry Polyakovsky of Oracle
Redis for Data Science and Engineering by Dmitry Polyakovsky of OracleRedis for Data Science and Engineering by Dmitry Polyakovsky of Oracle
Redis for Data Science and Engineering by Dmitry Polyakovsky of OracleRedis Labs
 
Practical Use Cases for ACLs in Redis 6 by Jamie Scott - Redis Day Seattle 2020
Practical Use Cases for ACLs in Redis 6 by Jamie Scott - Redis Day Seattle 2020Practical Use Cases for ACLs in Redis 6 by Jamie Scott - Redis Day Seattle 2020
Practical Use Cases for ACLs in Redis 6 by Jamie Scott - Redis Day Seattle 2020Redis Labs
 
Moving Beyond Cache by Yiftach Shoolman Redis Labs - Redis Day Seattle 2020
Moving Beyond Cache by Yiftach Shoolman Redis Labs - Redis Day Seattle 2020Moving Beyond Cache by Yiftach Shoolman Redis Labs - Redis Day Seattle 2020
Moving Beyond Cache by Yiftach Shoolman Redis Labs - Redis Day Seattle 2020Redis Labs
 
Leveraging Redis for System Monitoring by Adam McCormick of SBG - Redis Day S...
Leveraging Redis for System Monitoring by Adam McCormick of SBG - Redis Day S...Leveraging Redis for System Monitoring by Adam McCormick of SBG - Redis Day S...
Leveraging Redis for System Monitoring by Adam McCormick of SBG - Redis Day S...Redis Labs
 
JSON in Redis - When to use RedisJSON by Jay Won of Coupang - Redis Day Seatt...
JSON in Redis - When to use RedisJSON by Jay Won of Coupang - Redis Day Seatt...JSON in Redis - When to use RedisJSON by Jay Won of Coupang - Redis Day Seatt...
JSON in Redis - When to use RedisJSON by Jay Won of Coupang - Redis Day Seatt...Redis Labs
 
Highly Available Persistent Session Management Service by Mohamed Elmergawi o...
Highly Available Persistent Session Management Service by Mohamed Elmergawi o...Highly Available Persistent Session Management Service by Mohamed Elmergawi o...
Highly Available Persistent Session Management Service by Mohamed Elmergawi o...Redis Labs
 
Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...
Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...
Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...Redis Labs
 
Building a Multi-dimensional Analytics Engine with RedisGraph by Matthew Goos...
Building a Multi-dimensional Analytics Engine with RedisGraph by Matthew Goos...Building a Multi-dimensional Analytics Engine with RedisGraph by Matthew Goos...
Building a Multi-dimensional Analytics Engine with RedisGraph by Matthew Goos...Redis Labs
 
RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020
RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020
RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020Redis Labs
 
RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020
RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020
RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020Redis Labs
 
RedisTimeSeries 1.2 by Pieter Cailliau - Redis Day Bangalore 2020
RedisTimeSeries 1.2 by Pieter Cailliau - Redis Day Bangalore 2020RedisTimeSeries 1.2 by Pieter Cailliau - Redis Day Bangalore 2020
RedisTimeSeries 1.2 by Pieter Cailliau - Redis Day Bangalore 2020Redis Labs
 
RedisAI 0.9 by Sherin Thomas of Tensorwerk - Redis Day Bangalore 2020
RedisAI 0.9 by Sherin Thomas of Tensorwerk - Redis Day Bangalore 2020RedisAI 0.9 by Sherin Thomas of Tensorwerk - Redis Day Bangalore 2020
RedisAI 0.9 by Sherin Thomas of Tensorwerk - Redis Day Bangalore 2020Redis Labs
 
Rate-Limiting 30 Million requests by Vijay Lakshminarayanan and Girish Koundi...
Rate-Limiting 30 Million requests by Vijay Lakshminarayanan and Girish Koundi...Rate-Limiting 30 Million requests by Vijay Lakshminarayanan and Girish Koundi...
Rate-Limiting 30 Million requests by Vijay Lakshminarayanan and Girish Koundi...Redis Labs
 
Three Pillars of Observability by Rajalakshmi Raji Srinivasan of Site24x7 Zoh...
Three Pillars of Observability by Rajalakshmi Raji Srinivasan of Site24x7 Zoh...Three Pillars of Observability by Rajalakshmi Raji Srinivasan of Site24x7 Zoh...
Three Pillars of Observability by Rajalakshmi Raji Srinivasan of Site24x7 Zoh...Redis Labs
 
Solving Complex Scaling Problems by Prashant Kumar and Abhishek Jain of Myntr...
Solving Complex Scaling Problems by Prashant Kumar and Abhishek Jain of Myntr...Solving Complex Scaling Problems by Prashant Kumar and Abhishek Jain of Myntr...
Solving Complex Scaling Problems by Prashant Kumar and Abhishek Jain of Myntr...Redis Labs
 

Mais de Redis Labs (20)

Redis Day Bangalore 2020 - Session state caching with redis
Redis Day Bangalore 2020 - Session state caching with redisRedis Day Bangalore 2020 - Session state caching with redis
Redis Day Bangalore 2020 - Session state caching with redis
 
Protecting Your API with Redis by Jane Paek - Redis Day Seattle 2020
Protecting Your API with Redis by Jane Paek - Redis Day Seattle 2020Protecting Your API with Redis by Jane Paek - Redis Day Seattle 2020
Protecting Your API with Redis by Jane Paek - Redis Day Seattle 2020
 
The Happy Marriage of Redis and Protobuf by Scott Haines of Twilio - Redis Da...
The Happy Marriage of Redis and Protobuf by Scott Haines of Twilio - Redis Da...The Happy Marriage of Redis and Protobuf by Scott Haines of Twilio - Redis Da...
The Happy Marriage of Redis and Protobuf by Scott Haines of Twilio - Redis Da...
 
SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020
SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020
SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020
 
Rust and Redis - Solving Problems for Kubernetes by Ravi Jagannathan of VMwar...
Rust and Redis - Solving Problems for Kubernetes by Ravi Jagannathan of VMwar...Rust and Redis - Solving Problems for Kubernetes by Ravi Jagannathan of VMwar...
Rust and Redis - Solving Problems for Kubernetes by Ravi Jagannathan of VMwar...
 
Redis for Data Science and Engineering by Dmitry Polyakovsky of Oracle
Redis for Data Science and Engineering by Dmitry Polyakovsky of OracleRedis for Data Science and Engineering by Dmitry Polyakovsky of Oracle
Redis for Data Science and Engineering by Dmitry Polyakovsky of Oracle
 
Practical Use Cases for ACLs in Redis 6 by Jamie Scott - Redis Day Seattle 2020
Practical Use Cases for ACLs in Redis 6 by Jamie Scott - Redis Day Seattle 2020Practical Use Cases for ACLs in Redis 6 by Jamie Scott - Redis Day Seattle 2020
Practical Use Cases for ACLs in Redis 6 by Jamie Scott - Redis Day Seattle 2020
 
Moving Beyond Cache by Yiftach Shoolman Redis Labs - Redis Day Seattle 2020
Moving Beyond Cache by Yiftach Shoolman Redis Labs - Redis Day Seattle 2020Moving Beyond Cache by Yiftach Shoolman Redis Labs - Redis Day Seattle 2020
Moving Beyond Cache by Yiftach Shoolman Redis Labs - Redis Day Seattle 2020
 
Leveraging Redis for System Monitoring by Adam McCormick of SBG - Redis Day S...
Leveraging Redis for System Monitoring by Adam McCormick of SBG - Redis Day S...Leveraging Redis for System Monitoring by Adam McCormick of SBG - Redis Day S...
Leveraging Redis for System Monitoring by Adam McCormick of SBG - Redis Day S...
 
JSON in Redis - When to use RedisJSON by Jay Won of Coupang - Redis Day Seatt...
JSON in Redis - When to use RedisJSON by Jay Won of Coupang - Redis Day Seatt...JSON in Redis - When to use RedisJSON by Jay Won of Coupang - Redis Day Seatt...
JSON in Redis - When to use RedisJSON by Jay Won of Coupang - Redis Day Seatt...
 
Highly Available Persistent Session Management Service by Mohamed Elmergawi o...
Highly Available Persistent Session Management Service by Mohamed Elmergawi o...Highly Available Persistent Session Management Service by Mohamed Elmergawi o...
Highly Available Persistent Session Management Service by Mohamed Elmergawi o...
 
Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...
Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...
Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...
 
Building a Multi-dimensional Analytics Engine with RedisGraph by Matthew Goos...
Building a Multi-dimensional Analytics Engine with RedisGraph by Matthew Goos...Building a Multi-dimensional Analytics Engine with RedisGraph by Matthew Goos...
Building a Multi-dimensional Analytics Engine with RedisGraph by Matthew Goos...
 
RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020
RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020
RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020
 
RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020
RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020
RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020
 
RedisTimeSeries 1.2 by Pieter Cailliau - Redis Day Bangalore 2020
RedisTimeSeries 1.2 by Pieter Cailliau - Redis Day Bangalore 2020RedisTimeSeries 1.2 by Pieter Cailliau - Redis Day Bangalore 2020
RedisTimeSeries 1.2 by Pieter Cailliau - Redis Day Bangalore 2020
 
RedisAI 0.9 by Sherin Thomas of Tensorwerk - Redis Day Bangalore 2020
RedisAI 0.9 by Sherin Thomas of Tensorwerk - Redis Day Bangalore 2020RedisAI 0.9 by Sherin Thomas of Tensorwerk - Redis Day Bangalore 2020
RedisAI 0.9 by Sherin Thomas of Tensorwerk - Redis Day Bangalore 2020
 
Rate-Limiting 30 Million requests by Vijay Lakshminarayanan and Girish Koundi...
Rate-Limiting 30 Million requests by Vijay Lakshminarayanan and Girish Koundi...Rate-Limiting 30 Million requests by Vijay Lakshminarayanan and Girish Koundi...
Rate-Limiting 30 Million requests by Vijay Lakshminarayanan and Girish Koundi...
 
Three Pillars of Observability by Rajalakshmi Raji Srinivasan of Site24x7 Zoh...
Three Pillars of Observability by Rajalakshmi Raji Srinivasan of Site24x7 Zoh...Three Pillars of Observability by Rajalakshmi Raji Srinivasan of Site24x7 Zoh...
Three Pillars of Observability by Rajalakshmi Raji Srinivasan of Site24x7 Zoh...
 
Solving Complex Scaling Problems by Prashant Kumar and Abhishek Jain of Myntr...
Solving Complex Scaling Problems by Prashant Kumar and Abhishek Jain of Myntr...Solving Complex Scaling Problems by Prashant Kumar and Abhishek Jain of Myntr...
Solving Complex Scaling Problems by Prashant Kumar and Abhishek Jain of Myntr...
 

Último

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel AraĂșjo
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 

Último (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

RedisDay London 2018 - How to Count at Scale

  • 1. How to count at scale
  • 2. What is Pusher Channels?
  • 3. It’s like Redis Pub/Sub ...
  • 4. It’s like Redis Pub/Sub ... 
 with millionsof concurrentclients 
 on the Internet 
 using WebSocketconnections 
 hosted at pusher.com 
 plus extra features (presence, encryption, debug console 
)
  • 5. <script src="//js.pusher.com/4.3/pusher.min.js"></script> <script> var pusher = new Pusher('abc123'); var channel = pusher.subscribe('donuts'); channel.bind('new-price', price => alert('New price: ' + price)); </script>
  • 6. <?php $pusher = new Pusher('abc123', 'd34db33', '123456'); $pusher->trigger('donuts', 'new-price', '0.99');
  • 7. $ pusher channels channel-info --channel donuts --app-id 180207 { "Name": "donuts", "occupied": true, "subscription_count": 2 }
  • 8. How to count subscriptions
  • 9. We start with clients. client client
  • 10. These clients connect to a Channels service. The clients get “socket ids”. client 2345 Channels client 234
  • 11. Clients create subscriptions to channels. client 2345 user-jim Channels donuts client 234 donuts btc-usd
  • 12. The Channels box must keep a map of channel name to clients. client 2345 user-jim Channels donuts client 234 donuts btc-usd user-jim donuts btc-usd
  • 13. client 2345 user-jim Channels donuts client 234 donuts btc-usd user-jim donuts btc-usd Let’s count subscriptions. How many subscriptions are there for the channel “donuts”? Easy: find the “donuts” key of the map, then count the number of connections. (The answer is: 2.)
  • 15. client 2345 user-jim Channels donuts client 234 donuts btc-usd user-jim donuts btc-usd This is a monolith! It can’t be scaled in this form.
  • 16. client 123.2345 user-jim socket 123 socket 124 socket 125 donuts client 123.234 donuts client 124.23 donuts btc-usd client 125.1 donutsbtc-usd user-jim donuts btc-usd donuts btc-usd donuts To scale out: add more processes! We call these “socket processes”.
  • 17. client 123.2345 user-jim socket 123 socket 124 socket 125 donuts client 123.234 donuts client 124.23 donuts btc-usd client 125.1 donutsbtc-usd user-jim donuts btc-usd donuts btc-usd donuts redis-pubsub After adding more processes, where should you publish to? These socket processes need to communicate somehow. For this, we use Redis.
  • 18. client 123.2345 user-jim socket 123 socket 124 socket 125 donuts client 123.234 donuts client 124.23 donuts btc-usd client 125.1 donutsbtc-usd user-jim donuts btc-usd donuts btc-usd donuts redis-pubsub user-jim donuts btc-usd Specifically, we use the Redis Pub/Sub feature. Hence, we call this Redis “redis-pubsub”. Notice redis-pubsub looks a lot like a socket process! Redis Pub/Sub provides a very similar mapping from “channel names” to connections.
  • 20. client 123.2345 user-jim socket 123 socket 124 socket 125 donuts client 123.234 donuts client 124.23 donuts btc-usd client 125.1 donutsbtc-usd user-jim donuts btc-usd donuts btc-usd donuts redis-pubsub user-jim donuts btc-usd Let’s count subscriptions again. How many subscriptions are there for the channel “donuts”? We can ask Redis: 127.0.0.1:6381[2]> pubsub numsub donuts 1) "donuts" 2) "3" Wrong! Socket 123 has two end-user subscriptions for “donuts”, so the answer should be “4”.
  • 21. client 123.2345 user-jim socket 123 socket 124 socket 125 donuts client 123.234 donuts client 124.23 donuts btc-usd client 125.1 donutsbtc-usd user-jim donuts btc-usd donuts btc-usd donuts redis-pubsub user-jim donuts btc-usd Instead of counting connections to socket processes, we must keep separate counters for the number of connections to clients. Unfortunately, Redis Pub/Sub doesn’t provide this hypothetical feature, so ... 1 2 4
  • 22. redis-main client 123.2345 user-jim socket 123 socket 124 socket 125 donuts client 123.234 donuts client 124.23 donuts btc-usd client 125.1 donutsbtc-usd user-jim donuts btc-usd donuts btc-usd donuts redis-pubsub user-jim donuts btc-usd 
 for subscription counts, we have another Redis we call “redis-main”. All socket processes connect to this redis, too.
  • 23. redis-main client 123.2345 user-jim socket 123 socket 124 socket 125 donuts client 123.234 donuts client 124.23 donuts btc-usd client 125.1 donutsbtc-usd user-jim donuts btc-usd donuts btc-usd donuts redis-pubsub user-jim donuts btc-usd user-jim donuts btc-usd 1 4 2 channels:count:global redis-main keeps the per-channel subscription counts in a Redis hash “channels:count:global”. When a subscription to “donuts” is added or removed on a socket box, we do: HINCRBY channels:count:global donuts 1 HINCRBY channels:count:global donuts -1
  • 24. What happens when a socket process goes away?
  • 25. redis-main client 123.2345 user-jim socket 123 socket 124 socket 125 donuts client 123.234 donuts client 124.23 donuts btc-usd client 125.1 donutsbtc-usd user-jim donuts btc-usd donuts btc-usd donuts redis-pubsub user-jim donuts btc-usd user-jim donuts btc-usd 1 4 2 channels:count:global Consider this situation.
  • 26. redis-main client 123.2345 user-jim socket 123 socket 124 socket 125 donuts client 123.234 donuts client 124.23 donuts btc-usd client 125.1 donutsbtc-usd user-jim donuts btc-usd donuts btc-usd donuts redis-pubsub user-jim donuts btc-usd user-jim donuts btc-usd 1 4 2 channels:count:global Suddenly, socket 123 goes away! Along with all of its clients ...
  • 27. redis-main socket 124 socket 125 client 124.23 donuts btc-usd client 125.1 donuts donuts btc-usd donuts redis-pubsub donuts btc-usd user-jim donuts btc-usd 1 4 2 channels:count:global Redis-pubsub was able to clean up, but what about redis-main? Let’s count subscriptions again. How many subscriptions are there for the channel “donuts”? Not four, but two! The per-channel subscription counters are wrong! We need to subtract the two client subscriptions to “donuts” from the counter, but that number is now lost ...
  • 28. redis-main client 123.2345 user-jim socket 123 socket 124 socket 125 donuts client 123.234 donuts client 124.23 donuts btc-usd client 125.1 donutsbtc-usd user-jim donuts btc-usd donuts btc-usd donuts redis-pubsub user-jim donuts btc-usd user-jim donuts btc-usd 1 4 2 channels:count:global user-jim donuts btc-usd 1 2 1 channels:count:123 donuts btc-usd 2 1 channels:count:124 donuts 1 channels:count:125 We must keep the per-channel connection counts for each socket process, so that when the socket process dies, its counts can be subtracted. For each socket process, we keep another Redis hash of its subscription counts. For example, socket process 123 has the hash “channels:count:123”.
  • 29. MULTI HINCRBY channels:count:global donuts 1 HINCRBY channels:count:123 donuts 1 EXEC
  • 30. redis-main client 123.2345 user-jim socket 123 socket 124 socket 125 donuts client 123.234 donuts client 124.23 donuts btc-usd client 125.1 donutsbtc-usd user-jim donuts btc-usd donuts btc-usd donuts redis-pubsub user-jim donuts btc-usd user-jim donuts btc-usd 1 4 2 channels:count:global user-jim donuts btc-usd 1 2 1 channels:count:123 donuts btc-usd 2 1 channels:count:124 donuts 1 channels:count:125 Is this enough for cleaning up? See what happens when socket 123 goes away ...
  • 31. redis-main socket 124 socket 125 client 124.23 donuts btc-usd client 125.1 donuts donuts btc-usd donuts redis-pubsub donuts btc-usd user-jim donuts btc-usd 1 4 2 channels:count:global user-jim donuts btc-usd 1 2 1 channels:count:123 donuts btc-usd 2 1 channels:count:124 donuts 1 channels:count:125 Redis-pubsub is able to clean up, as before. But redis-main still doesn’t do anything! Why? Unfortunately, redis-main doesn’t know the relationship between the lost connection and the id “123”. Instead, we must detect dead socket processes ourselves, and clean up after them.
  • 33. redis-main client 123.2345 user-jim socket 123 socket 124 socket 125 donuts client 123.234 donuts client 124.23 donuts btc-usd client 125.1 donutsbtc-usd user-jim donuts btc-usd donuts btc-usd donuts redis-pubsub user-jim donuts btc-usd 125 123 124 17:35 17:35 17:35 socket:process:all user-jim donuts btc-usd 1 4 2 channels:count:global user-jim donuts btc-usd 1 2 1 channels:count:123 donuts btc-usd 2 1 channels:count:124 donuts 1 channels:count:125 To identify dead socket processes, we maintain a “last seen” time for each socket process id in a Redis hash. Each socket process continually updates this hash.
  • 34. redis-main socket 124 socket 125 client 124.23 donuts btc-usd client 125.1 donuts donuts btc-usd donuts redis-pubsub donuts btc-usd 125 123 124 17:46 17:35 17:46 socket:process:all user-jim donuts btc-usd 1 4 2 channels:count:global user-jim donuts btc-usd 1 2 1 channels:count:123 donuts btc-usd 2 1 channels:count:124 donuts 1 channels:count:125 When socket 123 goes away, its “last seen” time gets older. Then, after ten minutes, we consider it dead. client 123.2345 user-jim socket 123 donuts client 123.234 donuts btc-usd user-jim donuts btc-usd user-jim
  • 35. redis-main socket 124 socket 125 client 124.23 donuts btc-usd client 125.1 donuts donuts btc-usd donuts redis-pubsub donuts btc-usd 125 123 124 17:46 17:35 17:46 socket:process:all user-jim donuts btc-usd 1 4 2 channels:count:global user-jim donuts btc-usd 1 2 1 channels:count:123 donuts btc-usd 2 1 channels:count:124 donuts 1 channels:count:125 But still nothing happens! Redis-main doesn’t know about our socket process list. Instead, we must check it ourselves ...
  • 36. redis-main socket 124 socket 125 client 124.23 donuts btc-usd client 125.1 donuts donuts btc-usd donuts redis-pubsub donuts btc-usd cleanup-dead 125 123 124 17:46 17:35 17:46 socket:process:all user-jim donuts btc-usd 1 4 2 channels:count:global user-jim donuts btc-usd 1 2 1 channels:count:123 donuts btc-usd 2 1 channels:count:124 donuts 1 channels:count:125 We do this with a separate process, “cleanup-dead”.
  • 37. redis-main socket 124 socket 125 client 124.23 donuts btc-usd client 125.1 donuts donuts btc-usd donuts redis-pubsub donuts btc-usd cleanup-dead 125 124 17:46 17:46 socket:process:all donuts btc-usd 2 1 channels:count:global donuts btc-usd 2 1 channels:count:124 donuts 1 channels:count:125 Cleanup-dead runs a job every 4 minutes. If a socket has been inactive for more than 10 minutes, it considers it dead. It decrements the socket’s counts from the global counts. Then it deletes the socket’s counts. Then it deletes the socket from the “last seen” times.
  • 38.
  • 39. TESTAMENT SET EVALSHA 123abc 1 socket:123
  • 40. redis Client C Local set A Partial global index Application code Client B Local set Partial global index Application code Set C Set B Client A Application State A Global indexes: A + B + C Application code Important State A Global indexes: A + B + C