This repository has been archived by the owner on Dec 31, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathREADME
303 lines (236 loc) · 9.74 KB
/
README
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
GNIP STREAM - COLLECTOR METRICS
Command line tool for:
* Saving JSON stream of activities to disk in date-ordered directory tree
* See real-time rule production
* See real-time token frequency (uses redis store)
* Measure social media latency (time from creation time stamp to delivery)
Requires Python urllib2 and, for token frequency, Redis and the python
redis module.
The tool is driven from a config file named gnip.cfg. To get started,
enter your Gnip login credentials and stream URL and choose the tool
function you desire.
Usage:
All examples run with Gnip Powertrack rule set:
tebow
broncos
football
win
gnip
beer -root
Example 1: Rule production rates
--------------------------------
In gnip.cfg, set
...
# print out rule production rates
processtype=rules
...
Scott-Hendricksons-MacBook-Pro ~/IdeaProjects/RuleProduction/src> ./GnipStreamCollectorMetrics.py
(2012-01-06 13:07:53.989700) sample 154 tweets (20 seconds)
win: .......... ( 91 tweets matched) 4.4592 tweets/second
football: ..... ( 35 tweets matched) 1.7151 tweets/second
beer -root: ... ( 24 tweets matched) 1.1761 tweets/second
tebow: ........ ( 5 tweets matched) 0.2450 tweets/second
(2012-01-06 13:08:14.484888) sample 158 tweets (20 seconds)
win: .......... ( 95 tweets matched) 4.6359 tweets/second
football: ..... ( 28 tweets matched) 1.3664 tweets/second
beer -root: ... ( 24 tweets matched) 1.1712 tweets/second
tebow: ........ ( 9 tweets matched) 0.4392 tweets/second
broncos: ...... ( 5 tweets matched) 0.2440 tweets/second
(2012-01-06 13:08:34.731178) sample 162 tweets (20 seconds)
win: .......... ( 110 tweets matched) 5.4359 tweets/second
football: ..... ( 28 tweets matched) 1.3837 tweets/second
beer -root: ... ( 21 tweets matched) 1.0378 tweets/second
broncos: ...... ( 2 tweets matched) 0.0988 tweets/second
tebow: ........ ( 2 tweets matched) 0.0988 tweets/second
(2012-01-06 13:08:55.285500) sample 189 tweets (20 seconds)
win: .......... ( 110 tweets matched) 5.3634 tweets/second
beer -root: ... ( 39 tweets matched) 1.9016 tweets/second
football: ..... ( 35 tweets matched) 1.7065 tweets/second
tebow: ........ ( 4 tweets matched) 0.1950 tweets/second
broncos: ...... ( 1 tweets matched) 0.0488 tweets/second
(2012-01-06 13:09:15.276119) sample 176 tweets (20 seconds)
win: .......... ( 111 tweets matched) 5.5474 tweets/second
football: ..... ( 35 tweets matched) 1.7492 tweets/second
beer -root: ... ( 18 tweets matched) 0.8996 tweets/second
tebow: ........ ( 8 tweets matched) 0.3998 tweets/second
broncos: ...... ( 5 tweets matched) 0.2499 tweets/second
...
The parameter "rollduration" sets the time between reports. You may need to adjust this based
on the productivity of your rule set.
Example 2: English token frequency (Requires redis)
---------------------------------------------------
Start your local redis server and perform a "flushall" to clear the database.
In gnip.cfg, set
...
# store stream contents in redis
processtype=redis
...
Start the client:
Scott-Hendricksons-MacBook-Pro ~/IdeaProjects/RuleProduction/src> ./GnipStreamCollectorMetrics.py
(no output expected)
...
To see token frequencies, let the client run for a few minutes to collect data. Then run the
RedisFreq.py tool to see what is stored in redis. The token counts accumulated in the
redis store decay over 90 seconds so the store will reach steady state size after a few minutes.
You can monitor redis with a variety of tools. For example, with
the redis-cli tool is include with redis. Execute the command "dbsize"
to see the number of keys in the store. Like this:
redis 127.0.0.1:6379> dbsize
(integer) 4097
redis 127.0.0.1:6379>
This shows that there are 4097 redis keys in the store.
Running the RedisFreq.py script after a few minutes gives the 100 more frequent
tokens from the redis store. A sample of the counts and fractions
first few tokens is shown below. This data shows 15627 tokens counted with
"win" being the most common and comprising about 6% of the tokens counted.
(Edit the stopwords list in the script "Redis.py" if you want to
include/exclude different tokens.)
Scott-Hendricksons-MacBook-Pro ~/IdeaProjects/RuleProduction/src> ./RedisFreq.py
TotalTokensCount ......... 15627 (1.00000)
TotalRuleMatchCount ...... 1613 (0.10322)
win ...................... 1006 (0.06438)
football ................. 286 (0.01830)
beer ..................... 237 (0.01517)
follow ................... 124 (0.00793)
chance ................... 109 (0.00698)
giveaway ................. 99 (0.00634)
free ..................... 99 (0.00634)
please ................... 73 (0.00467)
enter .................... 69 (0.00442)
new ...................... 66 (0.00422)
game ..................... 64 (0.00410)
out ...................... 55 (0.00352)
play ..................... 54 (0.00346)
good ..................... 50 (0.00320)
tebow .................... 47 (0.00301)
team ..................... 46 (0.00294)
today .................... 45 (0.00288)
tonight .................. 44 (0.00282)
one ...................... 44 (0.00282)
2012 ..................... 43 (0.00275)
last ..................... 41 (0.00262)
via ...................... 40 (0.00256)
want ..................... 40 (0.00256)
love ..................... 39 (0.00250)
lol ...................... 39 (0.00250)
time ..................... 39 (0.00250)
day ...................... 38 (0.00243)
thanks ................... 38 (0.00243)
over ..................... 38 (0.00243)
see ...................... 37 (0.00237)
...
The redis store also contains rule match counts. Rules are stored in redis as strings
surrounded by "[...]". To see rule counts with redis-cli:
redis 127.0.0.1:6379> get "[tebow]"
"127"
redis 127.0.0.1:6379> get "[win]"
"2240"
redis 127.0.0.1:6379> get "[football]"
"675"
redis 127.0.0.1:6379>
...
Example 3: Latency measurements
--------------------------------
Latency estimates in this case include the python processes (and inherent variability) but
will give some idea of an application can accomplish. It should be fairly straight forward
to build an application that beats these measurements.
The latency data is output to standard out the measurement for each activity on a separate
line.
Be sure to set the rollduration to 1 sec. The rollduration is
included in the measured latency.
In gnip.cfg, set
...
rollduration=1
...
Scott-Hendricksons-MacBook-Pro ~/IdeaProjects/RuleProduction/src> ./GnipStreamCollectorMetrics.py
2012-01-06 20:25:52.841085, 10.841085
2012-01-06 20:25:52.849420, 10.849420
2012-01-06 20:25:52.851427, 10.851427
2012-01-06 20:25:53.954821, 11.954821
2012-01-06 20:25:53.957109, 11.957109
2012-01-06 20:25:53.959620, 12.959620
2012-01-06 20:25:53.962573, 14.962573
2012-01-06 20:25:53.964144, 11.964144
2012-01-06 20:25:53.965350, 11.965350
2012-01-06 20:25:53.966468, 11.966468
2012-01-06 20:25:53.967509, 11.967509
2012-01-06 20:25:53.968822, 12.968822
2012-01-06 20:25:53.970103, 11.970103
2012-01-06 20:25:53.971735, 10.971735
2012-01-06 20:25:55.282562, 13.282562
2012-01-06 20:25:55.285407, 13.285407
2012-01-06 20:25:55.287489, 12.287489
2012-01-06 20:25:55.289636, 13.289636
...
In the sample shown, the average latency is around 12 s. Gnip documentations estimates
that the stream enhancement adds about 10s of latency on average. The
GnipStreamCollectorMetrics.py adds approximately 1.5s on average.
An R utility is provided to create boxplots of latencies. (See ./R/plotLatency.r)
Example 4: Files
-----------------
To store data in files, edit gnip.cfg to set the appropriate rollduration and set
the filepath. Don't forget to set the processtype to "files"
...
filepath=/Users/scotthendrickson/IdeaProjects/RuleProduction/data
...
...
# store stream contents in files by year, month, day, hour, min
processtype=files
...
Run script.
Scott-Hendricksons-MacBook-Pro ~/IdeaProjects/RuleProduction/src> ./GnipStreamCollectorMetrics.py
(no output expected)
When you look in the data path:
Scott-Hendricksons-MacBook-Pro ~/IdeaProjects/RuleProduction/data> tree
.
└── 2012
└── 01
└── 06
└── 14
├── Powertrack_201201061448497544.gz
├── Powertrack_201201061448783761.gz
└── Powertrack_201201061449705606.gz
...
New directories will be created for every hour. Here the rollduration is set to
60s so a new file is created every minute.
If your input stream is JSON-formated, you can additionally parse it with Gnacs before writing to disk:
...
# store stream contents in files by year, month, day, hour, min
processtype=files-gnacs
...
Your cfg file must have a [gnacs] block, with a mandatory parameter 'delim' and an optional parameter
'options', which sets the Gnacs options.
...
[gnacs]
options=gulist
delim=|
,,,
When using 'files-gnacs', the output directory structure and files names are the same as for 'files'.
Example 5: Rules
-----------------
To store counts of rule matches, edit gnip.cfg to set the appropriate rollduration and set
the filepath. Set the processtype to "rules". The output will have the same structure as
"file" and "file-gnacs".
...
filepath=/Users/scotthendrickson/IdeaProjects/RuleProduction/data
...
...
processtype=rules
...
Run script.
Scott-Hendricksons-MacBook-Pro ~/IdeaProjects/RuleProduction/src> ./GnipStreamCollectorMetrics.py
(no output expected)
When you look in the data path:
Scott-Hendricksons-MacBook-Pro ~/IdeaProjects/RuleProduction/data> tree
.
└── 2012
└── 01
└── 06
└── 14
├── Powertrack_201201061448497544.counts
├── Powertrack_201201061448783761.counts
└── Powertrack_201201061449705606.counts
...
New directories will be created for every hour. Here the rollduration is set to
60s so a new file is created every minute.
Enjoy!