Giter Site home page Giter Site logo

spawn_viewer's Introduction

Spawn Viewer

Trial implementation to visualize process spawning. It uses phoenix web server.

Usage

$ git clone https://github.com/parroty/spawn_viewer
$ cd spawn_viewer
$ mix deps.get
$ mix compile
$ mix phoenix.server

Then, open http://localhost:4000 in the browser. In the browser, select a function and click Execute to draw the graph.

Sample

htmlimage

defmodule Runner.ParallelHttp do
  @moduledoc """
  Spawn processes which sends http get requests.
  """

  use Runner.Base

  @urls ["http://www.google.com",    "http://www.google.co.jp",
         "http://www.google.com.au", "http://www.google.ch",
         "http://www.google.cn",     "http://www.google.ru"]

  def run(actor) do
    parent = self

    Enum.map(@urls, fn(url) ->
      spawn_link(fn ->
        event_start(actor, self, tag: url)

        send parent, {self, HTTPotion.get(url)}

        event_end(actor, self)
      end)
    end)

    wait_events(Enum.count(@urls))
  end
end

Functions

Runner.RandomSleep

Spawn processes which just sleep random time and then exit.

Runner.Chain

Spawn processes which gets a value from child process, and then returns an incremented value.

Runner.ParallelHttp

Spawn processes which sends http get requests. The reqeusts are executed in parallel.

Runner.BinaryTree

Spawn processes which braches into 2 new processes until it reaches specified height.

Runner.Poolboy

Spawn processes which checkout worker from the pool and do some work. When number of running workers exeed the pool size, the following processes wait for the completion of previous ones.

Runner.PingPong

Spawn process to communicate each other to count-down a number.

Runner.TimeoutAfter

Spawn process to wait a message with after keyword. The logic in the after section is regularly executed until the completion message is received from the child.

Runner.Stream

Spawn processes to calculate value through stream and enum. Stream iteratively processes each value in the list, and Enum waits for the entire list to complete.

Runner.MapReducer

Parallel map-reducer, with two different types of reducer. Mapper just waits for some time and return values, and reducer accumulates returned values.

Runner.Supervisor

Spawn child processes and worker which are monitored by supervisors. When worker is crashed, it's automatically restarted by supervisor, and tries to restore the status from the stash.

Notes

  • Runner.Base module defines some helper functions to trigger events for the monitoring.
    • event_start and event_end functions take a pid (ex. self) to monitor, and a actor to store the monitoring results (which is passed as run function argument).
    • event_marker function allows to put a marker in the graph for the pid and the timing.
  • :timer.sleep call is inserted for some locations for graph visualization purpose.

spawn_viewer's People

Contributors

parroty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

holsee

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.