Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
* This example is available in full on [GitHub](https://github.com/51Degrees/51degrees-java/blob/main/examples/ip-intelligence/console/src/main/java/fiftyone/ipintelligence/examples/console/PerformanceBenchmark.java).
*
* By default the example uses the free Asn IP Intelligence data file, which it downloads when it
* is missing, and is far smaller than the Lite file. It asks for RegisteredName and AsnName, so
* it runs with any of the data files. To obtain an Enterprise data file, please
* is missing, and is far smaller than the Lite file. It asks only for the property it reads,
* being RegisteredName, or AsnName with the free Asn data file, which has no RegisteredName,
* so it runs with any of the data files. To obtain an Enterprise data file, please
* [contact us](https://51degrees.com/contact-us?utm_source=code&utm_medium=example&utm_campaign=51degrees-java&utm_content=console-src-main-java-fiftyone-ipintelligence-examples-console-performancebenchmark.java&utm_term=header).
*
* Required Maven Dependencies:
Expand All @@ -51,6 +52,7 @@
import fiftyone.ipintelligence.examples.shared.DataFileHelper;
import fiftyone.ipintelligence.examples.shared.EvidenceHelper;
import fiftyone.ipintelligence.engine.onpremise.flowelements.IPIntelligenceOnPremiseEngine;
import fiftyone.ipintelligence.engine.onpremise.flowelements.IPIntelligenceOnPremiseEngineBuilder;
import fiftyone.ipintelligence.shared.IPIntelligenceData;
import fiftyone.pipeline.core.data.FlowData;
import fiftyone.pipeline.core.data.IWeightedValue;
Expand Down Expand Up @@ -103,6 +105,8 @@ public class PerformanceBenchmark {
private int numberOfThreads = DEFAULT_NUMBER_OF_THREADS;
private List<Map<String, String>> evidence;
private String dataFileLocation;
// the properties asked for when not asking for all of them
private List<String> properties;
private PrintWriter writer;

// a default set of configurations: (profile, allProperties)
Expand Down Expand Up @@ -147,6 +151,7 @@ protected void runBenchmarks(PerformanceConfiguration[] performanceConfiguration
logger.info("Running Performance example");

this.dataFileLocation = getDataFileLocation(dataFilename);
this.properties = benchmarkProperties(dataFileLocation);

File evidenceFile = getEvidenceFile(evidenceFilename);
this.evidence = Collections.unmodifiableList(
Expand Down Expand Up @@ -237,13 +242,37 @@ private void setPipelinePerformanceProperties(
// Requesting properties from a single component
// reduces processing time compared with requesting properties from multiple components.
// If you don't specify any properties, then all properties are returned,
// here we choose "all properties" by specifying none, or just "RegisteredName"
// and "AsnName". The free Asn data file has AsnName, and the Lite and
// Enterprise data files have RegisteredName, so the benchmark runs
// with any of them.
// here we choose "all properties" by specifying none, or just the
// one property the benchmark reads, which benchmarkProperties
// chooses for the data file.
if (BooleanUtils.isFalse(config.allProperties)) {
builder.setProperty("RegisteredName");
builder.setProperty("AsnName");
for (String property : properties) {
builder.setProperty(property);
}
}
}

/**
* The properties the benchmark asks for when it does not ask for all of
* them, being only the one it reads. That is RegisteredName where the
* data file has it, as the Lite and Enterprise data files do, and
* AsnName for the free Asn data file, which has no RegisteredName. The
* data file is opened with the low memory profile, which reads little
* of it.
* @param dataFileLocation the data file the benchmark uses
* @return the one property to ask for
* @throws Exception if the data file cannot be opened
*/
static List<String> benchmarkProperties(String dataFileLocation)
throws Exception {
try (IPIntelligenceOnPremiseEngine engine =
new IPIntelligenceOnPremiseEngineBuilder()
.setPerformanceProfile(LowMemory)
.setAutoUpdate(false)
.build(dataFileLocation, false)) {
return Collections.singletonList(
DataFileHelper.hasProperty(engine, "RegisteredName") ?
"RegisteredName" : "AsnName");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* *********************************************************************
* This Original Work is copyright of 51 Degrees Mobile Experts Limited.
* Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House,
* Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU.
*
* This Original Work is licensed under the European Union Public Licence
* (EUPL) v.1.2 and is subject to its terms as set out below.
*
* If a copy of the EUPL was not distributed with this file, You can obtain
* one at https://opensource.org/licenses/EUPL-1.2.
*
* The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
* amended by the European Commission) shall be deemed incompatible for
* the purposes of the Work and the provisions of the compatibility
* clause in Article 5 of the EUPL shall not apply.
*
* If using the Work as, or as part of, a network application, by
* including the attribution notice(s) required under Article 5 of the EUPL
* in the end user terms of the application under an appropriate heading,
* such notice(s) shall fulfill the requirements of that article.
* ********************************************************************* */

package fiftyone.ipintelligence.examples.console;

import fiftyone.ipintelligence.examples.shared.DataFileHelper;
import org.junit.Test;

import java.util.Collections;

import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeTrue;

/**
* Checks that the performance benchmark asks only for the property it reads,
* being RegisteredName where the data file has it and AsnName for the free
* Asn data file, which has no RegisteredName.
*/
public class PerformanceBenchmarkPropertiesTest {

@Test
public void registeredNameAloneWhenTheDataFileHasIt() throws Exception {
String dataFile = DataFileHelper.findAvailableDataFile(
DataFileHelper.ENTERPRISE_DATA_FILE_REL_PATH,
DataFileHelper.LITE_DATA_FILE_REL_PATH);
assumeTrue("Skipping test, no IP Intelligence data file with the " +
"RegisteredName property found",
dataFile != null);
assertEquals(Collections.singletonList("RegisteredName"),
PerformanceBenchmark.benchmarkProperties(dataFile));
}

@Test
public void asnNameAloneWithTheAsnDataFile() throws Exception {
String dataFile = DataFileHelper.findAvailableDataFile(
DataFileHelper.ASN_DATA_FILE_REL_PATH);
assumeTrue("Skipping test, no free Asn IP Intelligence data file found",
dataFile != null);
assertEquals(Collections.singletonList("AsnName"),
PerformanceBenchmark.benchmarkProperties(dataFile));
}
}
Loading