Code Monkey home page Code Monkey logo

flame's Introduction

Imagine if we could auto scale simply by wrapping any existing app code in a function and have that block of code run in a temporary copy of the app.

Enter the FLAME pattern.

FLAME - Fleeting Lambda Application for Modular Execution

With FLAME, you treat your entire application as a lambda, where modular parts can be executed on short-lived infrastructure.

Check the screencast to see it in action:

Video

You can wrap any block of code in a FLAME.call and it will find or boot a copy of the app, execute the work there, and return the results:

def generate_thumbnails(%Video{} = vid, interval) do
  FLAME.call(MyApp.FFMpegRunner, fn ->
    # I'm runner on a short-lived, temporary server
    tmp_dir = Path.join(System.tmp_dir!(), Ecto.UUID.generate())
    File.mkdir!(tmp_dir)
    System.cmd("ffmpeg", ~w(-i #{vid.url} -vf fps=1/#{interval} #{tmp_dir}/%02d.png))
    urls = VideoStore.put_thumbnails(vid, Path.wildcard(tmp_dir <> "/*.png"))
    Repo.insert_all(Thumbnail, Enum.map(urls, &%{video_id: vid.id, url: &1}))
  end)
end

Here we wrapped up our CPU expensive ffmpeg operation in a FLAME.call/2. FLAME accepts a function and any variables that the function closes over. In this example, the %Video{} struct and interval are passed along automatically. The work happens in a temporary copy of the app. We can do any work inside the FLAME call because we are running the entire application, database connection(s) and all.

FLAME provides the following interfaces for elastically scaled operations:

  • FLAME.call/2 - used for synchronous calls
  • FLAME.cast/2 - used for async casts where you don't need to wait on the results
  • FLAME.place_child/3 โ€“ used for placing a child spec somewhere to run, in place of DynamicSupervisor.start_child, Task.Supervisor.start_child, etc

The FLAME.Pool handles elastically scaling runners up and down, as well as remote monitoring of resources. Check the moduledoc for example usage.

flame's People

Contributors

alizain avatar chrismccord avatar dannielb avatar dlederle avatar grzuy avatar jeregrine avatar joeljuca avatar josevalim avatar mcrumm avatar pgeraghty avatar seanmor5 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.