Procrastination
As A Service:
Caching &
Queueing
Presented by : Lawrence Shea
Photo by Kleber Varejão Filho on Unsplash
Hi, I’m Lawrence Shea
- PHP Developer for 6+ years
- Worked @verizondigital since Oct’16
- @soWizardly on Twitter
- Co-Organizer, Boston PHP (Next: July 28th)
- Moderator of /r/PHPHelp
- I don’t like pina coladas, or getting caught in
the rain
Raise your
hand if your
parents ever...
Scolded you for
not putting away
your toys
Photo by Ryan Franco on Unsplash
Raise your
hand if your
parents ever...
Believed you when you said
you’d made the bed
(you hadn’t done it yet)
Photo by Ryan Franco on Unsplash
Raise your
hand if your
parents ever...
Got mad at you for
procrastinating on homework,
But you got an A anyway
Photo by Ryan Franco on Unsplash
Your Parents Were Wrong!
Dr. Jin Nam Choy
- Published in 2005 study in The
Journal of Social Psychology
- Two types of procrastinators:
Active & Passive
- Passive procrastinators are
“typical”
- Active procrastinators at least
equal to non-procrastinators
Download: PDF
- Open source
- In memory data store
- Written in ANSI C
- Works as a cache
- Works as a message broker
- Many data structures
- Built in replication
- Configurable persistence
- For beginners & enterprise
- Will do your laundry
Download: https://redis.io
Photo by Anna Samoylova on Unsplash
Photo by Anna Samoylova on Unsplash
Let’s talk about Caching
a cache /kæʃ/ KASH,[1] is a hardware or software component that
stores data so future requests for that data can be served faster;
the data stored in a cache might be the result of an earlier
computation, or the duplicate of data stored elsewhere.
- https://en.wikipedia.org/wiki/Cache_(computing)
Photo by Maico Amorim on Unsplash
But where is
CACHING
useful?
Photo by Brad Barmore on Unsplash
users
user_id | username
================
1 | Bob
2 | Alice
3 | Frank
Etc...
user_coworker
user_id | coworker_id
================
1 | 2
3 | 1
Etc...
SELECT username
FROM tbl_user_coworker
JOIN tbl_users
ON (
tbl_users.user_id = tbl_user_coworker.coworker_id)
WHERE tbl_user_coworker.user_id IN
(
SELECT uc.coworker_id
FROM tbl_user_coworker AS uc
LEFT JOIN tbl_users AS u
ON (
uc.coworker_id = u.user_id)
WHERE uc.user_id IN
(
SELECT uc.coworker_id
FROM tbl_user_coworker AS uc
LEFT JOIN tbl_users AS u
ON (
uc.coworker_id = u.user_id)
WHERE uc.user_id = 1 )
UNION
(
SELECT uc.coworker_id
FROM tbl_user_coworker AS uc
LEFT JOIN tbl_users AS u
ON (
uc.coworker_id = u.user_id)
WHERE uc.user_id = 1 ) )
AND coworker_id <> 1
ORDER BY username
Kcachegrind results on this laptop
Subsequent
request
24.53% faster
Initial request up
only 2.51%
Photo by Ben White on Unsplash
We can use
CRON JOBS
to make every
request a
subsequent
request
*sometimes
Photo by Ben White on Unsplash
Can we Cache a
LEADERBOARD?
Ask yourself & team if you
REALLY need live data.
Even just 1 minute old
data can significantly
improve performance
Photo by Leslie Jones on Unsplash
“We now sell branded hats,
t-shirts, flip flops, handbags,
bluetooth speakers,
headsets, etc, etc, etc... and
not just one of each either!
Those are just the
categories! Our inventory of
over a million products is
showing up on monday!”
Photo by Leslie Jones on UnsplashPhoto by Bernard Hermant on Unsplash
Multiple Requests
to Cache on one
page?
Cache the WHOLE
PAGE, now just one
request
#InceptionCache
Photo by Ash from Modern Afflatus on Unsplash
Weeks have gone
by, and everything
seems quiet…
Too Quiet.
Photo by Kristina Flour on Unsplash
Create a simple form, get
that on a page and a link to
it in the footer, commit that,
make a PR, get it approved,
and done. Not bad for 5pm
on a Friday.
Everything is fine, time
to go home! Photo by Rob Bye on Unsplash
The email address is
blowing up! Thousands
of requests per second
for: item exchanges,
product questions, ‘how
do i do this’ questions,
just everything you
could think of.
Photo by Arny Mogensen on Unsplash
Our simple contact
form was never
intended to handle this
kind of load! Requests
are taking 20 seconds
to complete when they
aren’t just outright
failing! Photo by Mathew Schwartz on Unsplash
How do we
handle
thousands of
contact form
submissions
per second?
Lawrence shea
myemail@ok.com
How to order just 1 shoe
HELP PLZ! I submitted this form
three times and all three times
it took 2 minutes to say internal
server error what does that mean
Photo by Anna Samoylova on Unsplash
- Instant Success message
- Actually, send job off to do later
- We can queue jobs very fast
- Do work in the background
- Huge response time improvement
- Particularly fault tolerant
- Retry failed jobs
WHY JOB QUEUES?
Photo by Julie Johnson on Unsplash
What’s the Status Code?
202 - Accepted.
The request has been accepted for processing,
but the processing has not been completed.
The request might or might not eventually be
acted upon, as it might be disallowed when
processing actually takes place
https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
Photo by Jakob Owens on Unsplash
Which Package?
This is built into or easily integrated into frameworks in
many languages, but some examples are;
https://github.com/chrisboulton/php-resque for PHP
https://github.com/rq/django-rq for Python/Django &
https://github.com/smrchy/rsmq for JS
Photo by chuttersnap on Unsplash
But how fast is
JOB QUEUEING?
Photo by Ahsan Avi on Unsplash
Kcachegrind results on this laptop
But how fast is JOB QUEUEING?
Photo by Ahsan Avi on Unsplash
Sending five emails took 7.5 Seconds
Adding to queue took 2.02 Seconds
Decrease response time by 73.06%
Even when Frank
tripped over the
power cord to the
central email
server, emails
were eventually
sent. No user got
an error message!
Photo by Daniel Páscoa on Unsplash
Frank
What else can we
QUEUE?
Queue Limitations?
It’s only going to work when we don’t
actually need to respond to the user
with anything particularly useful.
Because we haven’t done the work
yet!
But can we overcome this limitation?
Photo by Feifei Peng on Unsplash
To Don’t?
Queue the addition of a task to
a to-do list? But if we do the job
later suddenly we have a
confused user.
They didn’t get an error, and
yet, there to-do app isn’t
updated with the task they just
submitted!
Photo by Jason Rosewell on Unsplash
WebSockets, an advanced
technology that makes it possible to
open an interactive communication
session between the user's browser
and a server. With this API, you can
send messages to a server and
receive event-driven responses
without having to poll the server for
a reply.
https://developer.mozilla.org/en-
US/docs/Web/API/WebSockets_A
PI
Which Package?
There are many options, but to name a few:
- Ratchet (PHP) http://socketo.me/
- WebSocketJS https://github.com/gimite/web-socket-js
- Python/Django https://github.com/jrief/django-websocket-redis
Photo by chuttersnap on Unsplash
No matter where you are on
your coder journey, it’s
never too early or too late to
improve performance by
actively procrastinating.
Procrastination
As A Service:
Caching &
Queueing
Presented by : Lawrence Shea
Photo by Kleber Varejão Filho on Unsplash
I’m still Lawrence Shea
- PHP Developer for 6+ years
- Worked @verizondigital since Oct’16
- @soWizardly on Twitter
- Co-Organizer, Boston PHP
- Moderator of /r/PHPHelp
- THANK YOU!!!

