普通事务ITransactionalSpout实例之按天统计数据

[size=large]1、普通事务Spout[/size]


/**
* 普通事务Spout
*/
public class MyTxSpout implements ITransactionalSpout<MyMata>{


private static final long serialVersionUID = 1L;


/**
* 数据源
*/
Map<Long, String> dbMap = null;
public MyTxSpout()
{
Random random = new Random();
dbMap = new HashMap<Long, String> ();
String[] hosts = { "www.taobao.com" };
String[] session_id = { "ABYH6Y4V4SCVXTG6DPB4VH9U123", "XXYH6YCGFJYERTT834R52FDXV9U34", "BBYH61456FGHHJ7JL89RG5VV9UYU7",
"CYYH6Y2345GHI899OFG4V9U567", "VVVYH6Y4V4SFXZ56JIPDPB4V678" };
String[] time = { "2014-01-07 08:40:50", "2014-01-07 08:40:51", "2014-01-07 08:40:52", "2014-01-07 08:40:53",
"2014-01-07 09:40:49", "2014-01-07 10:40:49", "2014-01-07 11:40:49", "2014-01-07 12:40:49" };

for (long i = 0; i < 100; i++) {
dbMap.put(i,hosts[0]+"\t"+session_id[random.nextInt(5)]+"\t"+time[random.nextInt(8)]);
}
}



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

public Map<String, Object> getComponentConfiguration() {
return null;
}

public org.apache.storm.transactional.ITransactionalSpout.Coordinator<MyMata> getCoordinator(Map conf,
TopologyContext context) {
/**
* 发射该metadata(事务tuple)到“batch emit”流
*/
return new MyCoordinator();
}

public org.apache.storm.transactional.ITransactionalSpout.Emitter<MyMata> getEmitter(Map conf,
TopologyContext context) {
/**
* 逐个发射实际batch的tuple
*/
return new MyEmitter(dbMap);
}

}


[size=large]2、事务Spout创建一个新的事务(元数据)metadata[/size]
[b]2、1元数据定义[/b]

public class MyMata implements Serializable{

/**
* metadata(元数据)中包含当前事务可以从哪个point进行重放数据,存放在zookeeper中的,spout可以通过Kryo从zookeeper中序列化和反序列化该元数据。
*/
private static final long serialVersionUID = 1L;

private long beginPoint ;//事务开始位置

private int num ;//batch 的tuple个数
@Override
public String toString() {
return getBeginPoint()+"----"+getNum();
}

public long getBeginPoint() {
return beginPoint;
}

public void setBeginPoint(long beginPoint) {
this.beginPoint = beginPoint;
}

public int getNum() {
return num;
}

public void setNum(int num) {
this.num = num;
}


}



[b]2、2 获得(元数据)metadata,逐个发射实际batch的tuple[/b]


public class MyEmitter implements ITransactionalSpout.Emitter<MyMata> {

Map<Long, String> dbMap = null;

public MyEmitter(Map<Long, String> dbMap) {
this.dbMap = dbMap;
}

//逐个发射实际batch的tuple
public void emitBatch(TransactionAttempt tx, MyMata coordinatorMeta, BatchOutputCollector collector) {

long beginPoint = coordinatorMeta.getBeginPoint();// 从上一个批次获得开始位置

int num = coordinatorMeta.getNum();// 从批次中获取批次数量

for (long i = beginPoint; i < num + beginPoint; i++) {
if (dbMap.get(i) == null) {
continue;
}
collector.emit(new Values(tx, dbMap.get(i)));
}

}

public void cleanupBefore(BigInteger txid) {

}

public void close() {

}

}


[size=large]------------------------spout与上篇相同-----------------------------------------[/size]

[size=x-large]3、按天统计数据事务Bolt,会从Emitter接收数据处理,处理完成,提交给finishBatch方法处理。[/size]


public class MyDailyBatchBolt implements IBatchBolt<TransactionAttempt> {

/**
* 按天统计数据
*/
private static final long serialVersionUID = 1L;
Map<String, Integer> countMap = new HashMap<String, Integer>();
BatchOutputCollector collector ;
Integer count = null;
String today = null;
TransactionAttempt tx = null;
@Override
public void execute(Tuple tuple) {
// TODO Auto-generated method stub
String log = tuple.getString(1);
tx = (TransactionAttempt)tuple.getValue(0);
if (log != null && log.split("\\t").length >=3 ) {
today = DateFmt.getCountDate(log.split("\\t")[2], DateFmt.date_short) ;
count = countMap.get(today);
if(count == null)
{
count = 0;
}
count ++ ;

countMap.put(today, count);
}
}

@Override
public void finishBatch() {
collector.emit(new Values(tx,today,count));
}

@Override
public void prepare(Map conf, TopologyContext context,
BatchOutputCollector collector, TransactionAttempt id) {
// TODO Auto-generated method stub
this.collector = collector;

}

@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
// TODO Auto-generated method stub
declarer.declare(new Fields("tx","date","count"));
}

