From a23083bc5f147e693e7d680711e3ba2c295aeb9f Mon Sep 17 00:00:00 2001
From: StrongestNumber9 <16169054+StrongestNumber9@users.noreply.github.com>
Date: Wed, 15 May 2024 15:41:52 +0300
Subject: [PATCH 1/6] Update to support newer rlp_09, refactor events to
records, int to long due to overflows
---
README.adoc | 6 ++++--
pom.xml | 2 +-
src/main/java/com/teragrep/rlp_10/Flooder.java | 12 ++++++------
.../com/teragrep/rlp_10/FlooderConfig.java | 8 ++++++--
src/main/java/com/teragrep/rlp_10/Main.java | 18 +++++++++++++-----
...rator.java => PerThreadRecordIterator.java} | 6 +++---
...ava => PerThreadRecordIteratorFactory.java} | 6 +++---
...tor.java => SharedTotalRecordIterator.java} | 6 +++---
...a => SharedTotalRecordIteratorFactory.java} | 6 +++---
9 files changed, 42 insertions(+), 28 deletions(-)
rename src/main/java/com/teragrep/rlp_10/{PerThreadMessageIterator.java => PerThreadRecordIterator.java} (93%)
rename src/main/java/com/teragrep/rlp_10/{PerThreadMessageIteratorFactory.java => PerThreadRecordIteratorFactory.java} (91%)
rename src/main/java/com/teragrep/rlp_10/{SharedTotalMessageIterator.java => SharedTotalRecordIterator.java} (92%)
rename src/main/java/com/teragrep/rlp_10/{SharedTotalMessageIteratorFactory.java => SharedTotalRecordIteratorFactory.java} (90%)
diff --git a/README.adoc b/README.adoc
index 1271373..9345f7c 100644
--- a/README.adoc
+++ b/README.adoc
@@ -6,7 +6,7 @@ Standalone version of https://github.com/teragrep/rlp_09[rlp_09]
- Simple to use
- Scales to as many threads as wanted
-- Supports infinite flooding and sending specific amount of events
+- Supports infinite flooding and sending specific amount of records, both per thread and total
== Limitations
@@ -35,10 +35,12 @@ Standalone version of https://github.com/teragrep/rlp_09[rlp_09]
|port|1601|RELP target port
|threads|4|RELP Flooder thread count
|useTls|false|Is TLS used for connections (Note: Not implemented)
-|payloadSize|10|Record message extra padding
+|payloadSize|10|Record extra padding
|reportInterval|10|How often report should be printed
|maxRecordsSent|-1|How many records should be sent (-1 for infinity). By default, this is per-thread but with usePerThreadIterator=false it is the total amount.
|usePerThreadIterator|true|Should each thread act as an independent iterator (will send maxRecordsSent * threads amount of records)
+|connectTimeout|5|Seconds to wait while connecting
+|waitForAcks|true|Whether to wait for acks or not. Recommended to keep on.
|===
== Contributing
diff --git a/pom.xml b/pom.xml
index 011ee81..2910c5f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,7 +14,7 @@
-SNAPSHOT
4.2.25
- 2.0.4
+ 3.0.0
2.22.1
2.0.5
diff --git a/src/main/java/com/teragrep/rlp_10/Flooder.java b/src/main/java/com/teragrep/rlp_10/Flooder.java
index ea76261..cd3f28b 100644
--- a/src/main/java/com/teragrep/rlp_10/Flooder.java
+++ b/src/main/java/com/teragrep/rlp_10/Flooder.java
@@ -69,15 +69,15 @@ public Flooder(RelpFlooderConfig relpFlooderConfig, RelpFlooderIteratorFactory r
this.relpFlooder = new RelpFlooder(relpFlooderConfig, relpFlooderIteratorFactory);
MetricRegistry metricRegistry = new MetricRegistry();
// Records sent total
- metricRegistry.register(name( "records","sent", "total"), (Gauge) relpFlooder::getTotalRecordsSent);
- metricRegistry.register(name("records", "sent", "total", "perThread"), (Gauge>) relpFlooder::getRecordsSentPerThread);
+ metricRegistry.register(name( "records","sent", "total"), (Gauge) relpFlooder::getTotalRecordsSent);
+ metricRegistry.register(name("records", "sent", "total", "perThread"), (Gauge>) relpFlooder::getRecordsSentPerThread);
// Records sent per second
metricRegistry.register(name("records", "sent", "perSecond"), (Gauge) this::reportRecordsPerSecond);
metricRegistry.register(name("records", "sent", "perSecond", "perThread"), (Gauge>) this::reportRecordsPerSecondPerThread);
// Bytes sent total
- metricRegistry.register(name("bytes", "sent", "total"), (Gauge) relpFlooder::getTotalBytesSent);
+ metricRegistry.register(name("bytes", "sent", "total"), (Gauge) relpFlooder::getTotalBytesSent);
metricRegistry.register(name("bytes", "sent", "total", "MB"), (Gauge) this::reportTotalMegaBytesSent);
- metricRegistry.register(name("bytes", "sent", "total", "perThread"), (Gauge>) relpFlooder::getTotalBytesSentPerThread);
+ metricRegistry.register(name("bytes", "sent", "total", "perThread"), (Gauge>) relpFlooder::getTotalBytesSentPerThread);
// Bytes second record
metricRegistry.register(name("bytes", "sent", "perSecond"), (Gauge) this::reportBytesPerSecond);
metricRegistry.register(name("bytes", "sent", "perSecond", "MB"), (Gauge) this::reportMegaBytesSentPerSecond);
@@ -120,7 +120,7 @@ private HashMap reportRecordsPerSecondPerThread() {
Instant now = Instant.now();
float elapsed = (now.toEpochMilli() - startTime.toEpochMilli())/1000f;
HashMap recordsPerThread = new HashMap<>();
- for(Map.Entry entry : relpFlooder.getRecordsSentPerThread().entrySet()) {
+ for(Map.Entry entry : relpFlooder.getRecordsSentPerThread().entrySet()) {
recordsPerThread.put(entry.getKey(), entry.getValue()/elapsed);
}
return recordsPerThread;
@@ -136,7 +136,7 @@ private HashMap reportBytesPerSecondPerThread() {
Instant now = Instant.now();
float elapsed = (now.toEpochMilli() - startTime.toEpochMilli())/1000f;
HashMap bytesPerThread = new HashMap<>();
- for(Map.Entry entry : relpFlooder.getTotalBytesSentPerThread().entrySet()) {
+ for(Map.Entry entry : relpFlooder.getTotalBytesSentPerThread().entrySet()) {
bytesPerThread.put(entry.getKey(), entry.getValue()/elapsed);
}
return bytesPerThread;
diff --git a/src/main/java/com/teragrep/rlp_10/FlooderConfig.java b/src/main/java/com/teragrep/rlp_10/FlooderConfig.java
index d8d0b20..4f1920e 100644
--- a/src/main/java/com/teragrep/rlp_10/FlooderConfig.java
+++ b/src/main/java/com/teragrep/rlp_10/FlooderConfig.java
@@ -55,8 +55,10 @@ class FlooderConfig {
public final boolean useTls;
public final int payloadSize;
public final int reportInterval;
- public final long maxMessagesSent;
+ public final long maxRecordsSent;
public final boolean usePerThreadIterator;
+ public final int connectTimeout;
+ public final boolean waitForAcks;
public FlooderConfig() {
this.hostname = System.getProperty("hostname", "localhost");
this.appname = System.getProperty("appname", "rlp_10");
@@ -66,7 +68,9 @@ public FlooderConfig() {
this.useTls = Boolean.parseBoolean(System.getProperty("useTls", "false"));
this.payloadSize = Integer.parseInt(System.getProperty("payloadSize", "10"));
this.reportInterval = Integer.parseInt(System.getProperty("reportInterval", "10"));
- this.maxMessagesSent = Long.parseLong(System.getProperty("maxMessagesSent", "-1"));
+ this.maxRecordsSent = Long.parseLong(System.getProperty("maxRecordsSent", "-1"));
this.usePerThreadIterator = Boolean.parseBoolean(System.getProperty("usePerThreadIterator", "true"));
+ this.connectTimeout = Integer.parseInt(System.getProperty("connectTimeout", "5"));
+ this.waitForAcks = Boolean.parseBoolean(System.getProperty("waitForAcks", "true"));
}
}
\ No newline at end of file
diff --git a/src/main/java/com/teragrep/rlp_10/Main.java b/src/main/java/com/teragrep/rlp_10/Main.java
index 1781123..2bd827b 100644
--- a/src/main/java/com/teragrep/rlp_10/Main.java
+++ b/src/main/java/com/teragrep/rlp_10/Main.java
@@ -54,19 +54,27 @@ class Main {
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
public static void main(String[] args) {
FlooderConfig flooderConfig = new FlooderConfig();
- RelpFlooderConfig relpFlooderConfig = new RelpFlooderConfig(flooderConfig.target, flooderConfig.port, flooderConfig.threads);
+ RelpFlooderConfig relpFlooderConfig = new RelpFlooderConfig(flooderConfig.target, flooderConfig.port, flooderConfig.threads, flooderConfig.connectTimeout, flooderConfig.waitForAcks);
LOGGER.info("Using hostname <[{}]>", flooderConfig.hostname);
LOGGER.info("Using appname <[{}]>", flooderConfig.appname);
LOGGER.info("Adding <[{}]> characters to payload size", flooderConfig.payloadSize);
LOGGER.info("Sending records to: <[{}]:[{}]>", flooderConfig.target, flooderConfig.port);
Flooder flooder;
if(flooderConfig.usePerThreadIterator) {
- LOGGER.info("Sending <[{}]> records per thread, total of <[{}]> records", flooderConfig.maxMessagesSent, flooderConfig.maxMessagesSent * flooderConfig.threads);
- flooder = new Flooder(relpFlooderConfig, new PerThreadMessageIteratorFactory(flooderConfig), flooderConfig.reportInterval);
+ LOGGER.info(
+ "Sending <[{}]> records per thread, total of <[{}]> records",
+ flooderConfig.maxRecordsSent < 0 ? "infinite" : flooderConfig.maxRecordsSent,
+ flooderConfig.maxRecordsSent < 0 ? "infinite" : flooderConfig.maxRecordsSent * flooderConfig.threads
+ );
+ flooder = new Flooder(relpFlooderConfig, new PerThreadRecordIteratorFactory(flooderConfig), flooderConfig.reportInterval);
} else {
- LOGGER.info("Sending total of <[{}]> records across all threads", flooderConfig.maxMessagesSent);
- flooder = new Flooder(relpFlooderConfig, new SharedTotalMessageIteratorFactory(flooderConfig), flooderConfig.reportInterval);
+ LOGGER.info(
+ "Sending total of <[{}]> records across all threads",
+ flooderConfig.maxRecordsSent < 0 ? "infinite" : flooderConfig.maxRecordsSent
+ );
+ flooder = new Flooder(relpFlooderConfig, new SharedTotalRecordIteratorFactory(flooderConfig), flooderConfig.reportInterval);
}
+ LOGGER.info("Waiting for acks: <[{}]>", flooderConfig.waitForAcks);
LOGGER.info("TLS enabled (FIXME: Implement): <[{}]>", flooderConfig.useTls);
LOGGER.info("Reporting stats every <[{}]> seconds", flooderConfig.reportInterval);
diff --git a/src/main/java/com/teragrep/rlp_10/PerThreadMessageIterator.java b/src/main/java/com/teragrep/rlp_10/PerThreadRecordIterator.java
similarity index 93%
rename from src/main/java/com/teragrep/rlp_10/PerThreadMessageIterator.java
rename to src/main/java/com/teragrep/rlp_10/PerThreadRecordIterator.java
index d517f16..78a580b 100644
--- a/src/main/java/com/teragrep/rlp_10/PerThreadMessageIterator.java
+++ b/src/main/java/com/teragrep/rlp_10/PerThreadRecordIterator.java
@@ -53,12 +53,12 @@
import java.time.Instant;
import java.util.Iterator;
-class PerThreadMessageIterator implements Iterator {
+class PerThreadRecordIterator implements Iterator {
private int current=0;
private final FlooderConfig flooderConfig;
private final String padding;
private final int threadId;
- public PerThreadMessageIterator(FlooderConfig flooderConfig, int threadId) {
+ public PerThreadRecordIterator(FlooderConfig flooderConfig, int threadId) {
this.flooderConfig = flooderConfig;
this.padding = new String(new char[flooderConfig.payloadSize]).replace("\0", "X");
this.threadId = threadId;
@@ -71,7 +71,7 @@ private String createMessage() {
@Override
public boolean hasNext() {
- return flooderConfig.maxMessagesSent <= -1 || current get(int threadId) {
- return new PerThreadMessageIterator(flooderConfig, threadId);
+ return new PerThreadRecordIterator(flooderConfig, threadId);
}
}
diff --git a/src/main/java/com/teragrep/rlp_10/SharedTotalMessageIterator.java b/src/main/java/com/teragrep/rlp_10/SharedTotalRecordIterator.java
similarity index 92%
rename from src/main/java/com/teragrep/rlp_10/SharedTotalMessageIterator.java
rename to src/main/java/com/teragrep/rlp_10/SharedTotalRecordIterator.java
index fc0ba50..3b87b02 100644
--- a/src/main/java/com/teragrep/rlp_10/SharedTotalMessageIterator.java
+++ b/src/main/java/com/teragrep/rlp_10/SharedTotalRecordIterator.java
@@ -54,13 +54,13 @@
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicInteger;
-class SharedTotalMessageIterator implements Iterator {
+class SharedTotalRecordIterator implements Iterator {
private final AtomicInteger recordsSent;
private final FlooderConfig flooderConfig;
private final String padding;
private final int threadId;
private int currentId;
- public SharedTotalMessageIterator(FlooderConfig flooderConfig, int threadId, AtomicInteger recordsSent) {
+ public SharedTotalRecordIterator(FlooderConfig flooderConfig, int threadId, AtomicInteger recordsSent) {
this.recordsSent = recordsSent;
this.flooderConfig = flooderConfig;
this.padding = new String(new char[flooderConfig.payloadSize]).replace("\0", "X");
@@ -74,7 +74,7 @@ private String createMessage() {
@Override
public boolean hasNext() {
currentId = recordsSent.incrementAndGet();
- return flooderConfig.maxMessagesSent <= -1 || currentId<=flooderConfig.maxMessagesSent;
+ return flooderConfig.maxRecordsSent <= -1 || currentId<=flooderConfig.maxRecordsSent;
}
@Override
diff --git a/src/main/java/com/teragrep/rlp_10/SharedTotalMessageIteratorFactory.java b/src/main/java/com/teragrep/rlp_10/SharedTotalRecordIteratorFactory.java
similarity index 90%
rename from src/main/java/com/teragrep/rlp_10/SharedTotalMessageIteratorFactory.java
rename to src/main/java/com/teragrep/rlp_10/SharedTotalRecordIteratorFactory.java
index cdb61f5..4b54644 100644
--- a/src/main/java/com/teragrep/rlp_10/SharedTotalMessageIteratorFactory.java
+++ b/src/main/java/com/teragrep/rlp_10/SharedTotalRecordIteratorFactory.java
@@ -51,14 +51,14 @@
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicInteger;
-public class SharedTotalMessageIteratorFactory implements RelpFlooderIteratorFactory {
+public class SharedTotalRecordIteratorFactory implements RelpFlooderIteratorFactory {
private final AtomicInteger recordsSent = new AtomicInteger(0);
private final FlooderConfig flooderConfig;
- SharedTotalMessageIteratorFactory(FlooderConfig flooderConfig) {
+ SharedTotalRecordIteratorFactory(FlooderConfig flooderConfig) {
this.flooderConfig = flooderConfig;
}
@Override
public Iterator get(int threadId) {
- return new SharedTotalMessageIterator(flooderConfig, threadId, recordsSent);
+ return new SharedTotalRecordIterator(flooderConfig, threadId, recordsSent);
}
}
From e848fb958cf106b523e0f10ca06896d65b07ea41 Mon Sep 17 00:00:00 2001
From: StrongestNumber9 <16169054+StrongestNumber9@users.noreply.github.com>
Date: Thu, 16 May 2024 12:01:18 +0300
Subject: [PATCH 2/6] Refactor to accept multiple different modes easily,
implement simple mode that sends static messages for maximum floodness
---
README.adoc | 10 ++-
.../com/teragrep/rlp_10/FlooderConfig.java | 4 +-
src/main/java/com/teragrep/rlp_10/Main.java | 49 ++++++----
.../teragrep/rlp_10/SimpleRecordIterator.java | 89 +++++++++++++++++++
.../rlp_10/SimpleRecordIteratorFactory.java | 64 +++++++++++++
5 files changed, 197 insertions(+), 19 deletions(-)
create mode 100644 src/main/java/com/teragrep/rlp_10/SimpleRecordIterator.java
create mode 100644 src/main/java/com/teragrep/rlp_10/SimpleRecordIteratorFactory.java
diff --git a/README.adoc b/README.adoc
index 9345f7c..ef42998 100644
--- a/README.adoc
+++ b/README.adoc
@@ -38,11 +38,19 @@ Standalone version of https://github.com/teragrep/rlp_09[rlp_09]
|payloadSize|10|Record extra padding
|reportInterval|10|How often report should be printed
|maxRecordsSent|-1|How many records should be sent (-1 for infinity). By default, this is per-thread but with usePerThreadIterator=false it is the total amount.
-|usePerThreadIterator|true|Should each thread act as an independent iterator (will send maxRecordsSent * threads amount of records)
|connectTimeout|5|Seconds to wait while connecting
|waitForAcks|true|Whether to wait for acks or not. Recommended to keep on.
+|mode|simple|Which mode to use. See modes for more information
|===
+=== Modes
+
+simple: Will flood identical static messages until each thread has sent total of maxRecordsSent. Fastest.
+
+dynamic: Will flood dynamic messages until each thread has sent total of maxRecordsSent. Slower than simple but more dynamic content.
+
+dynamic-shared: Will flood dynamic messages until total of maxRecordsSent records are sent across all threads. Slowest mode.
+
== Contributing
You can involve yourself with our project by https://github.com/teragrep/rlp_10/issues/new/choose[opening an issue] or submitting a pull request.
diff --git a/src/main/java/com/teragrep/rlp_10/FlooderConfig.java b/src/main/java/com/teragrep/rlp_10/FlooderConfig.java
index 4f1920e..05be547 100644
--- a/src/main/java/com/teragrep/rlp_10/FlooderConfig.java
+++ b/src/main/java/com/teragrep/rlp_10/FlooderConfig.java
@@ -56,9 +56,9 @@ class FlooderConfig {
public final int payloadSize;
public final int reportInterval;
public final long maxRecordsSent;
- public final boolean usePerThreadIterator;
public final int connectTimeout;
public final boolean waitForAcks;
+ public final String mode;
public FlooderConfig() {
this.hostname = System.getProperty("hostname", "localhost");
this.appname = System.getProperty("appname", "rlp_10");
@@ -69,8 +69,8 @@ public FlooderConfig() {
this.payloadSize = Integer.parseInt(System.getProperty("payloadSize", "10"));
this.reportInterval = Integer.parseInt(System.getProperty("reportInterval", "10"));
this.maxRecordsSent = Long.parseLong(System.getProperty("maxRecordsSent", "-1"));
- this.usePerThreadIterator = Boolean.parseBoolean(System.getProperty("usePerThreadIterator", "true"));
this.connectTimeout = Integer.parseInt(System.getProperty("connectTimeout", "5"));
this.waitForAcks = Boolean.parseBoolean(System.getProperty("waitForAcks", "true"));
+ this.mode = System.getProperty("mode", "simple");
}
}
\ No newline at end of file
diff --git a/src/main/java/com/teragrep/rlp_10/Main.java b/src/main/java/com/teragrep/rlp_10/Main.java
index 2bd827b..8e98564 100644
--- a/src/main/java/com/teragrep/rlp_10/Main.java
+++ b/src/main/java/com/teragrep/rlp_10/Main.java
@@ -47,6 +47,7 @@
package com.teragrep.rlp_10;
import com.teragrep.rlp_09.RelpFlooderConfig;
+import com.teragrep.rlp_09.RelpFlooderIteratorFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -59,21 +60,37 @@ public static void main(String[] args) {
LOGGER.info("Using appname <[{}]>", flooderConfig.appname);
LOGGER.info("Adding <[{}]> characters to payload size", flooderConfig.payloadSize);
LOGGER.info("Sending records to: <[{}]:[{}]>", flooderConfig.target, flooderConfig.port);
- Flooder flooder;
- if(flooderConfig.usePerThreadIterator) {
- LOGGER.info(
- "Sending <[{}]> records per thread, total of <[{}]> records",
- flooderConfig.maxRecordsSent < 0 ? "infinite" : flooderConfig.maxRecordsSent,
- flooderConfig.maxRecordsSent < 0 ? "infinite" : flooderConfig.maxRecordsSent * flooderConfig.threads
- );
- flooder = new Flooder(relpFlooderConfig, new PerThreadRecordIteratorFactory(flooderConfig), flooderConfig.reportInterval);
- } else {
- LOGGER.info(
- "Sending total of <[{}]> records across all threads",
- flooderConfig.maxRecordsSent < 0 ? "infinite" : flooderConfig.maxRecordsSent
- );
- flooder = new Flooder(relpFlooderConfig, new SharedTotalRecordIteratorFactory(flooderConfig), flooderConfig.reportInterval);
+ LOGGER.info("Using <[{}]> mode", flooderConfig.mode);
+ RelpFlooderIteratorFactory relpFlooderIteratorFactory;
+ switch(flooderConfig.mode) {
+ case "simple":
+ LOGGER.info(
+ "Sending <[{}]> static records per thread, total of <[{}]> records",
+ flooderConfig.maxRecordsSent < 0 ? "infinite" : flooderConfig.maxRecordsSent,
+ flooderConfig.maxRecordsSent < 0 ? "infinite" : flooderConfig.maxRecordsSent * flooderConfig.threads
+ );
+ relpFlooderIteratorFactory = new SimpleRecordIteratorFactory(flooderConfig);
+ break;
+ case "dynamic":
+ LOGGER.info(
+ "Sending <[{}]> dynamic records per thread, total of <[{}]> records",
+ flooderConfig.maxRecordsSent < 0 ? "infinite" : flooderConfig.maxRecordsSent,
+ flooderConfig.maxRecordsSent < 0 ? "infinite" : flooderConfig.maxRecordsSent * flooderConfig.threads
+ );
+ relpFlooderIteratorFactory = new PerThreadRecordIteratorFactory(flooderConfig);
+ break;
+ case "dynamic-shared":
+ LOGGER.info(
+ "Sending total of <[{}]> dynamic records across all threads",
+ flooderConfig.maxRecordsSent < 0 ? "infinite" : flooderConfig.maxRecordsSent * flooderConfig.threads
+ );
+ relpFlooderIteratorFactory = new SharedTotalRecordIteratorFactory(flooderConfig);
+ break;
+ default:
+ LOGGER.error("Invalid mode <[{}]> selected", flooderConfig.mode);
+ throw new IllegalStateException("Unexpected mode: " + flooderConfig.mode);
}
+ Flooder flooder = new Flooder(relpFlooderConfig, relpFlooderIteratorFactory, flooderConfig.reportInterval);
LOGGER.info("Waiting for acks: <[{}]>", flooderConfig.waitForAcks);
LOGGER.info("TLS enabled (FIXME: Implement): <[{}]>", flooderConfig.useTls);
LOGGER.info("Reporting stats every <[{}]> seconds", flooderConfig.reportInterval);
@@ -83,7 +100,7 @@ public static void main(String[] args) {
try {
flooder.stop();
} catch (InterruptedException | RuntimeException e) {
- LOGGER.error("Failed to stop properly: {}", e.getMessage());
+ LOGGER.error("Failed to stop properly: <{}>", e.getMessage());
}
});
Runtime.getRuntime().addShutdownHook(shutdownHook);
@@ -91,7 +108,7 @@ public static void main(String[] args) {
flooder.flood();
}
catch (Exception e){
- LOGGER.error("Caught an error while flooding: {}", e.getMessage());
+ LOGGER.error("Caught an error while flooding: <{}>", e.getMessage());
}
System.exit(0);
}
diff --git a/src/main/java/com/teragrep/rlp_10/SimpleRecordIterator.java b/src/main/java/com/teragrep/rlp_10/SimpleRecordIterator.java
new file mode 100644
index 0000000..be55fe3
--- /dev/null
+++ b/src/main/java/com/teragrep/rlp_10/SimpleRecordIterator.java
@@ -0,0 +1,89 @@
+/*
+ * Teragrep RELP Flooder Client RLP_10
+ * Copyright (C) 2024 Suomen Kanuuna Oy
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ *
+ *
+ * Additional permission under GNU Affero General Public License version 3
+ * section 7
+ *
+ * If you modify this Program, or any covered work, by linking or combining it
+ * with other code, such other code is not for that reason alone subject to any
+ * of the requirements of the GNU Affero GPL version 3 as long as this Program
+ * is the same Program as licensed from Suomen Kanuuna Oy without any additional
+ * modifications.
+ *
+ * Supplemented terms under GNU Affero General Public License version 3
+ * section 7
+ *
+ * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified
+ * versions must be marked as "Modified version of" The Program.
+ *
+ * Names of the licensors and authors may not be used for publicity purposes.
+ *
+ * No rights are granted for use of trade names, trademarks, or service marks
+ * which are in The Program if any.
+ *
+ * Licensee must indemnify licensors and authors for any liability that these
+ * contractual assumptions impose on licensors and authors.
+ *
+ * To the extent this program is licensed as part of the Commercial versions of
+ * Teragrep, the applicable Commercial License may apply to this file if you as
+ * a licensee so wish it.
+ */
+
+package com.teragrep.rlp_10;
+
+import com.teragrep.rlo_14.Facility;
+import com.teragrep.rlo_14.Severity;
+import com.teragrep.rlo_14.SyslogMessage;
+
+import java.time.Instant;
+import java.util.Iterator;
+
+class SimpleRecordIterator implements Iterator {
+ private int current=0;
+ private final byte[] record;
+ private final FlooderConfig flooderConfig;
+ public SimpleRecordIterator(FlooderConfig flooderConfig, int threadId) {
+ this.flooderConfig = flooderConfig;
+ this.record = new SyslogMessage()
+ .withTimestamp(Instant.now().toEpochMilli())
+ .withAppName(flooderConfig.appname)
+ .withHostname(flooderConfig.hostname)
+ .withFacility(Facility.USER)
+ .withSeverity(Severity.INFORMATIONAL)
+ .withMsg(
+ String.format(
+ "Thread %s, padding: %s",
+ threadId,
+ new String(new char[flooderConfig.payloadSize]).replace("\0", "X")
+ )
+ )
+ .toRfc5424SyslogMessage()
+ .getBytes();
+ }
+
+ @Override
+ public boolean hasNext() {
+ return flooderConfig.maxRecordsSent <= -1 || current.
+ *
+ *
+ * Additional permission under GNU Affero General Public License version 3
+ * section 7
+ *
+ * If you modify this Program, or any covered work, by linking or combining it
+ * with other code, such other code is not for that reason alone subject to any
+ * of the requirements of the GNU Affero GPL version 3 as long as this Program
+ * is the same Program as licensed from Suomen Kanuuna Oy without any additional
+ * modifications.
+ *
+ * Supplemented terms under GNU Affero General Public License version 3
+ * section 7
+ *
+ * Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified
+ * versions must be marked as "Modified version of" The Program.
+ *
+ * Names of the licensors and authors may not be used for publicity purposes.
+ *
+ * No rights are granted for use of trade names, trademarks, or service marks
+ * which are in The Program if any.
+ *
+ * Licensee must indemnify licensors and authors for any liability that these
+ * contractual assumptions impose on licensors and authors.
+ *
+ * To the extent this program is licensed as part of the Commercial versions of
+ * Teragrep, the applicable Commercial License may apply to this file if you as
+ * a licensee so wish it.
+ */
+
+package com.teragrep.rlp_10;
+
+import com.teragrep.rlp_09.RelpFlooderIteratorFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Iterator;
+
+public class SimpleRecordIteratorFactory implements RelpFlooderIteratorFactory {
+ private final FlooderConfig flooderConfig;
+ SimpleRecordIteratorFactory(FlooderConfig flooderConfig) {
+ this.flooderConfig = flooderConfig;
+ }
+ @Override
+ public Iterator get(int threadId) {
+ return new PerThreadRecordIterator(flooderConfig, threadId);
+ }
+}
From 030643688f7b1a10e8c28c3835cbb49ec85e6dba Mon Sep 17 00:00:00 2001
From: StrongestNumber9 <16169054+StrongestNumber9@users.noreply.github.com>
Date: Thu, 16 May 2024 12:28:29 +0300
Subject: [PATCH 3/6] Fixes SimpleRecordIterator, print thread count with mode
---
src/main/java/com/teragrep/rlp_10/Main.java | 2 +-
.../java/com/teragrep/rlp_10/SimpleRecordIteratorFactory.java | 4 +---
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/src/main/java/com/teragrep/rlp_10/Main.java b/src/main/java/com/teragrep/rlp_10/Main.java
index 8e98564..4370868 100644
--- a/src/main/java/com/teragrep/rlp_10/Main.java
+++ b/src/main/java/com/teragrep/rlp_10/Main.java
@@ -60,7 +60,7 @@ public static void main(String[] args) {
LOGGER.info("Using appname <[{}]>", flooderConfig.appname);
LOGGER.info("Adding <[{}]> characters to payload size", flooderConfig.payloadSize);
LOGGER.info("Sending records to: <[{}]:[{}]>", flooderConfig.target, flooderConfig.port);
- LOGGER.info("Using <[{}]> mode", flooderConfig.mode);
+ LOGGER.info("Using <[{}]> mode with <[{}]> threads", flooderConfig.mode, flooderConfig.threads);
RelpFlooderIteratorFactory relpFlooderIteratorFactory;
switch(flooderConfig.mode) {
case "simple":
diff --git a/src/main/java/com/teragrep/rlp_10/SimpleRecordIteratorFactory.java b/src/main/java/com/teragrep/rlp_10/SimpleRecordIteratorFactory.java
index 16f9904..98ab25f 100644
--- a/src/main/java/com/teragrep/rlp_10/SimpleRecordIteratorFactory.java
+++ b/src/main/java/com/teragrep/rlp_10/SimpleRecordIteratorFactory.java
@@ -47,8 +47,6 @@
package com.teragrep.rlp_10;
import com.teragrep.rlp_09.RelpFlooderIteratorFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.util.Iterator;
@@ -59,6 +57,6 @@ public class SimpleRecordIteratorFactory implements RelpFlooderIteratorFactory
}
@Override
public Iterator get(int threadId) {
- return new PerThreadRecordIterator(flooderConfig, threadId);
+ return new SimpleRecordIterator(flooderConfig, threadId);
}
}
From 5a93d145fbebfc61a9e0f64f75be3c5840d444ce Mon Sep 17 00:00:00 2001
From: StrongestNumber9 <16169054+StrongestNumber9@users.noreply.github.com>
Date: Mon, 17 Jun 2024 15:04:14 +0300
Subject: [PATCH 4/6] Updates to logging settings
---
pom.xml | 23 +++++++++-----
.../java/com/teragrep/rlp_10/Flooder.java | 2 +-
.../com/teragrep/rlp_10/FlooderConfig.java | 31 ++++++++++++-------
src/main/java/com/teragrep/rlp_10/Main.java | 19 +++++++++++-
.../rlp_10/PerThreadRecordIterator.java | 7 ++---
.../PerThreadRecordIteratorFactory.java | 2 +-
.../rlp_10/SharedTotalRecordIterator.java | 7 ++---
.../SharedTotalRecordIteratorFactory.java | 2 +-
.../teragrep/rlp_10/SimpleRecordIterator.java | 9 +++---
.../rlp_10/SimpleRecordIteratorFactory.java | 2 +-
src/main/resources/log4j2.xml | 13 ++++++++
11 files changed, 79 insertions(+), 38 deletions(-)
create mode 100644 src/main/resources/log4j2.xml
diff --git a/pom.xml b/pom.xml
index 2910c5f..4e46a26 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,9 +14,10 @@
-SNAPSHOT
4.2.25
- 3.0.0
- 2.22.1
- 2.0.5
+ 0.0.2-SNAPSHOT
+ 2.23.1
+ 2.0.13
+ 2.18.0
@@ -32,22 +33,26 @@
${rlp_09.version}
+
+ org.apache.logging.log4j
+ log4j-api
+ ${log4j2.version}
+
org.apache.logging.log4j
log4j-core
${log4j2.version}
- org.slf4j
- slf4j-api
- ${slf4j.version}
+ org.apache.logging.log4j
+ log4j-slf4j2-impl
+ ${log4j2.version}
org.slf4j
- slf4j-simple
+ slf4j-api
${slf4j.version}
-
${artifactId}-${revision}${changelist}${sha1}
@@ -92,6 +97,8 @@
rpm/**
src/main/assembly/jar-with-dependencies.xml
+
+ src/main/resources/log4j2.xml
README.adoc
diff --git a/src/main/java/com/teragrep/rlp_10/Flooder.java b/src/main/java/com/teragrep/rlp_10/Flooder.java
index cd3f28b..8f68d63 100644
--- a/src/main/java/com/teragrep/rlp_10/Flooder.java
+++ b/src/main/java/com/teragrep/rlp_10/Flooder.java
@@ -148,7 +148,7 @@ public void flood() {
relpFlooder.start();
}
- void stop() throws InterruptedException {
+ void stop() {
relpFlooder.stop();
consoleReporter.stop();
}
diff --git a/src/main/java/com/teragrep/rlp_10/FlooderConfig.java b/src/main/java/com/teragrep/rlp_10/FlooderConfig.java
index 05be547..697d58f 100644
--- a/src/main/java/com/teragrep/rlp_10/FlooderConfig.java
+++ b/src/main/java/com/teragrep/rlp_10/FlooderConfig.java
@@ -46,6 +46,8 @@
package com.teragrep.rlp_10;
+import java.util.Properties;
+
class FlooderConfig {
public final String hostname;
public final String appname;
@@ -59,18 +61,23 @@ class FlooderConfig {
public final int connectTimeout;
public final boolean waitForAcks;
public final String mode;
+ public final String logging;
public FlooderConfig() {
- this.hostname = System.getProperty("hostname", "localhost");
- this.appname = System.getProperty("appname", "rlp_10");
- this.target = System.getProperty("target", "127.0.0.1");
- this.port = Integer.parseInt(System.getProperty("port", "1601"));
- this.threads = Integer.parseInt(System.getProperty("threads", "4"));
- this.useTls = Boolean.parseBoolean(System.getProperty("useTls", "false"));
- this.payloadSize = Integer.parseInt(System.getProperty("payloadSize", "10"));
- this.reportInterval = Integer.parseInt(System.getProperty("reportInterval", "10"));
- this.maxRecordsSent = Long.parseLong(System.getProperty("maxRecordsSent", "-1"));
- this.connectTimeout = Integer.parseInt(System.getProperty("connectTimeout", "5"));
- this.waitForAcks = Boolean.parseBoolean(System.getProperty("waitForAcks", "true"));
- this.mode = System.getProperty("mode", "simple");
+ this(System.getProperties());
+ }
+ public FlooderConfig(Properties properties) {
+ this.hostname = properties.getProperty("hostname", "localhost");
+ this.appname = properties.getProperty("appname", "rlp_10");
+ this.target = properties.getProperty("target", "127.0.0.1");
+ this.port = Integer.parseInt(properties.getProperty("port", "1601"));
+ this.threads = Integer.parseInt(properties.getProperty("threads", "4"));
+ this.useTls = Boolean.parseBoolean(properties.getProperty("useTls", "false"));
+ this.payloadSize = Integer.parseInt(properties.getProperty("payloadSize", "10"));
+ this.reportInterval = Integer.parseInt(properties.getProperty("reportInterval", "10"));
+ this.maxRecordsSent = Long.parseLong(properties.getProperty("maxRecordsSent", "-1"));
+ this.connectTimeout = Integer.parseInt(properties.getProperty("connectTimeout", "5"));
+ this.waitForAcks = Boolean.parseBoolean(properties.getProperty("waitForAcks", "true"));
+ this.mode = properties.getProperty("mode", "simple");
+ this.logging = properties.getProperty("logging", "info");
}
}
\ No newline at end of file
diff --git a/src/main/java/com/teragrep/rlp_10/Main.java b/src/main/java/com/teragrep/rlp_10/Main.java
index 4370868..872d163 100644
--- a/src/main/java/com/teragrep/rlp_10/Main.java
+++ b/src/main/java/com/teragrep/rlp_10/Main.java
@@ -48,6 +48,8 @@
import com.teragrep.rlp_09.RelpFlooderConfig;
import com.teragrep.rlp_09.RelpFlooderIteratorFactory;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -55,6 +57,21 @@ class Main {
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
public static void main(String[] args) {
FlooderConfig flooderConfig = new FlooderConfig();
+ switch(flooderConfig.logging) {
+ case "info":
+ Configurator.setRootLevel(Level.INFO);
+ break;
+ case "debug":
+ Configurator.setRootLevel(Level.DEBUG);
+ break;
+ case "trace":
+ Configurator.setRootLevel(Level.TRACE);
+ break;
+ default:
+ LOGGER.error("Invalid logging level <[{}]>", flooderConfig.logging);
+ throw new IllegalStateException("Invalid logging level: " + flooderConfig.logging);
+ }
+ LOGGER.info("Logging level <[{}]>", flooderConfig.logging);
RelpFlooderConfig relpFlooderConfig = new RelpFlooderConfig(flooderConfig.target, flooderConfig.port, flooderConfig.threads, flooderConfig.connectTimeout, flooderConfig.waitForAcks);
LOGGER.info("Using hostname <[{}]>", flooderConfig.hostname);
LOGGER.info("Using appname <[{}]>", flooderConfig.appname);
@@ -99,7 +116,7 @@ public static void main(String[] args) {
LOGGER.info("Shutting down...");
try {
flooder.stop();
- } catch (InterruptedException | RuntimeException e) {
+ } catch (RuntimeException e) {
LOGGER.error("Failed to stop properly: <{}>", e.getMessage());
}
});
diff --git a/src/main/java/com/teragrep/rlp_10/PerThreadRecordIterator.java b/src/main/java/com/teragrep/rlp_10/PerThreadRecordIterator.java
index 78a580b..22a9d4f 100644
--- a/src/main/java/com/teragrep/rlp_10/PerThreadRecordIterator.java
+++ b/src/main/java/com/teragrep/rlp_10/PerThreadRecordIterator.java
@@ -53,7 +53,7 @@
import java.time.Instant;
import java.util.Iterator;
-class PerThreadRecordIterator implements Iterator {
+class PerThreadRecordIterator implements Iterator {
private int current=0;
private final FlooderConfig flooderConfig;
private final String padding;
@@ -75,7 +75,7 @@ public boolean hasNext() {
}
@Override
- public byte[] next() {
+ public String next() {
return new SyslogMessage()
.withTimestamp(Instant.now().toEpochMilli())
.withAppName(flooderConfig.appname)
@@ -83,7 +83,6 @@ public byte[] next() {
.withFacility(Facility.USER)
.withSeverity(Severity.INFORMATIONAL)
.withMsg(createMessage())
- .toRfc5424SyslogMessage()
- .getBytes();
+ .toRfc5424SyslogMessage();
}
}
diff --git a/src/main/java/com/teragrep/rlp_10/PerThreadRecordIteratorFactory.java b/src/main/java/com/teragrep/rlp_10/PerThreadRecordIteratorFactory.java
index be811ab..7e23ebd 100644
--- a/src/main/java/com/teragrep/rlp_10/PerThreadRecordIteratorFactory.java
+++ b/src/main/java/com/teragrep/rlp_10/PerThreadRecordIteratorFactory.java
@@ -56,7 +56,7 @@ public class PerThreadRecordIteratorFactory implements RelpFlooderIteratorFactor
this.flooderConfig = flooderConfig;
}
@Override
- public Iterator get(int threadId) {
+ public Iterator get(int threadId) {
return new PerThreadRecordIterator(flooderConfig, threadId);
}
}
diff --git a/src/main/java/com/teragrep/rlp_10/SharedTotalRecordIterator.java b/src/main/java/com/teragrep/rlp_10/SharedTotalRecordIterator.java
index 3b87b02..6c323a0 100644
--- a/src/main/java/com/teragrep/rlp_10/SharedTotalRecordIterator.java
+++ b/src/main/java/com/teragrep/rlp_10/SharedTotalRecordIterator.java
@@ -54,7 +54,7 @@
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicInteger;
-class SharedTotalRecordIterator implements Iterator {
+class SharedTotalRecordIterator implements Iterator {
private final AtomicInteger recordsSent;
private final FlooderConfig flooderConfig;
private final String padding;
@@ -78,7 +78,7 @@ public boolean hasNext() {
}
@Override
- public byte[] next() {
+ public String next() {
return new SyslogMessage()
.withTimestamp(Instant.now().toEpochMilli())
.withAppName(flooderConfig.appname)
@@ -86,7 +86,6 @@ public byte[] next() {
.withFacility(Facility.USER)
.withSeverity(Severity.INFORMATIONAL)
.withMsg(createMessage())
- .toRfc5424SyslogMessage()
- .getBytes();
+ .toRfc5424SyslogMessage();
}
}
diff --git a/src/main/java/com/teragrep/rlp_10/SharedTotalRecordIteratorFactory.java b/src/main/java/com/teragrep/rlp_10/SharedTotalRecordIteratorFactory.java
index 4b54644..d31c5c7 100644
--- a/src/main/java/com/teragrep/rlp_10/SharedTotalRecordIteratorFactory.java
+++ b/src/main/java/com/teragrep/rlp_10/SharedTotalRecordIteratorFactory.java
@@ -58,7 +58,7 @@ public class SharedTotalRecordIteratorFactory implements RelpFlooderIteratorFact
this.flooderConfig = flooderConfig;
}
@Override
- public Iterator get(int threadId) {
+ public Iterator get(int threadId) {
return new SharedTotalRecordIterator(flooderConfig, threadId, recordsSent);
}
}
diff --git a/src/main/java/com/teragrep/rlp_10/SimpleRecordIterator.java b/src/main/java/com/teragrep/rlp_10/SimpleRecordIterator.java
index be55fe3..a61f385 100644
--- a/src/main/java/com/teragrep/rlp_10/SimpleRecordIterator.java
+++ b/src/main/java/com/teragrep/rlp_10/SimpleRecordIterator.java
@@ -53,9 +53,9 @@
import java.time.Instant;
import java.util.Iterator;
-class SimpleRecordIterator implements Iterator {
+class SimpleRecordIterator implements Iterator {
private int current=0;
- private final byte[] record;
+ private final String record;
private final FlooderConfig flooderConfig;
public SimpleRecordIterator(FlooderConfig flooderConfig, int threadId) {
this.flooderConfig = flooderConfig;
@@ -72,8 +72,7 @@ public SimpleRecordIterator(FlooderConfig flooderConfig, int threadId) {
new String(new char[flooderConfig.payloadSize]).replace("\0", "X")
)
)
- .toRfc5424SyslogMessage()
- .getBytes();
+ .toRfc5424SyslogMessage();
}
@Override
@@ -82,7 +81,7 @@ public boolean hasNext() {
}
@Override
- public byte[] next() {
+ public String next() {
current++;
return record;
}
diff --git a/src/main/java/com/teragrep/rlp_10/SimpleRecordIteratorFactory.java b/src/main/java/com/teragrep/rlp_10/SimpleRecordIteratorFactory.java
index 98ab25f..7d96f82 100644
--- a/src/main/java/com/teragrep/rlp_10/SimpleRecordIteratorFactory.java
+++ b/src/main/java/com/teragrep/rlp_10/SimpleRecordIteratorFactory.java
@@ -56,7 +56,7 @@ public class SimpleRecordIteratorFactory implements RelpFlooderIteratorFactory
this.flooderConfig = flooderConfig;
}
@Override
- public Iterator get(int threadId) {
+ public Iterator get(int threadId) {
return new SimpleRecordIterator(flooderConfig, threadId);
}
}
diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml
new file mode 100644
index 0000000..bb869be
--- /dev/null
+++ b/src/main/resources/log4j2.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
From f9a59c08757fee56ed521dae161626b151e4ac56 Mon Sep 17 00:00:00 2001
From: StrongestNumber9 <16169054+StrongestNumber9@users.noreply.github.com>
Date: Mon, 17 Jun 2024 15:43:53 +0300
Subject: [PATCH 5/6] Adds some logging granularity
---
pom.xml | 1 -
.../java/com/teragrep/rlp_10/Flooder.java | 28 +++++++++++++++++--
.../com/teragrep/rlp_10/FlooderConfig.java | 10 +++++--
src/main/java/com/teragrep/rlp_10/Main.java | 20 +++----------
4 files changed, 38 insertions(+), 21 deletions(-)
diff --git a/pom.xml b/pom.xml
index 4e46a26..396506e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -17,7 +17,6 @@
0.0.2-SNAPSHOT
2.23.1
2.0.13
- 2.18.0
diff --git a/src/main/java/com/teragrep/rlp_10/Flooder.java b/src/main/java/com/teragrep/rlp_10/Flooder.java
index 8f68d63..299ea7e 100644
--- a/src/main/java/com/teragrep/rlp_10/Flooder.java
+++ b/src/main/java/com/teragrep/rlp_10/Flooder.java
@@ -52,6 +52,8 @@
import com.teragrep.rlp_09.RelpFlooder;
import com.teragrep.rlp_09.RelpFlooderConfig;
import com.teragrep.rlp_09.RelpFlooderIteratorFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.time.Instant;
import java.util.HashMap;
@@ -65,6 +67,7 @@ class Flooder {
private final ConsoleReporter consoleReporter;
private Instant startTime;
private final int reportInterval;
+ private static final Logger LOGGER = LoggerFactory.getLogger(Flooder.class);
public Flooder(RelpFlooderConfig relpFlooderConfig, RelpFlooderIteratorFactory relpFlooderIteratorFactory, int reportInterval) {
this.relpFlooder = new RelpFlooder(relpFlooderConfig, relpFlooderIteratorFactory);
MetricRegistry metricRegistry = new MetricRegistry();
@@ -92,64 +95,85 @@ public Flooder(RelpFlooderConfig relpFlooderConfig, RelpFlooderIteratorFactory r
}
private String reportElapsed() {
+ LOGGER.trace("Reporting Elapsed");
float elapsed = reportElapsedSeconds();
return String.format("%d:%02d", (int) Math.floor(elapsed/60), (int) elapsed%60);
}
private float reportElapsedSeconds() {
+ LOGGER.trace("Reporting ElapsedSeconds");
return (Instant.now().toEpochMilli()-startTime.toEpochMilli())/1000f;
}
private float reportTotalMegaBytesSent() {
+ LOGGER.trace("Reporting TotalMegabytesSent");
return relpFlooder.getTotalBytesSent()/1024f/1024f;
}
private float reportMegaBytesSentPerSecond() {
+ LOGGER.trace("Reporting TotalMegabytesSentPerSecond");
Instant now = Instant.now();
float elapsed = (now.toEpochMilli() - startTime.toEpochMilli()) / 1000f;
return relpFlooder.getTotalBytesSent()/1024f/1024f/elapsed;
}
private Float reportRecordsPerSecond() {
+ LOGGER.trace("Reporting RecordsPerSecond");
Instant now = Instant.now();
float elapsed = (now.toEpochMilli() - startTime.toEpochMilli()) / 1000f;
return relpFlooder.getTotalRecordsSent()/elapsed;
}
private HashMap reportRecordsPerSecondPerThread() {
+ LOGGER.trace("Reporting RecordsPerSecondPerThread");
Instant now = Instant.now();
float elapsed = (now.toEpochMilli() - startTime.toEpochMilli())/1000f;
HashMap recordsPerThread = new HashMap<>();
for(Map.Entry entry : relpFlooder.getRecordsSentPerThread().entrySet()) {
- recordsPerThread.put(entry.getKey(), entry.getValue()/elapsed);
+ int key = entry.getKey();
+ float value = entry.getValue()/elapsed;
+ LOGGER.debug("Adding key <{}>, value <{}> to RecordsPerSecondPerThread", key, value);
+ recordsPerThread.put(key, value);
}
return recordsPerThread;
}
private Float reportBytesPerSecond() {
+ LOGGER.trace("Reporting BytesPerSecond");
Instant now = Instant.now();
float elapsed = (now.toEpochMilli() - startTime.toEpochMilli()) / 1000f;
return relpFlooder.getTotalBytesSent()/elapsed;
}
private HashMap reportBytesPerSecondPerThread() {
+ LOGGER.trace("Reporting BytesPerSecondPerThread");
Instant now = Instant.now();
float elapsed = (now.toEpochMilli() - startTime.toEpochMilli())/1000f;
HashMap bytesPerThread = new HashMap<>();
for(Map.Entry entry : relpFlooder.getTotalBytesSentPerThread().entrySet()) {
- bytesPerThread.put(entry.getKey(), entry.getValue()/elapsed);
+ int key = entry.getKey();
+ float value = entry.getValue()/elapsed;
+ LOGGER.debug("Adding key <{}>, value <{}> to BytesPerSecondPerThread", key, value);
+ bytesPerThread.put(key, value);
}
return bytesPerThread;
}
public void flood() {
+ LOGGER.trace("Entering flood()");
startTime = Instant.now();
consoleReporter.start(reportInterval, TimeUnit.SECONDS);
+ LOGGER.trace("Running relpFlooder.start()");
relpFlooder.start();
+ LOGGER.trace("Exiting flood()");
}
void stop() {
+ LOGGER.trace("Entering stop()");
+ LOGGER.trace("Stopping RelpFlooder");
relpFlooder.stop();
+ LOGGER.trace("Stopping ConsoleReporter");
consoleReporter.stop();
+ LOGGER.trace("Exiting stop()");
}
}
\ No newline at end of file
diff --git a/src/main/java/com/teragrep/rlp_10/FlooderConfig.java b/src/main/java/com/teragrep/rlp_10/FlooderConfig.java
index 697d58f..ca7d56c 100644
--- a/src/main/java/com/teragrep/rlp_10/FlooderConfig.java
+++ b/src/main/java/com/teragrep/rlp_10/FlooderConfig.java
@@ -46,6 +46,8 @@
package com.teragrep.rlp_10;
+import org.apache.logging.log4j.Level;
+
import java.util.Properties;
class FlooderConfig {
@@ -61,7 +63,9 @@ class FlooderConfig {
public final int connectTimeout;
public final boolean waitForAcks;
public final String mode;
- public final String logging;
+ public final Level selfLogging;
+ public final Level libLogging;
+ public final Level globalLogging;
public FlooderConfig() {
this(System.getProperties());
}
@@ -78,6 +82,8 @@ public FlooderConfig(Properties properties) {
this.connectTimeout = Integer.parseInt(properties.getProperty("connectTimeout", "5"));
this.waitForAcks = Boolean.parseBoolean(properties.getProperty("waitForAcks", "true"));
this.mode = properties.getProperty("mode", "simple");
- this.logging = properties.getProperty("logging", "info");
+ this.selfLogging = Level.toLevel(properties.getProperty("selfLogging", "info"), Level.INFO);
+ this.libLogging = Level.toLevel(properties.getProperty("libLogging", "info"), Level.INFO);
+ this.globalLogging = Level.toLevel(properties.getProperty("globalLogging", "info"), Level.INFO);
}
}
\ No newline at end of file
diff --git a/src/main/java/com/teragrep/rlp_10/Main.java b/src/main/java/com/teragrep/rlp_10/Main.java
index 872d163..7c2eea5 100644
--- a/src/main/java/com/teragrep/rlp_10/Main.java
+++ b/src/main/java/com/teragrep/rlp_10/Main.java
@@ -48,7 +48,6 @@
import com.teragrep.rlp_09.RelpFlooderConfig;
import com.teragrep.rlp_09.RelpFlooderIteratorFactory;
-import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -57,21 +56,10 @@ class Main {
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
public static void main(String[] args) {
FlooderConfig flooderConfig = new FlooderConfig();
- switch(flooderConfig.logging) {
- case "info":
- Configurator.setRootLevel(Level.INFO);
- break;
- case "debug":
- Configurator.setRootLevel(Level.DEBUG);
- break;
- case "trace":
- Configurator.setRootLevel(Level.TRACE);
- break;
- default:
- LOGGER.error("Invalid logging level <[{}]>", flooderConfig.logging);
- throw new IllegalStateException("Invalid logging level: " + flooderConfig.logging);
- }
- LOGGER.info("Logging level <[{}]>", flooderConfig.logging);
+ Configurator.setLevel("com.teragrep.rlp_10", flooderConfig.selfLogging);
+ Configurator.setLevel("com.teragrep.rlp_09", flooderConfig.libLogging);
+ Configurator.setRootLevel(flooderConfig.globalLogging);
+ LOGGER.info("Using self logging level <[{}]>, lib logging level <[{}]>, global logging level <[{}]>", flooderConfig.selfLogging, flooderConfig.libLogging, flooderConfig.globalLogging);
RelpFlooderConfig relpFlooderConfig = new RelpFlooderConfig(flooderConfig.target, flooderConfig.port, flooderConfig.threads, flooderConfig.connectTimeout, flooderConfig.waitForAcks);
LOGGER.info("Using hostname <[{}]>", flooderConfig.hostname);
LOGGER.info("Using appname <[{}]>", flooderConfig.appname);
From f2153204a1280ba5e46f6d8d425eb6ca0822257c Mon Sep 17 00:00:00 2001
From: StrongestNumber9 <16169054+StrongestNumber9@users.noreply.github.com>
Date: Tue, 18 Jun 2024 08:59:18 +0300
Subject: [PATCH 6/6] Use java 17
---
.github/workflows/release.yaml | 2 +-
pom.xml | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
index 5adfaa6..a4ca0e5 100644
--- a/.github/workflows/release.yaml
+++ b/.github/workflows/release.yaml
@@ -17,7 +17,7 @@ jobs:
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
- java-version: '8'
+ java-version: 17
distribution: 'temurin'
server-id: github
settings-path: ${{ github.workspace }}
diff --git a/pom.xml b/pom.xml
index 396506e..4ad0cee 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,9 +7,9 @@
rlp_10
UTF-8
- 8
- 8
- 8
+ 17
+ 17
+ 17
0.0.1
-SNAPSHOT