More Related Content

PPT
Outils Web pour la recherche et la collaboration
PPTX
E-Resource Workflow for a Small/Medium Academic Library
PPT
Working Outside the Inbox- 2012
PDF
Eventual Consistency - Desining Fail Proof Systems
PDF
2024 Trend Updates: What Really Works In SEO & Content Marketing
PDF
Storytelling For The Web: Integrate Storytelling in your Design Process
PDF
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
PDF
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
Outils Web pour la recherche et la collaboration
E-Resource Workflow for a Small/Medium Academic Library
Working Outside the Inbox- 2012
Eventual Consistency - Desining Fail Proof Systems
2024 Trend Updates: What Really Works In SEO & Content Marketing
Storytelling For The Web: Integrate Storytelling in your Design Process
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...

Recently uploaded (20)

PPT
Chapter 1 - Introduction to Manufacturing Technology_2.ppt
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PDF
MLpara ingenieira CIVIL, meca Y AMBIENTAL
PPTX
wireless networks, mobile computing.pptx
PDF
LOW POWER CLASS AB SI POWER AMPLIFIER FOR WIRELESS MEDICAL SENSOR NETWORK
PPTX
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
PDF
Unit1 - AIML Chapter 1 concept and ethics
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PDF
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
PPTX
"Array and Linked List in Data Structures with Types, Operations, Implementat...
PPTX
CyberSecurity Mobile and Wireless Devices
PPTX
Amdahl’s law is explained in the above power point presentations
PDF
First part_B-Image Processing - 1 of 2).pdf
PDF
Computer System Architecture 3rd Edition-M Morris Mano.pdf
PPTX
A Brief Introduction to IoT- Smart Objects: The "Things" in IoT
PDF
distributed database system" (DDBS) is often used to refer to both the distri...
PPTX
CN_Unite_1 AI&DS ENGGERING SPPU PUNE UNIVERSITY
PPTX
tack Data Structure with Array and Linked List Implementation, Push and Pop O...
PDF
August -2025_Top10 Read_Articles_ijait.pdf
PPTX
Petroleum Refining & Petrochemicals.pptx
Chapter 1 - Introduction to Manufacturing Technology_2.ppt
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
MLpara ingenieira CIVIL, meca Y AMBIENTAL
wireless networks, mobile computing.pptx
LOW POWER CLASS AB SI POWER AMPLIFIER FOR WIRELESS MEDICAL SENSOR NETWORK
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
Unit1 - AIML Chapter 1 concept and ethics
Exploratory_Data_Analysis_Fundamentals.pdf
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
"Array and Linked List in Data Structures with Types, Operations, Implementat...
CyberSecurity Mobile and Wireless Devices
Amdahl’s law is explained in the above power point presentations
First part_B-Image Processing - 1 of 2).pdf
Computer System Architecture 3rd Edition-M Morris Mano.pdf
A Brief Introduction to IoT- Smart Objects: The "Things" in IoT
distributed database system" (DDBS) is often used to refer to both the distri...
CN_Unite_1 AI&DS ENGGERING SPPU PUNE UNIVERSITY
tack Data Structure with Array and Linked List Implementation, Push and Pop O...
August -2025_Top10 Read_Articles_ijait.pdf
Petroleum Refining & Petrochemicals.pptx
Ad
Ad

