Introduction
When using a PerformanceProfile that loads collections completely into memory, the API's ability to handle concurrent requests is only limited by the available hardware resources. However, when using a lower memory PerformanceProfile where collections are partially or fully read from file, consideration needs to be given to how many parallel threads will be accessing the Pipeline .
See the Specification for more technical details.
Detail
For PerformanceProfiles such as LowMemory and Balanced, the concurrency is limited by the number of file handles available in the file pool. In most implementations, the default value for this is the number of cores available on the machine. If more threads than this will be used, the expected concurrency must be configured when creating the engine, so that the file pool is created with the correct size to handle the expected number of concurrent accesses.
The snippet below shows how to set this when creating the engine:
C# Java Node.js PHP Python C C++ Rust Select a tab to view language specific information on setting the concurrency.
In code:
var pipeline = new DeviceDetectionPipelineBuilder(loggerFactory)
.UseOnPremise(dataFile, null , false )
.SetPerformanceProfile(PerformanceProfiles.LowMemory)
.SetConcurrency(threadCount)
.Build();
Or in config file:
"PipelineOptions": {
"Elements": [
{
"BuilderName": "DeviceDetectionHashEngineBuilder",
"BuildParameters": {
"DataFile": "51Degrees-LiteV4.1.hash",
"PerformanceProfile": "LowMemory",
"Concurrency": 30
}
}
...
]
}
In code:
DeviceDetectionOnPremisePipelineBuilder builder = new DeviceDetectionPipelineBuilder()
.useOnPremise(dataFileLocation, false )
.setPerformanceProfile(PerformanceProfiles.LowMemory)
.setConcurrency(threadCount)
.build();
Or in config file:
<PipelineOptions >
<Elements >
<Element >
<BuildParameters >
<DataFile >51Degrees-LiteV4.1.hash </DataFile >
<PerformanceProfile >LowMemory </PerformanceProfile >
<Concurrency >30</Concurrency >
</BuildParameters >
<BuilderName >DeviceDetectionHashEngine </BuilderName >
</Element >
...
</Elements >
</PipelineOptions >
In code:
const pipeline = new DeviceDetectionOnPremisePipelineBuilder({
dataFile: datafile,
performanceProfile: 'LowMemory',
concurrency: threadCount
}).build();
Or in config file:
"PipelineOptions": {
"Elements": [
{
"elementName": "deviceDetectionOnPremise",
"elementParameters": {
"performanceProfile": "LowMemmory",
"dataFilePath": "51Degrees-LiteV4.1.hash",
"concurrency": 30
}
}
...
]
}
For PHP, the concurrency options is set in the php.ini file.
extension=/usr/lib/php/20170718/FiftyOneDegreesHashEngine.so
FiftyOneDegreesHashEngine.data_file=/path to your file/51Degrees-LiteV4.1.hash
FiftyOneDegreesHashEngine.performance_profile=LowMemory
FiftyOneDegreesHashEngine.concurrency=30
In code:
pipeline = DeviceDetectionOnPremisePipelineBuilder(
data_file_path = data_file,
performance_profile = 'LowMemory' ,
concurrency = thread_count).build()
Or in config file:
"PipelineOptions": {
"Elements": [
{
"elementName": "DeviceDetectionOnPremise",
"elementPath": "fiftyone_devicedetection_onpremise.devicedetection_onpremise",
"elementParameters": {
"data_file_path": "51Degrees-LiteV4.1.hash",
"performance_profile": "LowMemory",
"concurrency": 30
}
}
...
]
}
ConfigHash config = HashLowMemoryConfig;
config.strings.concurrency = threadCount;
config.properties.concurrency = threadCount;
config.values.concurrency = threadCount;
config.profiles.concurrency = threadCount;
config.nodes.concurrency = threadCount;
config.profileOffsets.concurrency = threadCount;
config.maps.concurrency = threadCount;
config.components.concurrency = threadCount;
StatusCode status = HashInitManagerFromFile(
&manager,
&dataSetConfig,
&properties,
dataFileLocation,
exception);
ConfigHash* config = new ConfigHash();
config->setLowMemory();
config->setConcurrency(threadCount);
EngineHash *engine =
new DeviceDetection::Hash::EngineHash(
dataFilePath,
config,
properties);
In code:
use fiftyone_device_detection::{DeviceDetectionPipelineBuilder, PerformanceProfile};
let pipeline = DeviceDetectionPipelineBuilder::on_premise(data_file)
// Set the performance profile
.performance_profile(PerformanceProfile::LowMemory)
// Set the expected concurrency (the number of threads that will share the
// pipeline); this sizes the data set's file-handle pool.
.concurrency(thread_count)
.build()?;