Skip to content

Commit

Permalink
Merge pull request 7454 from hotfix/v4.4.10 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Project Collection Build Service (51degrees) authored and Project Collection Build Service (51degrees) committed Aug 9, 2022
2 parents b88112d + 824c29f commit c5f4681
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 21 deletions.
5 changes: 4 additions & 1 deletion Examples/OnPremise/AppleServerSideConfig-Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
using Constants = FiftyOne.DeviceDetection.Examples.Constants;

/// <summary>
/// @example OnPremise/AppleServerSide-Console/Program.cs
/// @example OnPremise/AppleServerSideConfig-Console/Program.cs
///
/// Detection of the specific models of Apple devices being used to make a request is
/// [more difficult](http://51degrees.com/documentation/4.4/_device_detection__features__apple_detection.html)
Expand All @@ -60,6 +60,9 @@
/// in the free, 'lite' data file.
/// See our [pricing page](http://51degrees.com/pricing) for details on how to obtain one.
///
/// This variation shows how to create the pipeline from a configuration file:
/// @include OnPremise/AppleServerSideConfig-Console/appsettings.json
///
/// Required NuGet Dependencies:
/// - FiftyOne.DeviceDetection
/// - Microsoft.Extensions.DependencyInjection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ public class PerformanceConfiguration
public bool AllProperties { get; set; }
public bool PerformanceGraph { get; set; }
public bool PredictiveGraph { get; set; }
public bool LoadFromDisk { get; set; }

