Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Running Jobs at Scale
Search
Kir Shatrov
June 16, 2018
Programming
1
210
Running Jobs at Scale
My talk from GORUCO 2018 in New York.
Kir Shatrov
June 16, 2018
Tweet
Share
More Decks by Kir Shatrov
See All by Kir Shatrov
Operating Rails in Kubernetes
kirs
3
480
RailsClub 2016
kirs
2
310
Performance regressions in Ruby on Rails Core
kirs
0
210
Building a toolkit to detect performance regressions in Ruby on Rails core
kirs
3
5.8k
Развертывание веб-приложений и фреймворк Capistrano
kirs
1
280
Capistrano 3
kirs
4
2.8k
Other Decks in Programming
See All in Programming
C-Shared Buildで突破するAI Agent バックテストの壁
po3rin
0
370
令和最新版Android Studioで化石デバイス向けアプリを作る
arkw
0
380
DSPy Meetup Tokyo #1 - はじめてのDSPy
masahiro_nishimi
1
160
Microservices Platforms: When Team Topologies Meets Microservices Patterns
cer
PRO
1
1k
複数人でのCLI/Infrastructure as Codeの暮らしを良くする
shmokmt
5
2.2k
無秩序からの脱却 / Emergence from chaos
nrslib
2
13k
Microservices rules: What good looks like
cer
PRO
0
1.1k
AIエージェントを活かすPM術 AI駆動開発の現場から
gyuta
0
350
안드로이드 9년차 개발자, 프론트엔드 주니어로 커리어 리셋하기
maryang
1
110
Rediscover the Console - SymfonyCon Amsterdam 2025
chalasr
2
160
AIコーディングエージェント(NotebookLM)
kondai24
0
170
Integrating WordPress and Symfony
alexandresalome
0
140
Featured
See All Featured
Designing Experiences People Love
moore
143
24k
Into the Great Unknown - MozCon
thekraken
40
2.2k
It's Worth the Effort
3n
187
29k
Music & Morning Musume
bryan
46
7k
Scaling GitHub
holman
464
140k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.7k
Learning to Love Humans: Emotional Interface Design
aarron
274
41k
Making Projects Easy
brettharned
120
6.5k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
A designer walks into a library…
pauljervisheath
210
24k
Art, The Web, and Tiny UX
lynnandtonic
303
21k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
Transcript
Running Jobs at Scale Kir Shatrov GORUCO 2018, @kirshatrov
GORUCO 2018, @kirshatrov
GORUCO 2018, @kirshatrov
GORUCO 2018, @kirshatrov
GORUCO 2018, @kirshatrov
Jobs GORUCO 2018, @kirshatrov
class ExampleJob < ActiveJob::Base def perform ... end end GORUCO
2018, @kirshatrov
class ExampleJob < ActiveJob::Base def perform Product.all.find_each do |product| product.sync_and_refresh
end end end GORUCO 2018, @kirshatrov
class ExampleJob < ActiveJob::Base def perform Product.all.find_each do |product| product.sync_and_refresh
end end end minutes? hours? days? GORUCO 2018, @kirshatrov
Long-running jobs GORUCO 2018, @kirshatrov
Long-running jobs — Deploys and termination GORUCO 2018, @kirshatrov
Long-running jobs — Deploys and termination — Abort and re-enqueue
— Progress lost GORUCO 2018, @kirshatrov
GORUCO 2018, @kirshatrov
Long-running jobs — Deploys and termination — Abort and re-enqueue
— Progress lost — Job may never complete GORUCO 2018, @kirshatrov
Long-running jobs — Deploys and termination — Abort and re-enqueue
— Progress lost — Job may never complete — Capacity and worker starvation GORUCO 2018, @kirshatrov
Long-running jobs — Deploys and termination — Abort and re-enqueue
— Progress lost — Job may never complete — Capacity and worker starvation — Cloud ☁ GORUCO 2018, @kirshatrov
Why is it taking long? Because it iterates over a
long collection. GORUCO 2018, @kirshatrov
What if jobs were interruptible and resumable? GORUCO 2018, @kirshatrov
Split the job definition 1. Collection to process 2. Work
to be done GORUCO 2018, @kirshatrov
Split the job definition 1. Collection to process ≫ Product.all
2. Work to be done GORUCO 2018, @kirshatrov
Split the job definition 1. Collection to process ≫ Product.all
2. Work to be done ≫ product.sync_and_refresh GORUCO 2018, @kirshatrov
class ExampleJob < ActiveJob::Base include Iteration def collection Product.all end
def each_iteration(product) product.sync_and_refresh end end GORUCO 2018, @kirshatrov
— def perform — collection — each_iteration GORUCO 2018, @kirshatrov
Product.all cursor: 1 GORUCO 2018, @kirshatrov
Product.all cursor: 2 GORUCO 2018, @kirshatrov
Product.all cursor: 3 GORUCO 2018, @kirshatrov
Product.all cursor: 4 GORUCO 2018, @kirshatrov
Product.all cursor: 5 GORUCO 2018, @kirshatrov
Product.all cursor: 450123 GORUCO 2018, @kirshatrov
class WhateverJob < ActiveJob::Base include Iteration def collection Enumerator.new do
|enum| 3.times do |n| enum << n end end end def each_iteration(n) # do something three times! end end GORUCO 2018, @kirshatrov
Endless possibilities — Interrupt and resume at any moment —
Progress tracking — Parallel computations — Throttling by default GORUCO 2018, @kirshatrov
Benefits for the infrastructure — Keep supporting long-running jobs —
Success for Cloud runtime — Make scale invisible for developers — Opportunities to save money with short-living instances in Cloud GORUCO 2018, @kirshatrov
Thank you! @kirshatrov GORUCO 2018, @kirshatrov