Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Asynchronous Processing for Fun and Profit
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Mike Perham
November 02, 2012
Technology
890
11
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Asynchronous Processing for Fun and Profit
Some pro tips and an overview of Sidekiq for great async victory!
Mike Perham
November 02, 2012
More Decks by Mike Perham
See All by Mike Perham
Computer Science vs Software Engineering
mperham
0
350
A Tribute to Ezra Zygmuntowicz
mperham
1
1.1k
Other Decks in Technology
See All in Technology
Oracle AI Database@AWS:サービス概要のご紹介
oracle4engineer
PRO
4
2.8k
JJUG CCC 2026 Spring AI時代の開発こそ標準化を武器に! ― 方式・プロセス・プラットフォームの標準化
s27watanabe
2
720
地元にいないローカルオーガナイザーの立ち回り
uvb_76
1
470
Platform engineering for developers, architects & the rest of us (AI agents)
danielbryantuk
0
180
Dario Amodi『Policy on the AI Exponential』を理解する
nagatsu
0
190
ITエンジニアを取り巻く環境とキャリアパス / A career path for Japanese IT engineers
takatama
4
1.8k
製造業のクラウド活用最適解〜AI,DXを加速するデータ基盤の作り方〜
hamadakoji
0
380
実装は速くなった、レビューはどうする? ― 自身のレビューをAIで再現させるサーヴァントエンジニアリングのすゝめ / Implementation got faster. So what about reviews? — An invitation to Servant Engineering: Recreating your own code reviews with AI
nrslib
7
3.8k
DevOps Agentで始めるAWS運用 〜フロンティアエージェントが変える運用の現場〜
nyankotaro
1
230
AI活用を推進するために ファインディが下した、一つの小さな決断
starfish719
0
250
「気づいたら仕事が終わっている」バクラクAIエージェント本番運用の裏側 / layerx-bakuraku-aie2026
yuya4
18
10k
Databricks における 生成AIガバナンスの実践
taka_aki
1
320
Featured
See All Featured
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
380
Crafting Experiences
bethany
1
170
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
Prompt Engineering for Job Search
mfonobong
0
330
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Writing Fast Ruby
sferik
630
63k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
320
Skip the Path - Find Your Career Trail
mkilby
1
140
Site-Speed That Sticks
csswizardry
13
1.2k
Transcript
Async Processing for Fun and Profit Mike Perham @mperham
Me Director of Engineering, TheClymb.com
Agenda • Basics • Protips • Sidekiq
Why? • User-Perceived Performance • I/O is SLOOOOOOOOOOOW • I/O
is unreliable
What? • Optional work • Anything not required to build
the HTTP response
How? • Client puts message on a queue • Server
pulls message off queue • Worker executes code based on message
How? async do # perform some work end
How? • Marshalling a Proc • Need to serialize closure
How? async(instance, :method, args)
How? • Marshal instance • Marshal args
How? async(Class, :method, args)
How? • Serialize just the class name • Marshal the
arguments
Congratulations! This is exactly how Resque and Sidekiq work.
How?
How?
How?
Tip #1 Small, Stateless Messages
Stateless • Database holds objects (nouns) • Queue holds actions
(verbs) • “Perform X on Object 123”
Avoid State • Bad • @user.delay.sync_images • Good • User.delay.sync_images(@user.id)
Simple Types • Small & Easy to read • Cross-platform
• Sidekiq / Resque use JSON
Debugging
Tip #2 Idempotent, Transactional Units of Work
Idempotent • Fancy computer science term • “Work can be
applied multiple times without changing the result beyond the initial application”
Idempotent • Canceling an order • Updating user’s email address
Not Idempotent! • Charging credit card • Sending email
Idempotent • Your code has bugs! • Sidekiq will retry
jobs that raise • Design jobs to be retried • e.g. verify you need to perform action before performing it
Transactional • Infinite credit?
Tip #3 Embrace Concurrency
Concurrency • Resque/DJ = 4 workers • Sidekiq = 100
workers • Mike, what is best in life?
“To crush their servers, see them smoking before you and
hear the lamentations of their admins.”
Concurrency • Use connection_pool gem to limit client connections •
Split work into small batches • 100 items => 10 jobs of 10 items
Concurrency • Thread safety rarely an issue • Most gem
maintainers very responsive • Recently fixed: • cocaine, typheuos
Theory, meet Practice
Sidekiq • Simple, efficient message processing • Like Resque, but
10x faster
MODERN RUBY IS NOT SLOW SINGLE THREADING IS SLOW
Concurrency • To scale single-threaded, create lots of processes. •
HORRIBLY RAM INEFFICIENT
Threads vs Processes • Example: 400MB single-threaded process • 25
processes = 10GB RAM = EC2 xlarge • 25 threads = 1GB RAM = EC2 small • $60/month vs $480/month • 160 dynos => 10 dynos • 150 dynos * $35/month =~ $5000/month
Quick Rant • GIL + poor GC • C extension
API must DIE • What’s larger: 50% or 800%?
Client Your App Client Middleware Redis Sidekiq Client API Rails
Process
Server Processor Server Middleware Redis Worker Sidekiq Process Processor Server
Middleware Worker Processor Server Middleware Worker Processor Server Middleware Worker Fetcher Manager
Versions • Sidekiq - Free, LGPLv3 • Sidekiq Pro -
more features, support, $ • motivation!
Features Sidekiq Resque DJ Concurrency Store Hooks Web UI Scheduler
Retry Delay Batches Threads Processes Processes Redis Redis DB middleware callbacks callbacks ✓ ✓ ? ✓ ? ✓ ✓ ? ✓ ✓ ? ✓ Pro ? - ? - optional
Future • Nicer, more functional Web UI • APIs for
managing queues / retries • Rails 4 Queue API
Pro Future • Enterprise-y features • Workflow • Notifications
Conclusion • small, stateless messages • idempotent / transactional •
concurrency • sidekiq
Questions? @mperham
[email protected]