@Override
public Map<String, Object> getComponentConfiguration() {
// TODO Auto-generated method stub
return null;
}

}



[size=large]4、接收统计数据,累加汇总MyDailyCommitterBolt,batch之间强制按照顺序进行提交[/size]


public class MyDailyCommitterBolt extends BaseTransactionalBolt implements ICommitter{

/**
* 接收统计数据,累加汇总
*/
private static final long serialVersionUID = 1L;
public static final String GLOBAL_KEY = "GLOBAL_KEY";
public static Map<String, DbValue> dbMap = new HashMap<String, DbValue>() ;

Map<String, Integer> countMap = new HashMap<String, Integer>();
TransactionAttempt id ;
BatchOutputCollector collector;
String today = null;
@Override
public void execute(Tuple tuple) {
today = tuple.getString(1) ;
Integer count = tuple.getInteger(2);
id = (TransactionAttempt)tuple.getValue(0);

if (today !=null && count != null) {
Integer batchCount = countMap.get(today) ;
if (batchCount == null) {
batchCount = 0;
}
batchCount += count ;
countMap.put(today, batchCount);
}
}

@Override
public void finishBatch() {
// TODO Auto-generated method stub
if (countMap.size() > 0) {
DbValue value = dbMap.get(GLOBAL_KEY);
DbValue newValue ;
if (value == null || !value.txid.equals(id.getTransactionId())) {
//更新数据库
newValue = new DbValue();
newValue.txid = id.getTransactionId() ;
newValue.dateStr = today;
if (value == null) {
newValue.count = countMap.get(today) ;
}else {
newValue.count = value.count + countMap.get("2014-01-07") ;
}
dbMap.put(GLOBAL_KEY, newValue);
}else
{
newValue = value;
}
}

System.out.println("total==========================:"+dbMap.get(GLOBAL_KEY).count);
// collector.emit(tuple)
}

@Override
public void prepare(Map conf, TopologyContext context,
BatchOutputCollector collector, TransactionAttempt id) {
// TODO Auto-generated method stub
this.id = id ;
this.collector = collector;
}

@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
// TODO Auto-generated method stub

}
public static class DbValue
{
BigInteger txid;
int count = 0;
String dateStr;
}

}



[size=large]5、topo类[/size]


public class MyDailyTopo {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

TransactionalTopologyBuilder builder = new TransactionalTopologyBuilder("ttbId","spoutid",new MyTxSpout(),1);
builder.setBolt("bolt1", new MyDailyBatchBolt(),3).shuffleGrouping("spoutid");
builder.setBolt("committer", new MyDailyCommitterBolt(),1).shuffleGrouping("bolt1") ;

Config conf = new Config() ;
conf.setDebug(true);

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




}

}


[size=large]6、测试结果[/size]
[quote]启动一个事务:0----10
total==========================:10
启动一个事务:10----10
total==========================:20
启动一个事务:20----10
total==========================:30[/quote]
SAP ABAP 获取采购订单未清数量/在途库存的 6 种方式 这篇文章我总结了获取采购订单未清数量/在途库存的 6 种方式,每种方式的优劣势和适用场景有所不同。读者请结合自身需要选择。 阅读详情

相关推荐

在 dell precision 7920 tower CentOS 8 Stream 上安裝nvidia驱动程序、Anaconda

简单记录一下如何在实验室dell precision 7920 tower CentOS 8 Stream上安装nvidia显卡驱动。

chen9046的博客 995

Storm之事务和项目案例

一、Storm事务 1、事务性拓扑(Transactional Topologies) 2、保证消息(tuple)被且仅被处理一次 官网:http://storm.apache.org/releases/0.9.6/Transactional-topologies.html 三种事务: 1、普通事务 2、Partitioned Transaction - 分区事务 3、Opaque T...

lixinkuan的博客 989

SAP BOM批量反查代码分享

