Skip to content

Commit

Permalink
CPU resource usage changes
Browse files Browse the repository at this point in the history
  • Loading branch information
moberacker committed Jul 28, 2017
1 parent 68e82c1 commit d28579e
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 18 deletions.
10 changes: 10 additions & 0 deletions Log4ALA/ConfigSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class ConfigSettings
private const string ALA_CORE_FIELD_NAMES_PROP = "coreFieldNames";
private const string ALA_MAX_FIELD_NAME_LENGTH_PROP = "maxFieldNameLength";
private const string ALA_THREAD_PRIORITY_PROP = "threadPriority";
private const string ALA_QUEUE_READ_TIMEOUT_PROP = "queueReadTimeout";


public const int DEFAULT_HTTP_DATA_COLLECTOR_RETRY = 6;
Expand All @@ -46,6 +47,7 @@ public class ConfigSettings
public const bool DEFAULT_JSON_DETECTION = true;
public const int DEFAULT_MAX_FIELD_BYTE_LENGTH = 32000;
public const int DEFAULT_MAX_FIELD_NAME_LENGTH = 500;
public const int DEFAULT_QUEUE_READ_TIMEOUT = 500;

public const string DEFAULT_DATE_FIELD_NAME = "DateValue";
public const string DEFAULT_MISC_MSG_FIELD_NAME = "MiscMsg";
Expand Down Expand Up @@ -282,6 +284,14 @@ public string ALAThreadPriority
return CloudConfigurationManager.GetSetting($"{this.propPrefix}.{ALA_THREAD_PRIORITY_PROP}");
}
}
public int? ALAQueueReadTimeout
{
get
{
string aLAQueueReadTimeout = CloudConfigurationManager.GetSetting($"{this.propPrefix}.{ALA_QUEUE_READ_TIMEOUT_PROP}");
return (string.IsNullOrWhiteSpace(aLAQueueReadTimeout) ? (int?)null : int.Parse(aLAQueueReadTimeout));
}
}

}
}
2 changes: 1 addition & 1 deletion Log4ALA/Log4ALA.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Log4Net appender for Azure Log Analytics (ALA)... sending data to Azure Log Analytics with the HTTP Data Collector API. The data will also be logged/sent asynchronously for high performance and to avoid blocking the caller thread.</description>
<copyright>Copyright © 2017 PTV Group</copyright>
<releaseNotes>Fix of unusable version 2.0.2.</releaseNotes>
<releaseNotes>CPU resource usage changes.</releaseNotes>
<dependencies>
<dependency id="log4net" version="2.0.5" />
<dependency id="Microsoft.WindowsAzure.ConfigurationManager" version="3.1.0" />
Expand Down
5 changes: 5 additions & 0 deletions Log4ALA/Log4ALAAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public string CoreFieldNames {
}

public string ThreadPriority { get; set; } = ConfigSettings.DEFAULT_THREAD_PRIORITY;
public int? QueueReadTimeout { get; set; } = ConfigSettings.DEFAULT_QUEUE_READ_TIMEOUT;




Expand Down Expand Up @@ -215,6 +217,9 @@ public override void ActivateOptions()
BatchNumItems = 0;
}

QueueReadTimeout = configSettings.ALAQueueReadTimeout == null ? QueueReadTimeout : configSettings.ALAQueueReadTimeout;
log.Inf($"[{this.Name}] - queueReadTimeout:[{QueueReadTimeout}]", true);

log.Inf($"[{this.Name}] - batchNumItems:[{BatchNumItems}]", true);

serializer = new LoggingEventSerializer();
Expand Down
4 changes: 2 additions & 2 deletions Log4ALA/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.3")]
[assembly: AssemblyFileVersion("2.0.3")]
[assembly: AssemblyVersion("2.0.4")]
[assembly: AssemblyFileVersion("2.0.4")]
22 changes: 10 additions & 12 deletions Log4ALA/QueueLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class QueueLogger
{
// Error message displayed when queue overflow occurs.
protected const String QueueOverflowMessage = "\n\nAzure Log Analytics buffer queue overflow. Message dropped.\n\n";

public const int BatchSizeMax = 31457280; //30 mb quota limit per post

protected readonly BlockingCollection<string> Queue;
Expand Down Expand Up @@ -84,6 +83,8 @@ protected virtual void Run()
{
OpenConnection();

int qReadTimeout = (int)appender.QueueReadTimeout;

// Send data in queue.
while (true)
{
Expand All @@ -104,18 +105,15 @@ protected virtual void Run()
{
try
{
if (Queue.Count > 0)

if (Queue.TryTake(out line, qReadTimeout))
{
line = Queue.Take();
if (!string.IsNullOrWhiteSpace(line))
{
byteLength += System.Text.Encoding.Unicode.GetByteCount(line);

buffer.Append(line);
buffer.Append(",");
++numItems;
line = string.Empty;
}
byteLength += System.Text.Encoding.Unicode.GetByteCount(line);

buffer.Append(line);
buffer.Append(",");
++numItems;
line = string.Empty;
}
}
catch (Exception ee)
Expand Down
4 changes: 2 additions & 2 deletions Log4ALATest/Log4ALATest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Log4ALA, Version=2.0.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Log4ALA.2.0.3\lib\net452\Log4ALA.dll</HintPath>
<Reference Include="Log4ALA, Version=2.0.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Log4ALA.2.0.4\lib\net452\Log4ALA.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=1.2.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.5\lib\net45-full\log4net.dll</HintPath>
Expand Down
4 changes: 4 additions & 0 deletions Log4ALATest/log4net.config
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
possible values Lowest/BelowNormal/Normal/AboveNormal/Highest (default Lowest)
<threadPriority value="Lowest"/>
-->

<!-- queue read timeout in milliseconds to decrease cpu usage (default 500)
<queueReadTimeout value="500"/>
-->
</appender>


Expand Down
2 changes: 1 addition & 1 deletion Log4ALATest/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Log4ALA" version="2.0.3" targetFramework="net452" />
<package id="Log4ALA" version="2.0.4" targetFramework="net452" />
<package id="log4net" version="2.0.5" targetFramework="net452" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.1.0" targetFramework="net452" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
Expand Down

0 comments on commit d28579e

Please sign in to comment.