Skip to content

Commit

Permalink
Adds null input functionality for rfc5424, build defaults if nothing … (
Browse files Browse the repository at this point in the history
#20)

* Adds null input functionality for rfc5424, build defaults if nothing given, add some perf tests

* Remove nulls, revert back to default of not subscribing to anything
  • Loading branch information
StrongestNumber9 authored Aug 3, 2023
1 parent 1a0138a commit 416a26f
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 6 deletions.
16 changes: 16 additions & 0 deletions src/main/java/com/teragrep/rlo_06/RFC5424Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ public final class RFC5424Parser {
private final ParserResultSet resultset;
private final Consumer<Stream> streamConsumer;

public RFC5424Parser() {
this(new InputStream() {
@Override
public int read() {
return -1;
}
});
}

public RFC5424Parser(InputStream inputStream) {
this(inputStream, new RFC5424ParserSubscription());
}
public RFC5424Parser(InputStream inputStream, RFC5424ParserSubscription subscription) {
this(inputStream, subscription, new RFC5424ParserSDSubscription());
}

public RFC5424Parser(InputStream inputStream, RFC5424ParserSubscription subscription, RFC5424ParserSDSubscription sdSubscription) {
this(inputStream, subscription, sdSubscription, true);
}
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/com/teragrep/rlo_06/EmptyParserInputTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.teragrep.rlo_06;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

public class EmptyParserInputTest {
@Test
void testEmptyParserInput() throws IOException {
// Should not break but also should not return any data
RFC5424Parser parser = new RFC5424Parser();
Assertions.assertFalse(parser.next());
ResultSetAsString resultsetAsString = new ResultSetAsString(parser.get());
}
}
111 changes: 105 additions & 6 deletions src/test/java/com/teragrep/rlo_06/tests/PerformanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@
*/
package com.teragrep.rlo_06.tests;

import com.teragrep.rlo_06.ParserResultSet;
import com.teragrep.rlo_06.RFC5424Parser;
import com.teragrep.rlo_06.RFC5424ParserSDSubscription;
import com.teragrep.rlo_06.RFC5424ParserSubscription;
import com.teragrep.rlo_06.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
Expand Down Expand Up @@ -117,8 +114,110 @@ void testShortPayloadPerformance() throws Exception {
long msgsize = (count * SYSLOG_MESSAGE.length())/1024/1024;
long spent = instant2.toEpochMilli()-instant1.toEpochMilli();
System.out.println("testShortPayloadPerformance: time taken " + spent + " for " + count +
", total RPS: " + (float) count/ ((float) spent/1000) +
", " + (float) msgsize + " megabytes (" + (float) (msgsize/((float)spent/1000)) + " MB/s)");
", total RPS: " + (float) count/ ((float) spent/1000) +
", " + (float) msgsize + " megabytes (" + (float) (msgsize/((float)spent/1000)) + " MB/s)");

}

@Test
@DisabledIfSystemProperty(named = "noPerfTest", matches = "true")
void testOnlyMsgSub() throws Exception {

String SYSLOG_MESSAGE = "<14>1 2014-06-20T09:14:07.12345+00:00 host01 systemd DEA MSG-01 [ID_A@1 u=\"\\\"3\" e=\"t\"][ID_B@2 n=\"9\"][event_id@48577 hostname=\"sc-99-99-14-247\" uuid=\"0FD92E51B37748EB90CD894CCEE63907\" unixtime=\"1612047600.0\" id_source=\"source\"][event_node_source@48577 hostname=\"sc-99-99-14-247\" source=\"f17_ssmis_20210131v7.nc\" source_module=\"imfile\"][event_node_relay@48577 hostname=\"localhost\" source=\"sc-99-99-14-247\" source_module=\"imrelp\"][event_version@48577 major=\"2\" minor=\"2\" hostname=\"localhost\" version_source=\"relay\"][event_node_router@48577 source=\"logrouter.example.com\" source_module=\"imrelp\" hostname=\"localhost\"][teragrep@48577 streamname=\"log:f17:0\" directory=\"com_teragrep_audit\" unixtime=\"1612047600.0\"] sigsegv\n";
RFC5424ParserSubscription subscription = new RFC5424ParserSubscription();
subscription.add(ParserEnum.MSG);

InputStream inputStream = new ByteArrayInputStream( SYSLOG_MESSAGE.getBytes());
RFC5424Parser parser = new RFC5424Parser(inputStream, subscription, null);


Instant instant1 = Instant.now();
long count = 10000000;
for (long i = 0; i < count; i++) {
Assertions.assertTrue(parser.next());
inputStream.reset();
}
Instant instant2 = Instant.now();

long msgsize = (count * SYSLOG_MESSAGE.length())/1024/1024;
long spent = instant2.toEpochMilli()-instant1.toEpochMilli();
System.out.println("testOnlyMsgSub: time taken " + spent + " for " + count +
", total RPS: " + (float) count/ ((float) spent/1000) +
", " + (float) msgsize + " megabytes (" + (float) (msgsize/((float)spent/1000)) + " MB/s)");

}

@Test
@DisabledIfSystemProperty(named = "noPerfTest", matches = "true")
void testNothingSub() throws Exception {

String SYSLOG_MESSAGE = "<14>1 2014-06-20T09:14:07.12345+00:00 host01 systemd DEA MSG-01 [ID_A@1 u=\"\\\"3\" e=\"t\"][ID_B@2 n=\"9\"][event_id@48577 hostname=\"sc-99-99-14-247\" uuid=\"0FD92E51B37748EB90CD894CCEE63907\" unixtime=\"1612047600.0\" id_source=\"source\"][event_node_source@48577 hostname=\"sc-99-99-14-247\" source=\"f17_ssmis_20210131v7.nc\" source_module=\"imfile\"][event_node_relay@48577 hostname=\"localhost\" source=\"sc-99-99-14-247\" source_module=\"imrelp\"][event_version@48577 major=\"2\" minor=\"2\" hostname=\"localhost\" version_source=\"relay\"][event_node_router@48577 source=\"logrouter.example.com\" source_module=\"imrelp\" hostname=\"localhost\"][teragrep@48577 streamname=\"log:f17:0\" directory=\"com_teragrep_audit\" unixtime=\"1612047600.0\"] sigsegv\n";
RFC5424ParserSubscription subscription = new RFC5424ParserSubscription();
InputStream inputStream = new ByteArrayInputStream( SYSLOG_MESSAGE.getBytes());
RFC5424Parser parser = new RFC5424Parser(inputStream, subscription);

Instant instant1 = Instant.now();
long count = 10000000;
for (long i = 0; i < count; i++) {
Assertions.assertTrue(parser.next());
inputStream.reset();
}
Instant instant2 = Instant.now();

long msgsize = (count * SYSLOG_MESSAGE.length())/1024/1024;
long spent = instant2.toEpochMilli()-instant1.toEpochMilli();
System.out.println("testNothingSub: time taken " + spent + " for " + count +
", total RPS: " + (float) count/ ((float) spent/1000) +
", " + (float) msgsize + " megabytes (" + (float) (msgsize/((float)spent/1000)) + " MB/s)");

}

@Test
@DisabledIfSystemProperty(named = "noPerfTest", matches = "true")
void testDashesFullSub() throws Exception {

String SYSLOG_MESSAGE = "<2>1 - - - - - ";
InputStream inputStream = new ByteArrayInputStream( SYSLOG_MESSAGE.getBytes());
RFC5424Parser parser = new RFC5424Parser(inputStream, null);

Instant instant1 = Instant.now();
long count = 100000000;
for (long i = 0; i < count; i++) {
Assertions.assertTrue(parser.next());
inputStream.reset();
}
Instant instant2 = Instant.now();

long msgsize = (count * SYSLOG_MESSAGE.length())/1024/1024;
long spent = instant2.toEpochMilli()-instant1.toEpochMilli();
System.out.println("testDashesFullSub: time taken " + spent + " for " + count +
", total RPS: " + (float) count/ ((float) spent/1000) +
", " + (float) msgsize + " megabytes (" + (float) (msgsize/((float)spent/1000)) + " MB/s)");

}

@Test
@DisabledIfSystemProperty(named = "noPerfTest", matches = "true")
void testDashesNoSub() throws Exception {

String SYSLOG_MESSAGE = "<2>1 - - - - - ";
RFC5424ParserSubscription subscription = new RFC5424ParserSubscription();
InputStream inputStream = new ByteArrayInputStream( SYSLOG_MESSAGE.getBytes());
RFC5424Parser parser = new RFC5424Parser(inputStream, subscription);

Instant instant1 = Instant.now();
long count = 100000000;
for (long i = 0; i < count; i++) {
Assertions.assertTrue(parser.next());
inputStream.reset();
}
Instant instant2 = Instant.now();

long msgsize = (count * SYSLOG_MESSAGE.length())/1024/1024;
long spent = instant2.toEpochMilli()-instant1.toEpochMilli();
System.out.println("testDashesNoSub: time taken " + spent + " for " + count +
", total RPS: " + (float) count/ ((float) spent/1000) +
", " + (float) msgsize + " megabytes (" + (float) (msgsize/((float)spent/1000)) + " MB/s)");

}
}

0 comments on commit 416a26f

Please sign in to comment.