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
Running Jobs at Scale
Search
Kir Shatrov
June 16, 2018
Programming
0
180
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
2
390
RailsClub 2016
kirs
2
300
Performance regressions in Ruby on Rails Core
kirs
0
190
Building a toolkit to detect performance regressions in Ruby on Rails core
kirs
3
5k
Развертывание веб-приложений и фреймворк Capistrano
kirs
1
260
Capistrano 3
kirs
4
2.5k
Other Decks in Programming
See All in Programming
PostmanでAPIの動作確認が楽になった話
h455h1
0
180
MetricKitで予期せぬ終了を検知する話 / Detect unexpected termination with MetricKit
nekowen
1
200
AmperとFleetを使ったAndroidアプリ
yoppie
0
260
Exploring the Implementation of “t.Run”, “t.Parallel”, and “t.Cleanup”
akarin
1
120
Ruby Pattern Matching
bkuhlmann
0
930
Komplexe Oberflächen mit SVG und der Web Animation API
joergneumann
0
680
単体テストを書かない技術 #phpcon_odawara
o0h
PRO
27
8.5k
VS Code をプロダクトにどう取り込むか
onomax
1
730
Domain-Driven Transformation
hschwentner
2
1.5k
使ってみよう Azure AI Document Intelligence
kosmosebi
2
360
効率化に挑戦してみたらモバイル開発が少し快適になった話
ryunakayama
0
140
GitHub Copilotのススメ
marcy731
1
230
Featured
See All Featured
The Language of Interfaces
destraynor
151
23k
How STYLIGHT went responsive
nonsquared
92
4.8k
Building Better People: How to give real-time feedback that sticks.
wjessup
356
18k
Web development in the modern age
philhawksworth
203
10k
Git: the NoSQL Database
bkeepers
PRO
423
63k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
21
1.4k
Building Applications with DynamoDB
mza
88
5.6k
GraphQLの誤解/rethinking-graphql
sonatard
55
9.3k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
26
2.3k
No one is an island. Learnings from fostering a developers community.
thoeni
16
2.1k
Imperfection Machines: The Place of Print at Facebook
scottboms
261
12k
Building Flexible Design Systems
yeseniaperezcruz
320
37k
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