use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.
the class TestBuilder method testLoadOnlyCompanyCustomFormatRules.
@Test
void testLoadOnlyCompanyCustomFormatRules() {
UserAgentAnalyzer userAgentAnalyzer = UserAgentAnalyzer.newBuilder().withoutCache().hideMatcherLoadStats().dropDefaultResources().addResources("CompanyInternalUserAgents.yaml").withFields("ApplicationName", "ApplicationVersion").withFields(Arrays.asList("ApplicationInstance", "ApplicationGitCommit")).withField("ServerName").build();
UserAgent parsedAgent = userAgentAnalyzer.parse("TestApplication/1.2.3 (node123.datacenter.example.nl; 1234; d71922715c2bfe29343644b14a4731bf5690e66e)");
// The requested fields
assertEquals("TestApplication", parsedAgent.getValue("ApplicationName"));
assertEquals("1.2.3", parsedAgent.getValue("ApplicationVersion"));
assertEquals("1234", parsedAgent.getValue("ApplicationInstance"));
assertEquals("d71922715c2bfe29343644b14a4731bf5690e66e", parsedAgent.getValue("ApplicationGitCommit"));
assertEquals("node123.datacenter.example.nl", parsedAgent.getValue("ServerName"));
}
use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.
the class TestMemoryFootprint method checkForMemoryLeaks.
@Disabled("This is too unreliable and fails much too often.")
@Test
void checkForMemoryLeaks() {
// ----------------------------------------------
long memoryInitial = getMemoryUsageAfterGC();
LOG.info(String.format("1: Startup + GC --> Used memory is %10d bytes (%5d MiB).", memoryInitial, bytesToMegabytes(memoryInitial)));
// ----------------------------------------------
UserAgentAnalyzer uaa = UserAgentAnalyzer.newBuilder().immediateInitialization().keepTests().build();
LOG.info("Init complete");
long memoryAfterInit = getMemoryUsageAfterGC();
LOG.info(String.format("2: Init Analyzer + GC --> Used memory is %10d bytes (%5d MiB).", memoryAfterInit, bytesToMegabytes(memoryAfterInit)));
// ----------------------------------------------
LOG.info("Run preheat");
uaa.preHeat();
LOG.info("Preheat completed");
long memoryAfterRun = getMemoryUsageAfterGC();
LOG.info(String.format("3: Run Analyzer + GC --> Used memory is %10d bytes (%5d MiB).", memoryAfterRun, bytesToMegabytes(memoryAfterRun)));
// ----------------------------------------------
long memoryAfterDestroy = getMemoryUsageAfterGC();
LOG.info(String.format("4: Destroy Analyzer + GC --> Used memory is %10d bytes (%5d MiB).", memoryAfterDestroy, bytesToMegabytes(memoryAfterDestroy)));
// ----------------------------------------------
long memoryAfterClean = getMemoryUsageAfterGC();
LOG.info(String.format("5: Null Analyzer + GC --> Used memory is %10d bytes (%5d MiB).", memoryAfterClean, bytesToMegabytes(memoryAfterClean)));
// ----------------------------------------------
// Assert the overall delta is below 20 MB
assertTrue((memoryAfterClean - memoryInitial) < 20_000_000, "To much memory remained after cleanup");
}
use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.
the class TestMemoryFootprint method profileMemoryFootprint.
@Disabled
@Test
void profileMemoryFootprint() {
// NOSONAR: Do not complain about ignored performance test
printCurrentMemoryProfile("Before ");
UserAgentAnalyzer uaa = UserAgentAnalyzer.newBuilder().hideMatcherLoadStats().withoutCache().keepTests().build();
printCurrentMemoryProfile("Loaded ");
uaa.initializeMatchers();
printCurrentMemoryProfile("Init ");
Runtime.getRuntime().gc();
printCurrentMemoryProfile("Post GC");
uaa.setCacheSize(1000);
uaa.preHeat();
Runtime.getRuntime().gc();
printCurrentMemoryProfile("Cache 1K");
uaa.setCacheSize(10000);
uaa.preHeat();
Runtime.getRuntime().gc();
printCurrentMemoryProfile("Cache 10K");
uaa.dropTests();
Runtime.getRuntime().gc();
printCurrentMemoryProfile("NoTest ");
}
use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.
the class TestMemoryFootprint method assesMemoryImpactPerFieldName.
@Disabled
@Test
void assesMemoryImpactPerFieldName() {
// NOSONAR: Do not complain about ignored performance test
// Get the Java runtime
Runtime runtime = Runtime.getRuntime();
// Calculate the used memory
long memory = runtime.totalMemory() - runtime.freeMemory();
LOG.error(String.format("Without Yauaa present and GC --> Used memory is %10d bytes (%5d MiB)", memory, bytesToMegabytes(memory)));
UserAgentAnalyzer uaa = UserAgentAnalyzer.newBuilder().hideMatcherLoadStats().withoutCache().keepTests().build();
uaa.preHeat();
runtime.gc();
uaa.preHeat();
runtime.gc();
// Calculate the used memory
memory = runtime.totalMemory() - runtime.freeMemory();
LOG.error(String.format("Querying for 'All fields' and GC --> Used memory is %10d bytes (%5d MiB)", memory, bytesToMegabytes(memory)));
for (String fieldName : uaa.getAllPossibleFieldNamesSorted()) {
uaa = UserAgentAnalyzer.newBuilder().withoutCache().withField(fieldName).hideMatcherLoadStats().keepTests().build();
uaa.preHeat();
runtime.gc();
uaa.preHeat();
runtime.gc();
// Calculate the used memory
memory = runtime.totalMemory() - runtime.freeMemory();
LOG.error(String.format("Querying for %s and GC --> Used memory is %10d bytes (%5d MiB)", fieldName, memory, bytesToMegabytes(memory)));
}
}
use of nl.basjes.parse.useragent.UserAgentAnalyzer in project yauaa by nielsbasjes.
the class TestUserAgentAnalyzerKryoSerialization method deserialize.
UserAgentAnalyzer deserialize(byte[] bytes) {
Kryo kryo = new Kryo();
UserAgentAnalyzer.configureKryo(kryo);
ByteBufferInput byteBufferInput = new ByteBufferInput(bytes);
return (UserAgentAnalyzer) kryo.readClassAndObject(byteBufferInput);
}
Aggregations