Storm-package: Write Storm Bolts in R using the Storm Multi-Language...

Description Details Author(s) References Examples

Description

Storm is a distributed real-time computation system. Similar to how Hadoop provides a set of general primitives for doing batch processing, Storm provides a set of general primitives for doing real-time computation.

Storm includes a “Multi-Language” (or “Multilang”) Protocol to allow implementation of Bolts and Spouts in languages other than Java. This R extension provides implementations of utility functions to allow an application developer to focus on application-specific functionality rather than Storm/R communications plumbing.

Details

Package: Storm
Type: Package
Version: 1.2
Date: 2012-12-25
License: GPL version 2 or newer
LazyLoad: yes

From Storm's point of view, it creates an R process to consume and produce Tuples. Storm communicates with R using a JSON-like format. Storm writes Tuples via STDIN, and reads Tuples from R via STDOUT. The Storm package implements several functions to take care of Storm/R I/O.

As the application programmer, you implement a single function with signature:v “function(s=Storm, t=Tuple)” that will be called once per Tuple. Inside this function, you can emit zero or more Tuples, as well as emit other status messages, such as failures and diagnostic messages.

To use this extension, briefly:

1. create a new Storm object.
2. define a function that can process and emit Tuple objects.
3. call the run() method on the Storm object.

A detailed example is given in the examples section.

Author(s)

Allen Day Maintainer: Allen Day <allenday@allenday.com>

References

Storm - https://github.com/nathanmarz/storm/wiki Storm Multi-Language Protocol - https://github.com/nathanmarz/storm/wiki/Multilang-protocol

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#library(Storm)
#source("Storm/R/Storm.R")

#create a Storm object
storm = Storm$new();

#by default it has a handler that logs that the tuple was skipped.
#let's replace it that with something more interesting and equally
#useless.

storm$lambda = function(s) {
  #argument 's' is the Storm object.

  #get the current Tuple object.
  t = s$tuple;

  #optional: acknowledge receipt of the tuple.
  s$ack(t);

  #optional: log a message.
  s$log(c("processing tuple=",t$id));

  #create contrived tuples to illustrate output.

  #create 1st tuple...
  t$output = vector(mode="character",length=1);
  t$output[1] = as.numeric(t$input[3])+as.numeric(t$input[4]);
  #...and emit it.
  s$emit(t);

  #create 2nd tuple...
  t$output[1] = as.numeric(t$input[3])-as.numeric(t$input[4]);
  #...and emit it.
  s$emit(t);

  #alternative/optional: mark the tuple as failed.
  s$fail(t);
};

#enter the main tuple-processing loop.
storm$run();

#proton:R allenday$ cat Storm/eg/example.txt 
#{
#  "id": "-6955786537413359385",
#  "comp": "1",
#  "stream": "1",
#  "task": 9,
#  "tuple": ["snow white and the seven dwarfs", "field2", 3, 4]
#}
#end
#proton:R allenday$ cat Storm/eg/example.txt | Storm/eg/example.r 
#{
#  "command": "ack",
#  "id": "-6955786537413359385"
#}
#end
#{
#	"command": "log",
#	"msg": "processing tuple=-6955786537413359385"
#}
#end
#{
#	"command": "emit",
#	"anchors": [],
#	"stream": "1",
#	"task": "9",
#	"tuple": ["7"],
#}
#end
#{
#	"command": "emit",
#	"anchors": [],
#	"stream": "1",
#	"task": "9",
#	"tuple": ["-1"],
#}
#end
#{
#	"command": "fail",
#	"id": "-6955786537413359385"
#}
#end

Example output

Loading required package: permute
Loading required package: rjson
{"pid": 6985}
end
{"command": "emit", "anchors": [], "tuple": ["bolt initializing"]}
end

Storm documentation built on May 2, 2019, 8:54 a.m.