SAP BOM反查批量查询代码分享

我小时候很黑的博客 4972

Storm系列(十九)普通事务ITransactionalSpout及示例

普通事务API详解 1 publicinterfaceITransactionalSpout<T>extendsIComponent{ 2 publicinterfaceCoordinator<X>{ ...

weixin_30516243的博客 200

动量因子在A股市场的有效性分析:量化实证研究

验证动量因子在A股市场的有效性及时间周期性分析不同时间窗口(短期/中期/长期)对动量效应的影响量化交易成本、市场流动性对动量策略收益的侵蚀程度比较A股与成熟市场(如美股)动量效应的差异特征理论框架:行为金融学解释动量效应的产生机制技术实现:Python全流程代码实现动量因子计算与回测实证分析:统计检验、风险收益指标、敏感性分析应用拓展:结合市场微观结构的策略优化方案动量因子(Momentum Factor)

2501_92132293的博客 2485

基于深度学习的树木种类识别

本文介绍了基于深度学习的树木种类识别技术。我们将通过深度学习模型和图像处理技术实现对树木的自动识别与分类。首先,我们将介绍深度学习的基本原理和相关算法。接着,我们将详细说明树木种类识别的数据准备、模型构建和训练过程。最后,我们将给出代码示例,帮助读者深入了解和实践该技术。

一键难忘的博客 2317

四、事务拓扑(Transactional Topolgoy)

1、问题的提出     怎样做到每个出错的tuple只被处理一次?这样才能统计所有发射出的tuple的数量。 2、简介 Storm 0.7.0引入了Transactional Topology, 它可以保证每个tuple”被且仅被处理一次”, 这样你就可以实现一种非常准确,非常可扩展,并且高度容错方式来实现计数类应用。跟DRPC类似, transactional topolo

王帆的专栏 1454

高通平台 Android T 蓝牙技术全解析:架构、代码与实现原理

协议栈、配置文件和服务都运行在一个独立的用户空间进程。

专业开发者的博客,一个从事Android WiFi和蓝牙的工程师 100

MySQL 各级别事务的实现机制

MySQL 各级别事务的实现机制在处理cnctp项目已合包裹状态同步的问题时,发现读包裹状态和对包裹状态的更新不在一个事务内,我提出是否会因为消息并发导致状态一致性问题。在和同事讨论的过程中,我们开始论及事务隔离级别与其实现,以及修改隔离级别是否会对其他会话和事务造成影响等问题。由于学而忘习,对这个问题谈得比较模糊,没有以有力的论据说服其他人,因此整理了一下相关文档记录于此。 谈事务的实现前,先说...

weixin_34406796的博客 147

国科大学习资料--矩阵论(叶世伟)-期末考试题整理3

国科大学习资料–矩阵论-期末考试题整理3 国科大学习资料–矩阵论-期末考试题整理3 国科大学习资料–矩阵论-期末考试题整理3

无名何许人的博客 1406

高项备考论文:规划绩效域

高项备考论文:规划绩效域

liuxu324的博客 1129

SQL语句统计每天、每月、每年的 数据

1、每年 select year(ordertime) AS '年', sum(Total) '销售合计' from order_list group by year(ordertime) 2、每月 select year(ordertime) '年', month(ordertime) '月', sum(Total) '销售合计' from order_list group by year(o

Saindy5828的专栏 9556

解决Gradle中NPM命令失效问题

摘要:本文分析了IntelliJ IDEA中Gradle执行npm命令失败的问题,报错显示"npm"文件不存在。通过确认npm安装路径、检查系统PATH与Gradle环境的差异,提出两种解决方案:1) 在build.gradle中使用npm绝对路径;2) 通过launchctl修改用户PATH。实例展示了如何修改Gradle脚本或系统配置来解决该问题,指出跨平台开发中环境变量配置的重要性。文章为开发者提供了处理类似问题的实用方法。

2501_90323865的博客 91

EXCEL与数据透视表:如何统计每日按工号统计的数量。

一 题目:原始数据和需求 每天每一个人,台数有重复的算1台,没重复的台数就算多少台 不是台数求和,而是台数求格数,且需要去重复 统计出现次数 日期 工号 台数 辅助列 3月1日 C01 1 1 3月1日 C01 2 1 3月1日 C01 3 1 3月1日 C02 5 0.5 3...

奔跑的犀牛先生 7684

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Storm 本地模式

本地模式,是在eclipse等编译器编写strom运行文件,在于模拟storm在集群运行的结果,便于代码的编写和调试。 一、下载开发环境的zip文件,将storm相关jar包导入编辑器。注意是zip文件,不是gz运行linux文件。 http://storm.apache.org/downloads.html 二、创建数据文件 [b]storm有Tai...

futureofstar的博客 649

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

storm高并发UV统计

[size=small]统计高并发UV可行的方案(类似WordCount的计算去重word总数): bolt1通过fieldGrouping 进行多线程局部汇总,下一级blot2进行单线程保存session_id和count数到Map且进行遍历,可以得到: Pv、UV、访问深度(按每个session_id 的浏览数) 2014-05-01 UV数(按日期统计) 既然去重,必...

futureofstar的博客 464

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

集群统一启动和停止shell脚本开发

1、cd 2、ls -al 显示隐藏目录 3、rm -rf .ssh 删除各节点的.ssh目录 4、ssh master/slave 验证是否需要密码 exit退出登陆 [size=large]一、设置ssh无密码访问slave节点[/size] 1、各节点(master/slave)执行ssh-keygen -t rsa 建立ssh目录,一路敲回车,生成的密钥...

futureofstar的博客 401

storm分组策略介绍

[size=medium][b]一、storm数据来源[/b][/size] Spout的数据源: MQ:直接流数据源 Db:只能读配置文件 文件:只能学习用,其他无用。 问题:1、分布式应用无法读;2、spout开并发会重复读 Log文件增量数据:1、读出内容写入MQ,2、Storm处理 [size=medium][b]二、分组策略[/b][/size] st...

futureofstar的博客 400

不透明分区事务IOpaquePartitionedTransactional实例

1、spout [code="java"] public class MyOpaquePtTxSpout implements IOpaquePartitionedTransactionalSpout { /** * 将Coordinator发射数据动作下放到emitPartitionBatch类执行。 */ private static final long se...

futureofstar的博客 384

分区事务IPartitionedTransactionalSpout实例

[size=large]1.分区事务spout[/size] [code="java"] public class MyPtTxSpout implements IPartitionedTransactionalSpout{ /** * 分区事务spout */ private static final long serialVersionUID = 1L; p...

futureofstar的博客 336

storm高并发PV统计

[b][size=medium]一、PV统计思考[/size][/b] 方案需要考虑分析多线程下,注意线程安全问题。 线程安全:多线程处理的结果和单线程一致 如下是否可行? 不可行方案: 定义static long pv, Synchronized 控制累计操作。Synchronized 和 Lock在单个JVM下有效,但在多JVM下无效。 可行方案两个方案: 1...

futureofstar的博客 315

Storm启动配置

[size=large]一、安装Storm[/size] wget http://www.apache.org/dyn/closer.lua/storm/apache-storm-1.0.3/apache-storm-1.0.3.tar.gz tar xzvf ./apache-storm-1.0.3.tar.gz [size=large]二、新建data文件夹[/...

futureofstar的博客 306

Trident实战之计算网站PV

[size=large]1、Trident实战之计算网站PV[/size] [code="java"] /** * Trident实战之计算网站PV */ public class TridentPVTopo { public static StormTopology buildTopology(LocalDRPC drpc) { Random random =...

futureofstar的博客 290

Trident API和概念

[size=large]一、Trident API——Spout[/size]     [b]ITridentSpout[/b]:最通用的Spout,可以支持事务或者不透明事务语义。     IBatchSpout: 一个非事务spout 。     [b]IPartitionedTridentSpout[/b]: 分区事务spout,从数据源(比如一个Kafka集群)读分区数据     ...

futureofstar的博客 270

Storm高并发运用WordSum

1、创建发射所有字符串统计总个数及去重个数处理类 [code="java"] public class SumBolt implements IBasicBolt { /** * 对发射所有字符串统计总个数及去重个数 */ private static final long serialVersionUID = 1L; Map counts = new Ha...

futureofstar的博客 251

Strom依赖软件安装

[size=large]一、下载zeroMq[/size] http://zeromq.org/intro:get-the-software [quote] tar -xzvf zeromq-2.1.7.tar.gz cd zeromq-2.1.7 ./configure make (普通帐户加sudo)...

futureofstar的博客 249
上一篇: 普通事务ITransactionalSpout实例
下一篇: 分区事务IPartitionedTransactionalSpout实例
futureofstar
博客等级 码龄17年 0粉丝 89原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值