GithubHelp home page GithubHelp logo

alexxnica / asap Goto Github PK

View Code? Open in Web Editor NEW

This project forked from avik-das/asap

0.0 1.0 0.0 792 KB

A JRuby library providing an eDSL to specify a dependency tree of resources to fetch, possibly in parallel

License: MIT License

Ruby 100.00%

asap's Introduction

ASAP - a Parallel Fetch Library

by Greg Spurrier, Avik Das

DESCRIPTION

ASAP is a JRuby library built on top of Netty and Java's NIO classes. It provides an embedded domain specific language for specifying a list of resources to fetch, all in parallel, as well specify a dependency tree in order to use previous results in calculating subsequent ones. The results of all the requests are then automatically collected into a simple tree-like data structure that has a one-to-one mapping to the tree structure specified by the code, despite the fact that results may arrive in an unspecified order.

EXAMPLE

Assume that a server is running on http://0.0.0.0:1234, which maps the paths /user/followers and /user/followers/N to a list of five numbers and data related to the Nth follower respectively. (This is implemented by asap-mongrel-test-server.)

require 'rubygems'
require 'asap'

data = Asap do
  get 'http://0.0.0.0:1234/user/followers' do |followers|
    followers = followers.split("\n").map(&:to_i)

    # get the first 3 followers
    get "http://0.0.0.0:1234/user/followers/#{followers[0]}"
    get "http://0.0.0.0:1234/user/followers/#{followers[1]}"
    get "http://0.0.0.0:1234/user/followers/#{followers[2]}"

    # or you can use a map
    followers[3,2].each do |fi|
      get "http://0.0.0.0:1234/user/followers/#{fi}"
    end
  end
end

p data

# => [['93\n5\n64\n74\n11',
        ['Follower #93',
         'Follower #5' ,
         'Follower #64',
         'Follower #74',
         'Follower #11']]]

QUICK START

gem install asap

DEVELOPMENT QUICK START

# Check out repository
git clone git://github.com/avik-das/asap.git
cd asap

# Make sure you're using JRuby

# Install the dependencies
gem install bundler
bundle install
rake install

# start the server (run in a separate window)
asap-mongrel-test-server

# run the tests
rake spec

# compare the times required to fetch the same data if it is retrieved
# serially versus if it is retrieved with ASAP.
time examples/followers-example-serial.rb
time examples/followers-example.rb

# There is an alternate, EventMachine-based server, but it does not
# implement the /user/followers/ routes. EventMachine does not run
# well with JRuby, while the main library requires JRuby. However,
# the EventMachine-based server runs well on MRI, assuming the
# correct gems are installed (see the gemspec).
script/em_test_server.rb

asap's People

Contributors

avik-das avatar

Watchers

 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.