Skip to content

Commit

Permalink
Enhance the performance of Log API methods
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiamurialdo committed Dec 7, 2023
1 parent a40afa5 commit 026d74a
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 18 deletions.
12 changes: 10 additions & 2 deletions dotnet/DotNetStandardClasses.sln
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GXOtel.Diagnostics", "src\d
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetCoreCmdTest", "test\DotNetCoreCmdTest\DotNetCoreCmdTest.csproj", "{956402BD-AC8C-426E-961B-B77B3F3EDAEB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{46DAAFD1-FAF5-4904-8EC5-406BE04E5538}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LogTest", "test\benchmarks\LogTest\LogTest.csproj", "{A1DBDCE0-4F09-445F-A202-9B260CDD46CF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -627,7 +631,10 @@ Global
{956402BD-AC8C-426E-961B-B77B3F3EDAEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{956402BD-AC8C-426E-961B-B77B3F3EDAEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{956402BD-AC8C-426E-961B-B77B3F3EDAEB}.Release|Any CPU.Build.0 = Release|Any CPU

{A1DBDCE0-4F09-445F-A202-9B260CDD46CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A1DBDCE0-4F09-445F-A202-9B260CDD46CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A1DBDCE0-4F09-445F-A202-9B260CDD46CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A1DBDCE0-4F09-445F-A202-9B260CDD46CF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -751,7 +758,8 @@ Global
{0FCFB078-5584-469F-92CC-61B0A6216D0D} = {1D6F1776-FF4B-46C2-9B3D-BC46CCF049DC}
{A42066E8-DDB9-4767-AEFA-E6D13EFF051A} = {BBE020D4-C0FF-41A9-9EB1-D1EE12CC4BB8}
{956402BD-AC8C-426E-961B-B77B3F3EDAEB} = {1D6F1776-FF4B-46C2-9B3D-BC46CCF049DC}

{46DAAFD1-FAF5-4904-8EC5-406BE04E5538} = {1D6F1776-FF4B-46C2-9B3D-BC46CCF049DC}
{A1DBDCE0-4F09-445F-A202-9B260CDD46CF} = {46DAAFD1-FAF5-4904-8EC5-406BE04E5538}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E18684C9-7D76-45CD-BF24-E3944B7F174C}
Expand Down
24 changes: 8 additions & 16 deletions dotnet/src/dotnetframework/GxClasses/Diagnostics/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,21 @@ private enum LogLevel
Error = 20,
Fatal = 30
}
#if NETCORE
static ILoggerFactory _instance = GXLogService.GetLogFactory();
#endif
private static readonly string DefaultRepository = LogManager.GetRepository().Name;
private static readonly string DefaultUserLogNamespace = Config.GetValueOf("USER_LOG_NAMESPACE", LogConfiguration.USER_LOG_TOPIC);
private static readonly IGXLogger GlobalLog = new GXLoggerLog4Net(LogManager.GetLogger(DefaultRepository, DefaultUserLogNamespace));

internal static IGXLogger GetLogger(string topic)
{
string defaultUserLogNamespace = Configuration.Config.GetValueOf("USER_LOG_NAMESPACE", LogConfiguration.USER_LOG_TOPIC);
string loggerName = defaultUserLogNamespace;
if (!string.IsNullOrEmpty(topic))
{
loggerName = topic.StartsWith("$") ? topic.Substring(1) : string.Format("{0}.{1}", defaultUserLogNamespace, topic.Trim());
string loggerName = topic.StartsWith("$") ? topic.Substring(1) : string.Format("{0}.{1}", DefaultUserLogNamespace, topic.Trim());
return GXLoggerFactory.GetLogger(loggerName);
}
#if NETCORE
if (_instance != null)
else
{
return new GXLoggerMsExtensions(_instance.CreateLogger(loggerName));
return GlobalLog;
}
string defaultRepository = LogManager.GetRepository(System.Reflection.Assembly.GetEntryAssembly()).Name;
#else
string defaultRepository = LogManager.GetRepository().Name;
#endif
return new GXLoggerLog4Net(log4net.LogManager.GetLogger(defaultRepository, loggerName));

}

public static void Write(int logLevel, string message, string topic)
Expand Down
48 changes: 48 additions & 0 deletions dotnet/test/benchmarks/LogTest/LogTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
using GeneXus.Diagnostics;
using Xunit;
namespace BenchmarkTest
{
public class LoggerBenchmark
{
[Params(1000)]
public int N;
const int Debug = 5;

[Benchmark]
public void Write_PerformanceTest()
{
for (int i = 0; i < N; i++)
{
Log.Write("Test Message", "Test Topi", Debug);
}
}
}

public class PerformanceTests
{
const double MAX_NANOSECONDS = 150000;
[Fact]
public void RunLoggerBenchmark()
{
#if DEBUG
var config = DefaultConfig.Instance.WithOptions(ConfigOptions.DisableOptimizationsValidator);
Summary summary = BenchmarkRunner.Run<LoggerBenchmark>(config);
#else
Summary summary = BenchmarkRunner.Run<LoggerBenchmark>();
#endif
Assert.NotEmpty(summary.Reports);
foreach (BenchmarkReport report in summary.Reports)
{
Assert.NotEmpty(report.AllMeasurements);
foreach (Measurement runMeasure in report.AllMeasurements)
{
Assert.InRange(runMeasure.Nanoseconds, low: 0, high: MAX_NANOSECONDS);
}
}
}
}
}
36 changes: 36 additions & 0 deletions dotnet/test/benchmarks/LogTest/LogTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net462</TargetFrameworks>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.11" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\dotnetcore\GxClasses\GxClasses.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="log.console.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
64 changes: 64 additions & 0 deletions dotnet/test/benchmarks/LogTest/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"appSettings": {
"AppMainNamespace": "GeneXus.Programs",
"DataStore1": "Default",
"DataStore-Count": "1",
"DataStore-Default": "Default",
"Connection-Default-DBMS": "sqlserver",
"Connection-Default-Port": "",
"Connection-Default-LockTimeout": "0",
"Connection-Default-LockRetryCount": "10",
"Connection-Default-IsolationLevel": "CR",
"Connection-Default-Datasource": "",
"Connection-Default-User": "",
"Connection-Default-Password": "",
"Connection-Default-DB": "",
"Connection-Default-Schema": "",
"Connection-Default-Opts": "",
"Connection-Default-TrnInt": "1",
"DateFormat": "MDY",
"YearLimit": "1940",
"TimeAmPmFormat": "12",
"VER_STAMP": "20210602.093942",
"CS_BLOB_PATH": "PublicTempStorage",
"TMPMEDIA_DIR": "PrivateTempStorage",
"PRINT_LAYOUT_METADATA_DIR": "LayoutMetadata",
"StorageTimeZone": "1",
"LOGIN_AS_USERID": "0",
"LANGUAGE": "eng",
"LANG_NAME": "English",
"DECIMAL_POINT": ".",
"DATE_FMT": "MDY",
"CTOD_DATE_FMT": "L",
"Culture": "en-US",
"Theme": "Carmine",
"UseNamedParameters": "1",
"EnableIntegratedSecurity": "0",
"MAX_CURSOR": "100",
"STATIC_CONTENT": "",
"GX_BUILD_NUMBER": "11103481",
"CACHE_CONTENT_EXPIRATION": "36",
"ENABLE_MANAGEMENT": "0",
"COMPRESS_HTML": "1",
"IE_COMPATIBILITY_VIEW": "EmulateIE7",
"DocumentType": "HTML5",
"EXPOSE_METADATA": "0",
"SMART_CACHING": "0",
"wcf:serviceHostingEnvironment:useClassicReadEntityBodyMode": "true",
"HTTP_PROTOCOL": "Unsecure",
"SAMESITE_COOKIE": "Lax",
"CACHE_INVALIDATION_TOKEN": "20216211291931",
"CORS_ALLOW_ORIGIN": "https://normal-website.com",
"MY_CUSTOM_PTY": "DEFAULT_VALUE"
},
"languages": {
"English": {
"code": "eng",
"culture": "en-US",
"date_fmt": "MDY",
"decimal_point": ".",
"thousand_sep": ",",
"time_fmt": "12"
}
}
}
37 changes: 37 additions & 0 deletions dotnet/test/benchmarks/LogTest/log.console.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d{ISO8601} [%t] %-5p %c - %m%n"/>
</layout>
</appender>

<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="client.log"/>
<appendToFile value="true"/>
<maximumFileSize value="9000KB"/>
<maxSizeRollBackups value="4"/>
<rollingStyle value="Size"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d{ISO8601} [%t] %-5p %c - %m%n"/>
</layout>
<lockingModel type="log4net.Appender.FileAppender+ExclusiveLock"/>
</appender>

<root>
<level value="DEBUG"/>
<appender-ref ref="RollingFile"/>
</root>
<!-- GeneXus Standard Classes Logging !-->
<!-- <logger name="GeneXus" additivity="false">
<level value="ALL" />
<appender-ref ref="RollingFile"/>
</logger> !-->

<!-- User custom Logging !-->
<logger name="GeneXusUserLog" additivity="false">
<level value="ERROR" />
<appender-ref ref="RollingFile"/>
</logger>


</log4net>

0 comments on commit 026d74a

Please sign in to comment.