forked from apache/storm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
STORM-350: Upgrade to newer version of disruptor
- Loading branch information
Robert (Bobby) Evans
committed
Oct 26, 2015
1 parent
f582b8f
commit 48c55c8
Showing
11 changed files
with
295 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
185 changes: 185 additions & 0 deletions
185
examples/storm-starter/src/jvm/storm/starter/FastWordCountTopology.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package storm.starter; | ||
|
||
import backtype.storm.Config; | ||
import backtype.storm.StormSubmitter; | ||
import backtype.storm.generated.*; | ||
import backtype.storm.spout.SpoutOutputCollector; | ||
import backtype.storm.task.TopologyContext; | ||
import backtype.storm.topology.BasicOutputCollector; | ||
import backtype.storm.topology.IRichBolt; | ||
import backtype.storm.topology.OutputFieldsDeclarer; | ||
import backtype.storm.topology.TopologyBuilder; | ||
import backtype.storm.topology.base.BaseBasicBolt; | ||
import backtype.storm.topology.base.BaseRichSpout; | ||
import backtype.storm.tuple.Fields; | ||
import backtype.storm.tuple.Tuple; | ||
import backtype.storm.tuple.Values; | ||
import backtype.storm.utils.NimbusClient; | ||
import backtype.storm.utils.Utils; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Random; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
/** | ||
* WordCount but teh spout does not stop, and the bolts are implemented in | ||
* java. This can show how fast the word count can run. | ||
*/ | ||
public class FastWordCountTopology { | ||
public static class FastRandomSentenceSpout extends BaseRichSpout { | ||
SpoutOutputCollector _collector; | ||
Random _rand; | ||
|
||
@Override | ||
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) { | ||
_collector = collector; | ||
_rand = ThreadLocalRandom.current(); | ||
} | ||
|
||
@Override | ||
public void nextTuple() { | ||
String[] sentences = new String[]{ "the cow jumped over the moon", "an apple a day keeps the doctor away", | ||
"four score and seven years ago", "snow white and the seven dwarfs", "i am at two with nature" }; | ||
String sentence = sentences[_rand.nextInt(sentences.length)]; | ||
_collector.emit(new Values(sentence), sentence); | ||
} | ||
|
||
@Override | ||
public void ack(Object id) { | ||
//Ignored | ||
} | ||
|
||
@Override | ||
public void fail(Object id) { | ||
_collector.emit(new Values(id), id); | ||
} | ||
|
||
@Override | ||
public void declareOutputFields(OutputFieldsDeclarer declarer) { | ||
declarer.declare(new Fields("sentence")); | ||
} | ||
} | ||
|
||
public static class SplitSentence extends BaseBasicBolt { | ||
@Override | ||
public void execute(Tuple tuple, BasicOutputCollector collector) { | ||
String sentence = tuple.getString(0); | ||
for (String word: sentence.split("\\s+")) { | ||
collector.emit(new Values(word, 1)); | ||
} | ||
} | ||
|
||
@Override | ||
public void declareOutputFields(OutputFieldsDeclarer declarer) { | ||
declarer.declare(new Fields("word", "count")); | ||
} | ||
} | ||
|
||
public static class WordCount extends BaseBasicBolt { | ||
Map<String, Integer> counts = new HashMap<String, Integer>(); | ||
|
||
@Override | ||
public void execute(Tuple tuple, BasicOutputCollector collector) { | ||
String word = tuple.getString(0); | ||
Integer count = counts.get(word); | ||
if (count == null) | ||
count = 0; | ||
count++; | ||
counts.put(word, count); | ||
collector.emit(new Values(word, count)); | ||
} | ||
|
||
@Override | ||
public void declareOutputFields(OutputFieldsDeclarer declarer) { | ||
declarer.declare(new Fields("word", "count")); | ||
} | ||
} | ||
|
||
public static void printMetrics(Nimbus.Client client, String name) throws Exception { | ||
ClusterSummary summary = client.getClusterInfo(); | ||
String id = null; | ||
for (TopologySummary ts: summary.get_topologies()) { | ||
if (name.equals(ts.get_name())) { | ||
id = ts.get_id(); | ||
} | ||
} | ||
if (id == null) { | ||
throw new Exception("Could not find a topology named "+name); | ||
} | ||
TopologyInfo info = client.getTopologyInfo(id); | ||
int uptime = info.get_uptime_secs(); | ||
long acked = 0; | ||
double weightedAvgTotal = 0.0; | ||
for (ExecutorSummary exec: info.get_executors()) { | ||
if ("spout".equals(exec.get_component_id())) { | ||
SpoutStats stats = exec.get_stats().get_specific().get_spout(); | ||
Map<String, Long> ackedMap = stats.get_acked().get(":all-time"); | ||
Map<String, Double> avgLatMap = stats.get_complete_ms_avg().get(":all-time"); | ||
for (String key: ackedMap.keySet()) { | ||
long ackVal = ackedMap.get(key); | ||
double latVal = avgLatMap.get(key) * ackVal; | ||
acked += ackVal; | ||
weightedAvgTotal += latVal; | ||
} | ||
} | ||
} | ||
double avgLatency = weightedAvgTotal/acked; | ||
System.out.println("uptime: "+uptime+" acked: "+acked+" avgLatency: "+avgLatency+" acked/sec: "+(((double)acked)/uptime)); | ||
} | ||
|
||
public static void kill(Nimbus.Client client, String name) throws Exception { | ||
KillOptions opts = new KillOptions(); | ||
opts.set_wait_secs(0); | ||
client.killTopologyWithOpts(name, opts); | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
|
||
TopologyBuilder builder = new TopologyBuilder(); | ||
|
||
builder.setSpout("spout", new FastRandomSentenceSpout(), 4); | ||
|
||
builder.setBolt("split", new SplitSentence(), 4).shuffleGrouping("spout"); | ||
builder.setBolt("count", new WordCount(), 4).fieldsGrouping("split", new Fields("word")); | ||
|
||
Config conf = new Config(); | ||
conf.registerMetricsConsumer(backtype.storm.metric.LoggingMetricsConsumer.class); | ||
|
||
String name = "wc-test"; | ||
if (args != null && args.length > 0) { | ||
name = args[0]; | ||
} | ||
|
||
conf.setNumWorkers(1); | ||
StormSubmitter.submitTopologyWithProgressBar(args[0], conf, builder.createTopology()); | ||
|
||
Map clusterConf = Utils.readStormConfig(); | ||
clusterConf.putAll(Utils.readCommandLineOpts()); | ||
Nimbus.Client client = NimbusClient.getConfiguredClient(clusterConf).getClient(); | ||
|
||
//Sleep for 5 mins | ||
for (int i = 0; i < 10; i++) { | ||
Thread.sleep(30 * 1000); | ||
printMetrics(client, name); | ||
} | ||
kill(client, name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.