Procrastination as a Service: Caching and Queueing

  • 1. Procrastination As A Service: Caching & Queueing Presented by : Lawrence Shea Photo by Kleber Varejão Filho on Unsplash
  • 2. Hi, I’m Lawrence Shea - PHP Developer for 6+ years - Worked @verizondigital since Oct’16 - @soWizardly on Twitter - Co-Organizer, Boston PHP (Next: July 28th) - Moderator of /r/PHPHelp - I don’t like pina coladas, or getting caught in the rain
  • 3. Raise your hand if your parents ever... Scolded you for not putting away your toys Photo by Ryan Franco on Unsplash
  • 4. Raise your hand if your parents ever... Believed you when you said you’d made the bed (you hadn’t done it yet) Photo by Ryan Franco on Unsplash
  • 5. Raise your hand if your parents ever... Got mad at you for procrastinating on homework, But you got an A anyway Photo by Ryan Franco on Unsplash
  • 7. Dr. Jin Nam Choy - Published in 2005 study in The Journal of Social Psychology - Two types of procrastinators: Active & Passive - Passive procrastinators are “typical” - Active procrastinators at least equal to non-procrastinators Download: PDF
  • 8. - Open source - In memory data store - Written in ANSI C - Works as a cache - Works as a message broker - Many data structures - Built in replication - Configurable persistence - For beginners & enterprise - Will do your laundry Download: https://redis.io
  • 9. Photo by Anna Samoylova on Unsplash
  • 10. Photo by Anna Samoylova on Unsplash
  • 11. Let’s talk about Caching a cache /kæʃ/ KASH,[1] is a hardware or software component that stores data so future requests for that data can be served faster; the data stored in a cache might be the result of an earlier computation, or the duplicate of data stored elsewhere. - https://en.wikipedia.org/wiki/Cache_(computing) Photo by Maico Amorim on Unsplash
  • 12. But where is CACHING useful? Photo by Brad Barmore on Unsplash
  • 13. users user_id | username ================ 1 | Bob 2 | Alice 3 | Frank Etc... user_coworker user_id | coworker_id ================ 1 | 2 3 | 1 Etc... SELECT username FROM tbl_user_coworker JOIN tbl_users ON ( tbl_users.user_id = tbl_user_coworker.coworker_id) WHERE tbl_user_coworker.user_id IN ( SELECT uc.coworker_id FROM tbl_user_coworker AS uc LEFT JOIN tbl_users AS u ON ( uc.coworker_id = u.user_id) WHERE uc.user_id IN ( SELECT uc.coworker_id FROM tbl_user_coworker AS uc LEFT JOIN tbl_users AS u ON ( uc.coworker_id = u.user_id) WHERE uc.user_id = 1 ) UNION ( SELECT uc.coworker_id FROM tbl_user_coworker AS uc LEFT JOIN tbl_users AS u ON ( uc.coworker_id = u.user_id) WHERE uc.user_id = 1 ) ) AND coworker_id <> 1 ORDER BY username
  • 14. Kcachegrind results on this laptop
  • 15. Subsequent request 24.53% faster Initial request up only 2.51% Photo by Ben White on Unsplash
  • 16. We can use CRON JOBS to make every request a subsequent request *sometimes Photo by Ben White on Unsplash
  • 17. Can we Cache a LEADERBOARD? Ask yourself & team if you REALLY need live data. Even just 1 minute old data can significantly improve performance Photo by Leslie Jones on Unsplash
  • 18. “We now sell branded hats, t-shirts, flip flops, handbags, bluetooth speakers, headsets, etc, etc, etc... and not just one of each either! Those are just the categories! Our inventory of over a million products is showing up on monday!” Photo by Leslie Jones on UnsplashPhoto by Bernard Hermant on Unsplash
  • 19. Multiple Requests to Cache on one page? Cache the WHOLE PAGE, now just one request #InceptionCache Photo by Ash from Modern Afflatus on Unsplash
  • 20. Weeks have gone by, and everything seems quiet… Too Quiet. Photo by Kristina Flour on Unsplash
  • 21. Create a simple form, get that on a page and a link to it in the footer, commit that, make a PR, get it approved, and done. Not bad for 5pm on a Friday. Everything is fine, time to go home! Photo by Rob Bye on Unsplash
  • 22. The email address is blowing up! Thousands of requests per second for: item exchanges, product questions, ‘how do i do this’ questions, just everything you could think of. Photo by Arny Mogensen on Unsplash
  • 23. Our simple contact form was never intended to handle this kind of load! Requests are taking 20 seconds to complete when they aren’t just outright failing! Photo by Mathew Schwartz on Unsplash
  • 24. How do we handle thousands of contact form submissions per second? Lawrence shea myemail@ok.com How to order just 1 shoe HELP PLZ! I submitted this form three times and all three times it took 2 minutes to say internal server error what does that mean
  • 25. Photo by Anna Samoylova on Unsplash
  • 26. - Instant Success message - Actually, send job off to do later - We can queue jobs very fast - Do work in the background - Huge response time improvement - Particularly fault tolerant - Retry failed jobs WHY JOB QUEUES? Photo by Julie Johnson on Unsplash
  • 27. What’s the Status Code? 202 - Accepted. The request has been accepted for processing, but the processing has not been completed. The request might or might not eventually be acted upon, as it might be disallowed when processing actually takes place https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html Photo by Jakob Owens on Unsplash
  • 28. Which Package? This is built into or easily integrated into frameworks in many languages, but some examples are; https://github.com/chrisboulton/php-resque for PHP https://github.com/rq/django-rq for Python/Django & https://github.com/smrchy/rsmq for JS Photo by chuttersnap on Unsplash
  • 29. But how fast is JOB QUEUEING? Photo by Ahsan Avi on Unsplash
  • 30. Kcachegrind results on this laptop
  • 31. But how fast is JOB QUEUEING? Photo by Ahsan Avi on Unsplash Sending five emails took 7.5 Seconds Adding to queue took 2.02 Seconds Decrease response time by 73.06%
  • 32. Even when Frank tripped over the power cord to the central email server, emails were eventually sent. No user got an error message! Photo by Daniel Páscoa on Unsplash Frank
  • 33. What else can we QUEUE?
  • 34. Queue Limitations? It’s only going to work when we don’t actually need to respond to the user with anything particularly useful. Because we haven’t done the work yet! But can we overcome this limitation? Photo by Feifei Peng on Unsplash
  • 35. To Don’t? Queue the addition of a task to a to-do list? But if we do the job later suddenly we have a confused user. They didn’t get an error, and yet, there to-do app isn’t updated with the task they just submitted! Photo by Jason Rosewell on Unsplash
  • 36. WebSockets, an advanced technology that makes it possible to open an interactive communication session between the user's browser and a server. With this API, you can send messages to a server and receive event-driven responses without having to poll the server for a reply. https://developer.mozilla.org/en- US/docs/Web/API/WebSockets_A PI
  • 37. Which Package? There are many options, but to name a few: - Ratchet (PHP) http://socketo.me/ - WebSocketJS https://github.com/gimite/web-socket-js - Python/Django https://github.com/jrief/django-websocket-redis Photo by chuttersnap on Unsplash
  • 38. No matter where you are on your coder journey, it’s never too early or too late to improve performance by actively procrastinating.
  • 39. Procrastination As A Service: Caching & Queueing Presented by : Lawrence Shea Photo by Kleber Varejão Filho on Unsplash
  • 40. I’m still Lawrence Shea - PHP Developer for 6+ years - Worked @verizondigital since Oct’16 - @soWizardly on Twitter - Co-Organizer, Boston PHP - Moderator of /r/PHPHelp - THANK YOU!!!