storm

nimbus
British [?n?mb?s] American [?n?mb?s]
n.
(Large) rain cloud; halo

strom distributed real-time streaming computing framework

strom is on the right side of the figure below. Come and process one piece of data. The amount of data processed in a unit time cannot be too large to ensure its normal operation, but once it is started, it runs all the time.
Batch processing is different. Spark is the computing framework of the micro-batch processing framework, which can also achieve real-time performance.
MR can't achieve real-time performance, the order of magnitude is TB, PB level, frequent disk operation, frequent start and stop jobs.

 share picture

 

< p>

Share a picture

< p>Share a picture

< p> Share a picture

< p> Share a picture

< p>

share picture

 ETL (data cleaning) extracted transform load
Spout
British [spa?t] Beautiful [spa?t]
Spout; spout; spout; spout; tornado
bolt
British [b??lt] American [bo?lt]
n.
(For doors and windows) bolts, insert v.
bolt with a pin; can be bolted; fix (A and B) together with a bolt; (horse, etc. are frightened)
adv.
Suddenly; like an arrow; upright

Nimbus is similar to master
supervisor is similar to slave 
worker task

  

 share picture

Share a picture

Share a picture

 share picture

share picture

share picture

share picture

share picture

share picture

share picture

share picture

share picture

The ack mechanism cannot guarantee that the data will not be recalculated, but it can guarantee that the data will be processed correctly at least once. (May be calculated twice due to an error, causing non-error data retransmission)

package com.sxt.storm.ack;


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Map;

import backtype.storm.spout.SpoutOutputCollector;
import backtype.storm.task.TopologyContext;
import backtype.storm.topology.IRichSpout;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.tuple.Fields;
import backtype.storm.tuple.Values;

