-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
130 changed files
with
12,185 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
############################################################################### | ||
# Set default behavior to automatically normalize encoding and line endings. | ||
############################################################################### | ||
* text encoding=UTF-8 eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
Aliyun.Api.LogService.Benchmark/Aliyun.Api.LogService.Benchmark.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Aliyun.Api.LogService\Aliyun.Api.LogService.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.10.14" /> | ||
</ItemGroup> | ||
</Project> |
170 changes: 170 additions & 0 deletions
170
Aliyun.Api.LogService.Benchmark/DefaultLogServiceClientBenchmark.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
// | ||
// DefaultLogServiceClientBenchmark.cs | ||
// | ||
// Author: | ||
// MiNG <[email protected]> | ||
// | ||
// Copyright (c) 2018 Alibaba Cloud | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Aliyun.Api.LogService.Domain.Log; | ||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace Aliyun.Api.LogService.Benchmark | ||
{ | ||
public class DefaultLogServiceClientBenchmark | ||
{ | ||
private const Int32 LogContentSize = 10; | ||
|
||
private ILogServiceClient client; | ||
|
||
private String logstoreName; | ||
|
||
private String cursor; | ||
|
||
private LogGroupInfo logGroup; | ||
|
||
[Params(5, 500)] | ||
public Int32 SizeK { get; set; } | ||
|
||
[GlobalSetup] | ||
public void Prepare() | ||
{ | ||
this.client = LogServiceClientBuilders.HttpBuilder | ||
.Endpoint("cn-shenzhen.log.aliyuncs.com", "dotnet-sdk-sz") | ||
.Credential("<secret>", "<secret>") | ||
.Build(); | ||
|
||
var timestamp = DateTimeOffset.Now.ToUnixTimeSeconds(); | ||
this.logstoreName = $"logstore-dotnet-sdk-test-{timestamp}"; | ||
|
||
// Create logstore for benchmark | ||
this.client.CreateLogStoreAsync(this.logstoreName, 1, 1).Result.EnsureSuccess(); | ||
Console.WriteLine($"// LogStore {this.logstoreName} created."); | ||
|
||
// Wait logstore prepared | ||
this.WaitLogStorePrepared().Wait(); | ||
|
||
// Prepare data | ||
var logLines = this.SizeK * 1024 / (10 * LogContentSize) + 1; | ||
this.logGroup = new LogGroupInfo | ||
{ | ||
Topic = "PressureTest", | ||
Source = "PressureTest", | ||
LogTags = | ||
{ | ||
{"Tag1", "Value1"}, | ||
{"Tag2", "Value2"} | ||
}, | ||
Logs = Enumerable.Repeat(new LogInfo | ||
{ | ||
Time = DateTimeOffset.Now, | ||
Contents = Enumerable.Range(0, LogContentSize) | ||
.Select(i => (key: $"key{i}", value: $"value{i}")) | ||
.ToDictionary(kv => kv.key, kv => kv.value) | ||
}, logLines).ToList() | ||
}; | ||
Console.WriteLine($"// Data ready, assume size: {10 * LogContentSize * logLines / 1024}KB per request."); | ||
} | ||
|
||
private async Task WaitLogStorePrepared() | ||
{ | ||
var successCount = 0; | ||
|
||
while (true) | ||
{ | ||
var result = await this.client.GetCursorAsync(this.logstoreName, 0, "begin"); | ||
if (result.IsSuccess) | ||
{ | ||
Console.WriteLine( | ||
$"// {DateTime.Now} [{successCount}] - LogStore created verify ok, cursor was read, shardId=0, cursor={result.Result.Cursor}."); | ||
// Require cotinued success 10 times. | ||
if (++successCount >= 10) | ||
{ | ||
Console.WriteLine($"// {DateTime.Now} - LogStore created verify pass, assumes LogStore has been prepared."); | ||
this.cursor = result.Result.Cursor; | ||
return; | ||
} | ||
} else | ||
{ | ||
Console.WriteLine($"// {DateTime.Now} [{successCount}] - LogStore created verify failed, reset success count."); | ||
successCount = 0; | ||
} | ||
|
||
await Task.Delay(TimeSpan.FromSeconds(1)); | ||
} | ||
} | ||
|
||
[GlobalCleanup] | ||
public void CleanUp() | ||
{ | ||
var response = this.client.DeleteLogStoreAsync(this.logstoreName).Result; | ||
Console.WriteLine($"// CleanUp: {(response.IsSuccess ? "ok" : "failed")}"); | ||
} | ||
|
||
[Benchmark(Baseline = true)] | ||
public async Task PostLogStoreLogs_Base() | ||
{ | ||
await this.client.PostLogStoreLogsAsync(this.logstoreName, this.logGroup); | ||
} | ||
|
||
[BenchmarkCategory("PostLogStoreLogs")] | ||
[Benchmark(OperationsPerInvoke = 10)] | ||
public async Task PostLogStoreLogs_10Parallel() | ||
{ | ||
await Task.WhenAll(Enumerable.Range(0, 10) | ||
.Select(async i => | ||
await this.client.PostLogStoreLogsAsync(this.logstoreName, this.logGroup))); | ||
} | ||
|
||
// [BenchmarkCategory("PostLogStoreLogs")] | ||
// [Benchmark(OperationsPerInvoke = 100)] | ||
// public async Task PostLogStoreLogs_100Parallel() | ||
// { | ||
// await Task.WhenAll(Enumerable.Range(0, 100) | ||
// .Select(async i => | ||
// await this.client.PostLogStoreLogsAsync(this.logstoreName, this.logGroup))); | ||
// } | ||
|
||
// [BenchmarkCategory("PullLogs")] | ||
// [Benchmark(Baseline = true)] | ||
// public async Task PullLogs_Base() | ||
// { | ||
// await this.client.PullLogsAsync(this.logstoreName, 0, this.cursor, 10); | ||
// } | ||
// | ||
// [BenchmarkCategory("PullLogs")] | ||
// [Benchmark] | ||
// public async Task PullLogs_100Lines() | ||
// { | ||
// await this.client.PullLogsAsync(this.logstoreName, 0, this.cursor, 100); | ||
// } | ||
// | ||
// [BenchmarkCategory("PullLogs")] | ||
// [Benchmark] | ||
// public async Task PullLogs_1000Lines() | ||
// { | ||
// await this.client.PullLogsAsync(this.logstoreName, 0, this.cursor, 1000); | ||
// } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// Program.cs | ||
// | ||
// Author: | ||
// MiNG <[email protected]> | ||
// | ||
// Copyright (c) 2018 Alibaba Cloud | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
using System; | ||
using BenchmarkDotNet.Running; | ||
|
||
namespace Aliyun.Api.LogService.Benchmark | ||
{ | ||
public static class Program | ||
{ | ||
public static void Main(String[] args) | ||
{ | ||
BenchmarkRunner.Run<DefaultLogServiceClientBenchmark>(); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Aliyun.Api.LogService.Examples/Aliyun.Api.LogService.Examples.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
<LangVersion>7.1</LangVersion> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Aliyun.Api.LogService\Aliyun.Api.LogService.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Autofac" Version="4.7.0" /> | ||
<PackageReference Include="Ninject" Version="3.3.4" /> | ||
</ItemGroup> | ||
</Project> |
92 changes: 92 additions & 0 deletions
92
Aliyun.Api.LogService.Examples/ApiUsage/PostLogStoreLogsExample.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// | ||
// PostLogStoreLogsExample.cs | ||
// | ||
// Author: | ||
// MiNG <[email protected]> | ||
// | ||
// Copyright (c) 2018 Alibaba Cloud | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Aliyun.Api.LogService.Domain.Log; | ||
|
||
namespace Aliyun.Api.LogService.Examples.ApiUsage | ||
{ | ||
public static class PostLogStoreLogsExample | ||
{ | ||
private static readonly String LogStoreName = "example-logstore"; | ||
|
||
public static async Task PostLogStoreLogs(ILogServiceClient client) | ||
{ | ||
// 原始日志 | ||
var rawLogs = new[] | ||
{ | ||
"2018-05-04 12:34:56 INFO id=1 status=foo", | ||
"2018-05-04 12:34:57 INFO id=2 status=bar", | ||
"2018-05-04 12:34:58 INFO id=1 status=foo", | ||
"2018-05-04 12:34:59 WARN id=1 status=foo", | ||
}; | ||
|
||
// 解释 LogInfo | ||
var parsedLogs = rawLogs | ||
.Select(x => | ||
{ | ||
var components = x.Split(' '); | ||
|
||
var date = components[0]; | ||
var time = components[1]; | ||
var level = components[2]; | ||
var id = components[3].Split('='); | ||
var status = components[4].Split('='); | ||
|
||
var logInfo = new LogInfo | ||
{ | ||
Contents = | ||
{ | ||
{"level", level}, | ||
{id[0], id[1]}, | ||
{status[0], status[1]}, | ||
}, | ||
Time = DateTimeOffset.ParseExact($"{date} {time}", "yyyy-MM-dd HH:mm:ss", null) | ||
}; | ||
|
||
return logInfo; | ||
}) | ||
.ToList(); | ||
|
||
var logGroupInfo = new LogGroupInfo | ||
{ | ||
Topic = "example", | ||
LogTags = | ||
{ | ||
{"example", "true"}, | ||
}, | ||
Logs = parsedLogs | ||
}; | ||
|
||
var response = await client.PostLogStoreLogsAsync(LogStoreName, logGroupInfo); | ||
|
||
// 此接口没有返回结果,确保返回结果成功即可。 | ||
response.EnsureSuccess(); | ||
} | ||
} | ||
} |
Oops, something went wrong.