Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write simple stress test code in Storm

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article is to share with you about how to write simple stress test code in Storm. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article.

The code is relatively simple, look at the picture and say:

Package storm.benchmark;import backtype.storm.Config;import backtype.storm.StormSubmitter;import backtype.storm.spout.SpoutOutputCollector;import backtype.storm.task.TopologyContext;import backtype.storm.topology.BasicOutputCollector;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 java.util.Map;import java.util.Random Public class ThroughputTest {public static class GenSpout extends BaseRichSpout {private static final Character [] CHARS = new Character [] {'await,' baked, 'cased,' dashed, 'eyed,' faded, 'grubbed,' h'}; SpoutOutputCollector _ collector; int _ size; Random _ rand; String _ id; String _ val Public GenSpout (int size) {_ size = size;} @ Override public void open (Map conf, TopologyContext context, SpoutOutputCollector collector) {_ collector = collector; _ rand = new Random (); _ id = randString (5); _ val = randString (_ size) } @ Override public void nextTuple () {_ collector.emit (new Values (_ id, _ val));} private String randString (int size) {StringBuffer buf = new StringBuffer (); for (int iTuno; I

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report