Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Running Jobs at Scale

Running Jobs at Scale

My talk from GORUCO 2018 in New York.

Kir Shatrov

June 16, 2018
Tweet

More Decks by Kir Shatrov

Other Decks in Programming

Transcript

  1. Long-running jobs — Deploys and termination — Abort and re-enqueue

    — Progress lost — Job may never complete GORUCO 2018, @kirshatrov
  2. Long-running jobs — Deploys and termination — Abort and re-enqueue

    — Progress lost — Job may never complete — Capacity and worker starvation GORUCO 2018, @kirshatrov
  3. Long-running jobs — Deploys and termination — Abort and re-enqueue

    — Progress lost — Job may never complete — Capacity and worker starvation — Cloud ☁ GORUCO 2018, @kirshatrov
  4. Why is it taking long? Because it iterates over a

    long collection. GORUCO 2018, @kirshatrov
  5. Split the job definition 1. Collection to process ≫ Product.all

    2. Work to be done GORUCO 2018, @kirshatrov
  6. Split the job definition 1. Collection to process ≫ Product.all

    2. Work to be done ≫ product.sync_and_refresh GORUCO 2018, @kirshatrov
  7. class ExampleJob < ActiveJob::Base include Iteration def collection Product.all end

    def each_iteration(product) product.sync_and_refresh end end GORUCO 2018, @kirshatrov
  8. 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
  9. Endless possibilities — Interrupt and resume at any moment —

    Progress tracking — Parallel computations — Throttling by default GORUCO 2018, @kirshatrov
  10. 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