public PerformanceConfiguration(PerformanceProfiles profile,
public PerformanceConfiguration(bool loadFromDisk, PerformanceProfiles profile,
bool allProperties, bool performanceGraph, bool predictiveGraph)
{
LoadFromDisk = loadFromDisk;
Profile = profile;
AllProperties = allProperties;
PerformanceGraph = performanceGraph;
Expand Down
61 changes: 44 additions & 17 deletions Examples/OnPremise/Performance-Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* such notice(s) shall fulfill the requirements of that article.
* ********************************************************************* */

using FiftyOne.DeviceDetection.Hash.Engine.OnPremise.FlowElements;
using FiftyOne.Pipeline.Core.FlowElements;
using FiftyOne.Pipeline.Engines;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -33,12 +34,12 @@
using System.Threading.Tasks;

/// <summary>
/// @example Hash/Performance/Program.cs
/// @example Performance-Console/Program.cs
///
/// The example illustrates a "clock-time" benchmark for assessing detection speed.
///
/// Using a YAML formatted evidence file - "20000 Evidence Records.yml" - supplied with the
/// distribution or can be obtained from the (data repository on Github)[https://github.com/51Degrees/device-detection-data/blob/master/20000%20Evidence%20Records.yml].
/// distribution or can be obtained from the [data repository on Github](https://github.com/51Degrees/device-detection-data/blob/master/20000%20Evidence%20Records.yml).
///
/// It's important to understand the trade-offs between performance, memory usage and accuracy, that
/// the 51Degrees pipeline configuration makes available, and this example shows a range of
Expand Down Expand Up @@ -73,12 +74,10 @@ private class BenchmarkResult

private static readonly PerformanceConfiguration[] _configs = new PerformanceConfiguration[]
{
new PerformanceConfiguration(PerformanceProfiles.MaxPerformance, false, true, true),
new PerformanceConfiguration(PerformanceProfiles.MaxPerformance, false, false, true),
new PerformanceConfiguration(PerformanceProfiles.MaxPerformance, true, true, false),
new PerformanceConfiguration(PerformanceProfiles.Balanced, false, true, true),
new PerformanceConfiguration(PerformanceProfiles.Balanced, false, false, true),
new PerformanceConfiguration(PerformanceProfiles.Balanced, true, true, false)
new PerformanceConfiguration(true, PerformanceProfiles.MaxPerformance, false, true, false),
new PerformanceConfiguration(true, PerformanceProfiles.MaxPerformance, true, true, false),
new PerformanceConfiguration(false, PerformanceProfiles.LowMemory, false, true, false),
new PerformanceConfiguration(false, PerformanceProfiles.LowMemory, true, true, false)
};

private const ushort DEFAULT_THREAD_COUNT = 4;
Expand Down Expand Up @@ -218,24 +217,24 @@ public static void Run(string dataFile, string evidenceFile,
using (var serviceProvider = new ServiceCollection()
// Make sure we're logging to the console.
.AddLogging(l => l.AddConsole())
.AddTransient<DeviceDetectionPipelineBuilder>()
// Add a factory to create the singleton IPipeline instance
.AddSingleton((x) => {
var builder = x.GetRequiredService<DeviceDetectionPipelineBuilder>()
.UseOnPremise(dataFile, null, false)
.AddTransient<PipelineBuilder>()
.AddTransient<DeviceDetectionHashEngineBuilder>()
// Add a factory to create the singleton DeviceDetectionHashEngine instance.
.AddSingleton((x) =>
{
var builder = x.GetRequiredService<DeviceDetectionHashEngineBuilder>()
// Disable any data file updates
.SetDataFileSystemWatcher(false)
.SetAutoUpdate(false)
.SetDataUpdateOnStartUp(false)
// Disable usage sharing for testing
.SetShareUsage(false)
.SetDataUpdateOnStartup(false)
// Set performance profile
.SetPerformanceProfile(config.Profile)
// Configure detection graphs
.SetUsePerformanceGraph(config.PerformanceGraph)
.SetUsePredictiveGraph(config.PredictiveGraph)
// Hint for cache concurrency
.SetConcurrency(threadCount);

// Performance is improved by selecting only the properties you intend to
// use. Requesting properties from a single component reduces detection
// time compared with requesting properties from multiple components.
Expand All @@ -248,7 +247,34 @@ public static void Run(string dataFile, string evidenceFile,
{
builder.SetProperty("IsMobile");
}
return builder.Build();

// The data file can be loaded directly from disk or from a byte array
// in memory.
// This latter option is useful for cloud-based environments with little
// or no hard drive space available. In this scenario, the 'LowMemory'
// performance profile is recommended, as the data is actually already
// in memory. Using MaxPerformance would just cause the native code to
// make another copy of the data in memory for little benefit.
DeviceDetectionHashEngine engine = null;
if (config.LoadFromDisk)
{
engine = builder.Build(dataFile, false);
}
else
{
using (MemoryStream stream = new MemoryStream(File.ReadAllBytes(dataFile)))
{
engine = builder.Build(stream);
}
}

return engine;
})
// Add a factory to create the singleton IPipeline instance
.AddSingleton((x) => {
return x.GetRequiredService<PipelineBuilder>()
.AddFlowElement(x.GetRequiredService<DeviceDetectionHashEngine>())
.Build();
})
.AddTransient<Example>()
.BuildServiceProvider())
Expand All @@ -268,6 +294,7 @@ public static void Run(string dataFile, string evidenceFile,
serviceProvider.GetRequiredService<IPipeline>(),
serviceProvider.GetRequiredService<ILogger<Program>>());
output.WriteLine($"Processing evidence from '{evidenceFile}'");
output.WriteLine($"Data loaded from '{(config.LoadFromDisk ? "disk" : "memory")}'");
output.WriteLine($"Benchmarking with profile '{config.Profile}', " +
$"AllProperties {config.AllProperties}, " +
$"PerformanceGraph {config.PerformanceGraph}, " +
Expand Down
2 changes: 1 addition & 1 deletion FiftyOne.DeviceDetection/device-detection-cxx
Submodule device-detection-cxx updated 35 files
+27 −31 VisualStudio/DeviceDetection.sln
+1 −1 VisualStudio/Examples/C/Hash/ExampleBase/ExampleBase.vcxproj
+1 −1 VisualStudio/Examples/C/Hash/Find Profiles/Find Profiles.vcxproj
+1 −1 VisualStudio/Examples/C/Hash/Getting Started/Getting Started.vcxproj
+1 −1 VisualStudio/Examples/C/Hash/Match For Device Id/Match For Device Id.vcxproj
+1 −1 VisualStudio/Examples/C/Hash/Match Metrics/Match Metrics.vcxproj
+1 −1 VisualStudio/Examples/C/Hash/MemHash/MemHash.vcxproj
+1 −1 VisualStudio/Examples/C/Hash/Offline Processing/Offline Processing.vcxproj
+1 −1 VisualStudio/Examples/C/Hash/PerfHash/PerfHash.vcxproj
+152 −0 VisualStudio/Examples/C/Hash/Performance/Performance.vcxproj
+22 −0 VisualStudio/Examples/C/Hash/Performance/Performance.vcxproj.filters
+1 −1 VisualStudio/Examples/C/Hash/ProcHash/ProcHash.vcxproj
+1 −1 VisualStudio/Examples/C/Hash/Reload From File/Reload From File.vcxproj
+1 −1 VisualStudio/Examples/C/Hash/Reload From Memory/Reload From Memory.vcxproj
+1 −1 VisualStudio/Examples/C/Hash/Strongly Typed/Strongly Typed.vcxproj
+1 −1 VisualStudio/Examples/CPP/Hash/ExampleBase/ExampleBase.vcxproj
+1 −1 VisualStudio/Examples/CPP/Hash/Getting Started/Getting Started.vcxproj
+1 −1 VisualStudio/Examples/CPP/Hash/Match Metrics/Match Metrics.vcxproj
+1 −1 VisualStudio/Examples/CPP/Hash/Meta Data/Meta Data.vcxproj
+1 −1 VisualStudio/Examples/CPP/Hash/Reload From File/Reload From File.vcxproj
+1 −1 VisualStudio/Examples/CPP/Hash/Reload From Memory/Reload From Memory.vcxproj
+1 −1 VisualStudio/Examples/CPP/Hash/Strongly Typed/Strongly Typed.vcxproj
+1 −1 VisualStudio/FiftyOne.DeviceDetection.C/FiftyOne.DeviceDetection.C.vcxproj
+1 −1 VisualStudio/FiftyOne.DeviceDetection.CPP/FiftyOne.DeviceDetection.CPP.vcxproj
+1 −1 VisualStudio/FiftyOne.DeviceDetection.Hash.C/FiftyOne.DeviceDetection.Hash.C.vcxproj
+1 −1 VisualStudio/FiftyOne.DeviceDetection.Hash.Cpp/FiftyOne.DeviceDetection.Hash.Cpp.vcxproj
+2 −5 VisualStudio/FiftyOne.DeviceDetection.Hash.Tests/FiftyOne.DeviceDetection.Hash.Tests.vcxproj
+1 −1 VisualStudio/FiftyOne.DeviceDetection.Hash.Tests/FiftyOne.DeviceDetection.Hash.Tests.vcxproj.filters
+1 −1 ci/common-ci
+54 −3 examples/C/Hash/ExampleBase.c
+20 −0 examples/C/Hash/ExampleBase.h
+0 −537 examples/C/Hash/PerfHash.c
+602 −0 examples/C/Hash/Performance.c
+1 −1 src/common-cxx
+8 −10 test/hash/ExampleHashPerformanceTests.cpp
2 changes: 1 addition & 1 deletion ci/common-ci
Submodule common-ci updated 1 files
+45 −3 release-config.json

0 comments on commit c5f4681

Please sign in to comment.