public class MySpout implements IRichSpout{

private static final long serialVersionUID = 1L;

int index = 0;

FileInputStream fis;
InputStreamReader isr;
BufferedReader br;
SpoutOutputCollector collector = null;
String str = null;

@Override
public void nextTuple() {
try {
if ((str = this.br.readLine()) != null) {
// filter action
index++;
collector.emit(new Values(str), index);
// collector.emit(new Values(str));
}
} catch (Exception e) {
}


}
@Override
public void close() {
try {
br.close();
isr.close();
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void open(Map conf, TopologyContext context,
SpoutOutputCollector collector) {
try {
this.collector = collector;
this.fis = new FileInputStream("track.log");
this.isr = new InputStreamReader(fis, "UTF-8");
this.br = new BufferedReader(isr);
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
declarer.declare(new Fields("log"));
}

@Override
public Map getComponentConfiguration() {
return null;
}

@Override
public void ack(Object msgId) {
System.err.println(" [" + Thread.currentThread().getName() + "] "+ "spout ack:"+msgId.toString());
}

@Override
public void activate() {

}

@Override
public void deactivate() {

}

@Override
public void fail(Object msgId) {
System.err.println(" [" + Thread.currentThread().getName() + "] "+ "spout fail:"+msgId.toString());
}

}

package com.sxt.storm.ack;

import java.util.Map;

import backtype.storm.task.OutputCollector;
import backtype.storm.task.TopologyContext;
import backtype.storm.topology.IRichBolt;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.tuple.Fields;
import backtype.storm.tuple.Tuple;
import backtype.storm.tuple.Values;

public class MyBolt implements IRichBolt {

private static final long serialVersionUID = 1L;

OutputCollector collector = null;
@Override
public void cleanup() {

}
int num = 0;
String valueString = null;
@Override
public void execute(Tuple input) {
try {
valueString = input.getStringByField("log");

if(valueString != null) {
num ++;
System.err.println(Thread.currentThread().getName()+" lines :"+num +" session_id:"+valueString.split("	")[1]);
}
collector.emit(input, new Values(valueString));
// collector.emit(new Values(valueString));
collector.ack(input);
Thread.sleep(2000);
} catch (Exception e) {
collector.fail(input);
e.printStackTrace();
}

}

@Override
public void prepare(Map stormConf, TopologyContext context,
OutputCollector collector) {
this.collector = collector;
}

@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
declarer.declare(new Fields("session_id"));
}

@Override
public Map getComponentConfiguration() {
return null;
}

}

package com.sxt.storm.ack;


import backtype.storm.Config;
import backtype.storm.LocalCluster;
import backtype.storm.StormSubmitter;
import backtype.storm.generated.AlreadyAliveException;
import backtype.storm.generated.InvalidTopologyException;
import backtype.storm.topology.TopologyBuilder;

public class Main {

/**
* @param args
*/
public static void main(String[] args) {

TopologyBuilder builder = new TopologyBuilder();

builder.setSpout("spout", new MySpout(), 1);
builder.setBolt("bolt", new MyBolt(), 2).shuffleGrouping("spout");

// Map conf = new HashMap();
// conf.put(Config.TOPOLOGY_WORKERS, 4);

Config conf = new Config();
conf.setDebug(true);
conf.setMessageTimeoutSecs(conf, 100);
conf.setNumAckers(4);

if (args.length> 0) {
try {
StormSubmitter.submitTopology(args[0], conf, builder.createTopology());
} catch (AlreadyAliveException e) {
e.printStackTrace();
} catch (InvalidTopologyException e) {
e.printStackTrace();
}
}else {
LocalCluster localCluster = new LocalCluster();
localCluster.submitTopology("mytopology", conf, builder.createTopology());
}

}

}

  

share picture

Single point of failure, flume ha
Single point of bottleneck, load balance

http://flume.apache.org/FlumeUserGuide.html#scribe-source

Meituan log collection system architecture
https://tech.meituan.com/2013/12/09/meituan-flume-log-system-architecture-and-design.html


Example: call drop rate, (abnormal hang-up: no sound, not in the service area)
China Mobile project structure diagram:

 share picture

kafka creates topic
./kafka-topics.sh --zookeeper node2:2181,node3:2181,node4:2181 --create --replication-factor 2 --partitions 3 --topic mylog_cmcc

## Start consumption
./kafka-console-consumer.sh --zookeeper node2:2181,node3:2181,node4:2181 --from-beginning --topic mylog_cmcc



// The following program is used to generate production data.

/**
 * 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 kafka.productor;

import java.util.Properties;
import java.util.Random;

import backtype.storm.utils.Utils;
import kafka.producer.KeyedMessage;
import kafka.producer.ProducerConfig;
import tools.DateFmt;

/***
 * Simulate sending data to Kafka
 *
 * @author hadoop
 *
 */
public class CellProducer extends Thread {

// bin/kafka-topics.sh --create --zookeeper localhost:2181
// --replication-factor 3 --partitions 5 --topic cmcccdr
private final kafka.javaapi.producer.Producer producer;
private final String topic;
private final Properties props = new Properties();

public CellProducer(String topic) {
props.put("serializer.class", "kafka.serializer.StringEncoder");// string message
props.put("metadata.broker.list", KafkaProperties.broker_list);
producer = new kafka.javaapi.producer.Producer(new ProducerConfig(props));
this.topic = topic;
}

/*
* public void run() {// order_id,order_amt,create_time,province_id Random
* random = new Random(); String[] cell_num = {"29448-37062",
* "29448-51331", "29448-51331","29448-51333", "29448-51343" }; String[]
* drop_num = {"0","1","2"};//drop 1 (intermittent signal) drop 2 (completely disconnected)
*
* // Producer.java // record_time, imei, cell,
* ph_num,call_num,drop_num,duration,drop_rate,net_type,erl // 2011-06-28
* 14:24:59.867,356966,29448-37062,0,0,0,0,0,G,0 // 2011-06-28
* 14:24:59.867,352024,29448-51331,0,0,0,0,0,G,0 // 2011-06-28
* 14:24:59.867,353736,29448-51331,0,0,0,0,0,G,0 // 2011-06-28
* 14:24:59.867,353736,29448-51333,0,0,0,0,0,G,0 // 2011-06-28
* 14:24:59.867,351545,29448-51333,0,0,0,0,0,G,0 // 2011-06-28
* 14:24:59.867,353736,29448-51343,1,0,0,8,0,G,0 int i =0; NumberFormat nf
* = new DecimalFormat("000000"); while(true) {i ++; // String messageStr
* = i+"	"+cell_num[random.nextInt(cell_num.length)]+"	"+DateFmt.
* getCountDate(null,
* DateFmt.date_long)+"	"+drop_num[random.nextInt(drop_num.length)];
* String testStr = nf.format(random.nextInt(10)+1);
*
* String messageStr =
* i+"	"+("29448-"+testStr)+"	"+DateFmt.getCountDate(null,
* DateFmt.date_long)+"	"+drop_num[random.nextInt(drop_num.length)];
*
* System.out.println("product:"+messageStr); producer.send(new
* KeyedMessage(topic, messageStr)); Utils.sleep(1000); //
* if (i==500) {// break; //}}
*
*}
*/
public void run() {
Random random = new Random();
String[] cell_num = {"29448-37062", "29448-51331", "29448-51331", "29448-51333", "29448-51343" };
// normal 0; dropped call 1 (intermittent signal); dropped call 2 (completely disconnected)
String[] drop_num = {"0", "1", "2" };
int i = 0;
while (true) {
i++;
String testStr = String.format("%06d", random.nextInt(10) + 1);

// messageStr: 2494 29448-000003 2016-01-05 10:25:17 1
//
String messageStr = i + "	" + ("29448-" + testStr) + "	" + DateFmt.getCountDate(null, DateFmt.date_long)
+ "	" + drop_num[random.nextInt(drop_num.length)];
System.out.println("product:" + messageStr);
producer.send(new KeyedMessage(topic, messageStr));
Utils.sleep(1000);
// if(i == 500) {
// break;
//}
}
}

public static void main(String[] args) {
// topic settings
CellProducer producerThread = new CellProducer(KafkaProperties.Cell_Topic);

// Start the thread to generate data
producerThread.start();

}
}


package cmcc.constant;

public class Constants {

public static final String HBASE_ZOOKEEPER_LIST = "node4:2181";

public static final String KAFKA_ZOOKEEPER_LIST = "node2:2181,node3:2181,node4:2181";

public static final String BROKER_LIST = "node2:9092,node3:9092,node4:9092";

public static final String ZOOKEEPERS = "node2,node3,node4";
}

nimbus
British [?n?mb?s] American [?n?mb?s]
n.
(Large) rain cloud; halo

strom distributed real-time streaming computing framework

strom is shown on the right side of the figure below, here is a piece of data , Process one, the amount of data processed per unit time can not be too large to ensure its normal operation, but once it is started, it runs all the time.
Batch processing is different. Spark is the computing framework of the micro-batch processing framework, which can also achieve real-time performance.
MR can't achieve real-time performance, the order of magnitude is TB, PB level, frequent disk operation, frequent start and stop jobs.

ETL (data cleaning) extracted transform load
Spout
British [spa?t] Beautiful [spa?t]
Spout; spout; spout; spout; tornado
bolt
British [b??lt] American [bo?lt]
n.
(For doors and windows) bolts, insert v.
bolt with a pin; can be bolted; fix (A and B) together with a bolt; (horse, etc. are frightened)
adv.
Suddenly; like an arrow; upright

Nimbus is similar to master
The supervisor is similar to the slave 
worker task

ack mechanism cannot guarantee that the data will not be double-calculated, but it can guarantee that the data is at least It was handled correctly once. (May be calculated twice due to an error, causing non-error data retransmission)

package com.sxt.storm.ack;


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Map;

import backtype.storm.spout.SpoutOutputCollector;
import backtype.storm.task.TopologyContext;
import backtype.storm.topology.IRichSpout;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.tuple.Fields;
import backtype.storm.tuple.Values;

public class MySpout implements IRichSpout{

private static final long serialVersionUID = 1L;

int index = 0;

FileInputStream fis;
InputStreamReader isr;
BufferedReader br;
SpoutOutputCollector collector = null;
String str = null;

@Override
public void nextTuple() {
try {
if ((str = this.br.readLine()) != null) {
// filter action
index++;
collector.emit(new Values(str), index);
// collector.emit(new Values(str));
}
} catch (Exception e) {
}


}
@Override
public void close() {
try {
br.close();
isr.close();
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void open(Map conf, TopologyContext context,
SpoutOutputCollector collector) {
try {
this.collector = collector;
this.fis = new FileInputStream("track.log");
this.isr = new InputStreamReader(fis, "UTF-8");
this.br = new BufferedReader(isr);
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
declarer.declare(new Fields("log"));
}

@Override
public Map getComponentConfiguration() {
return null;
}

@Override
public void ack(Object msgId) {
System.err.println(" [" + Thread.currentThread().getName() + "] "+ "spout ack:"+msgId.toString());
}

@Override
public void activate() {

}

@Override
public void deactivate() {

}

@Override
public void fail(Object msgId) {
System.err.println(" [" + Thread.currentThread().getName() + "] "+ "spout fail:"+msgId.toString());
}

}

package com.sxt.storm.ack;

import java.util.Map;

import backtype.storm.task.OutputCollector;
import backtype.storm.task.TopologyContext;
import backtype.storm.topology.IRichBolt;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.tuple.Fields;
import backtype.storm.tuple.Tuple;
import backtype.storm.tuple.Values;

public class MyBolt implements IRichBolt {

private static final long serialVersionUID = 1L;

OutputCollector collector = null;
@Override
public void cleanup() {

}
int num = 0;
String valueString = null;
@Override
public void execute(Tuple input) {
try {
valueString = input.getStringByField("log");

if(valueString != null) {
num ++;
System.err.println(Thread.currentThread().getName()+" lines :"+num +" session_id:"+valueString.split("	")[1]);
}
collector.emit(input, new Values(valueString));
// collector.emit(new Values(valueString));
collector.ack(input);
Thread.sleep(2000);
} catch (Exception e) {
collector.fail(input);
e.printStackTrace();
}

}

@Override
public void prepare(Map stormConf, TopologyContext context,
OutputCollector collector) {
this.collector = collector;
}

@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
declarer.declare(new Fields("session_id"));
}

@Override
public Map getComponentConfiguration() {
return null;
}

}

package com.sxt.storm.ack;


import backtype.storm.Config;
import backtype.storm.LocalCluster;
import backtype.storm.StormSubmitter;
import backtype.storm.generated.AlreadyAliveException;
import backtype.storm.generated.InvalidTopologyException;
import backtype.storm.topology.TopologyBuilder;

public class Main {

/**
* @param args
*/
public static void main(String[] args) {

TopologyBuilder builder = new TopologyBuilder();

builder.setSpout("spout", new MySpout(), 1);
builder.setBolt("bolt", new MyBolt(), 2).shuffleGrouping("spout");

// Map conf = new HashMap();
// conf.put(Config.TOPOLOGY_WORKERS, 4);

Config conf = new Config();
conf.setDebug(true);
conf.setMessageTimeoutSecs(conf, 100);
conf.setNumAckers(4);

if (args.length> 0) {
try {
StormSubmitter.submitTopology(args[0], conf, builder.createTopology());
} catch (AlreadyAliveException e) {
e.printStackTrace();
} catch (InvalidTopologyException e) {
e.printStackTrace();
}
}else {
LocalCluster localCluster = new LocalCluster();
localCluster.submitTopology("mytopology", conf, builder.createTopology());
}

}

}

Single point of failure, flume ha
Single point of bottleneck, load balance

http://flume.apache.org/FlumeUserGuide.html#scribe-source

Meituan log collection system architecture
https://tech.meituan.com/2013/12/09/meituan-flume-log-system-architecture-and-design.html


Example: call drop rate, (abnormal hang-up: no sound, not in the service area)
China Mobile project architecture diagram:

kafka creates topic
./kafka-topics.sh --zookeeper node2:2181,node3:2181,node4:2181 --create --replication-factor 2 --partitions 3 --topic mylog_cmcc

## Start consumption
./kafka-console-consumer.sh --zookeeper node2:2181,node3:2181,node4:2181 --from-beginning --topic mylog_cmcc



// The following program is used to generate production data.

/**
 * 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 kafka.productor;

import java.util.Properties;
import java.util.Random;

import backtype.storm.utils.Utils;
import kafka.producer.KeyedMessage;
import kafka.producer.ProducerConfig;
import tools.DateFmt;

/***
 * Simulate sending data to Kafka
 *
 * @author hadoop
 *
 */
public class CellProducer extends Thread {

// bin/kafka-topics.sh --create --zookeeper localhost:2181
// --replication-factor 3 --partitions 5 --topic cmcccdr
private final kafka.javaapi.producer.Producer producer;
private final String topic;
private final Properties props = new Properties();

public CellProducer(String topic) {
props.put("serializer.class", "kafka.serializer.StringEncoder");// string message
props.put("metadata.broker.list", KafkaProperties.broker_list);
producer = new kafka.javaapi.producer.Producer(new ProducerConfig(props));
this.topic = topic;
}

/*
* public void run() {// order_id,order_amt,create_time,province_id Random
* random = new Random(); String[] cell_num = {"29448-37062",
* "29448-51331", "29448-51331","29448-51333", "29448-51343" }; String[]
* drop_num = {"0","1","2"};//drop 1 (intermittent signal) drop 2 (completely disconnected)
*
* // Producer.java // record_time, imei, cell,
* ph_num,call_num,drop_num,duration,drop_rate,net_type,erl // 2011-06-28
* 14:24:59.867,356966,29448-37062,0,0,0,0,0,G,0 // 2011-06-28
* 14:24:59.867,352024,29448-51331,0,0,0,0,0,G,0 // 2011-06-28
* 14:24:59.867,353736,29448-51331,0,0,0,0,0,G,0 // 2011-06-28
* 14:24:59.867,353736,29448-51333,0,0,0,0,0,G,0 // 2011-06-28
* 14:24:59.867,351545,29448-51333,0,0,0,0,0,G,0 // 2011-06-28
* 14:24:59.867,353736,29448-51343,1,0,0,8,0,G,0 int i =0; NumberFormat nf
* = new DecimalFormat("000000"); while(true) {i ++; // String messageStr
* = i+"	"+cell_num[random.nextInt(cell_num.length)]+"	"+DateFmt.
* getCountDate(null,
* DateFmt.date_long)+"	"+drop_num[random.nextInt(drop_num.length)];
* String testStr = nf.format(random.nextInt(10)+1);
*
* String messageStr =
* i+"	"+("29448-"+testStr)+"	"+DateFmt.getCountDate(null,
* DateFmt.date_long)+"	"+drop_num[random.nextInt(drop_num.length)];
*
* System.out.println("product:"+messageStr); producer.send(new
* KeyedMessage(topic, messageStr)); Utils.sleep(1000); //
* if (i==500) {// break; //}}
*
*}
*/
public void run() {
Random random = new Random();
String[] cell_num = {"29448-37062", "29448-51331", "29448-51331", "29448-51333", "29448-51343" };
// normal 0; dropped call 1 (intermittent signal); dropped call 2 (completely disconnected)
String[] drop_num = {"0", "1", "2" };
int i = 0;
while (true) {
i++;
String testStr = String.format("%06d", random.nextInt(10) + 1);

// messageStr: 2494 29448-000003 2016-01-05 10:25:17 1
//
String messageStr = i + "	" + ("29448-" + testStr) + "	" + DateFmt.getCountDate(null, DateFmt.date_long)
+ "	" + drop_num[random.nextInt(drop_num.length)];
System.out.println("product:" + messageStr);
producer.send(new KeyedMessage(topic, messageStr));
Utils.sleep(1000);
// if(i == 500) {
// break;
//}
}
}

public static void main(String[] args) {
// topic settings
CellProducer producerThread = new CellProducer(KafkaProperties.Cell_Topic);

// Start the thread to generate data
producerThread.start();

}
}


package cmcc.constant;

public class Constants {

public static final String HBASE_ZOOKEEPER_LIST = "node4:2181";

public static final String KAFKA_ZOOKEEPER_LIST = "node2:2181,node3:2181,node4:2181";

public static final String BROKER_LIST = "node2:9092,node3:9092,node4:9092";

public static final String ZOOKEEPERS = "node2,node3,node4";
}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 488 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.