Git Product home page Git Product logo

dirq-r's Introduction

dirq - A Filesystem Directory Based Queue

A port of Perl module [Directory::Queue::Simple] (http://search.cpan.org/dist/Directory-Queue/) The goal of this package is to offer a simple queue system using the underlying filesystem for storage, security and to prevent race conditions via atomic operations.

A simple producer:

# Define a path to your queue
# In production, you wouldn't use a temporary directory!
path <- tempfile()
# Create a new queue or recover an existing one
q <- dirq(path)
cat(paste("top level directory is", q$path(), "\n"))
#> top level directory is /tmp/RtmpJDLM7b/file29f13413268dd
# Add some messages
for (i in seq.int(1, 6)) {
  name <- q$add(list(data = paste("element", i)), format = "json")
  cat(paste("added element", name, "\n"))
}
#> added element 657CEE98/657CEE9A75DCE4 
#> added element 657CEE98/657CEE9A76AFC4 
#> added element 657CEE98/657CEE9A775C24 
#> added element 657CEE98/657CEE9A784004 
#> added element 657CEE98/657CEE9A790224 
#> added element 657CEE98/657CEE9A79B3A4

A simple consumer:

# Recover the previous queue
q <- dirq(path)
# Get the first element in the queue
cursor <- q$iter_first()
while (!is.null(cursor)) {
  if (q$lock(cursor)) {
    cat(paste("reading element", cursor, "\n"))
    data <- q$get(cursor, format = "json")
    q$remove(cursor)
    # Or use q$unlock(cursor) to just peek at data
  }
  # Get the next element in the queue
  cursor <- q$iter_next(cursor)
}
#> reading element 657CEE98/657CEE9A75DCE4 
#> reading element 657CEE98/657CEE9A76AFC4 
#> reading element 657CEE98/657CEE9A775C24 
#> reading element 657CEE98/657CEE9A784004 
#> reading element 657CEE98/657CEE9A790224 
#> reading element 657CEE98/657CEE9A79B3A4

Similar work

txtq

Will Landau’s txtq is also a pure filesystem-based queue.

liteq

Gábor Csárdi’s liteq package offers essentially the same functionality implemented with SQLite. It has a some additional features, such as the ability to detect crashed workers and re-queue failed messages, but it was in an early stage of development at the time dirq was released.

Other message queues

There is a plethora of message queues beyond R, most notably ZeroMQ and RabbitMQ. In fact, Jeroen Ooms and Whit Armstrong maintain rzmq, a package to work with ZeroMQ from R. Even in this landscape, dirq has advantages.

  1. The dirq user interface is friendly, and its internals are simple. No prior knowledge of sockets or message-passing is required.
  2. dirq is lightweight, R-focused, and easy to install. It only depends on R and a few packages on CRAN.
  3. Because dirq it is file-based, the queue persists even if your work crashes.

dirq-r's People

Contributors

pzingg 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.