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
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
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
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
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
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
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.
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!!!