Created: 2011-07-18 07:42
Updated: 2018-11-29 06:30
License: mit

ASAP - a Parallel Fetch Library

by Greg Spurrier, Avik Das


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.


Assume that a server is running on, 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 '' do |followers|
    followers = followers.split("\n").map(&:to_i)

    # get the first 3 followers
    get "{followers[0]}"
    get "{followers[1]}"
    get "{followers[2]}"

    # or you can use a map
    followers[3,2].each do |fi|
      get "{fi}"

p data

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


gem install asap


# Check out repository
git clone 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)

# 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).
Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more