-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
增加了Fantasy.Benchmark基准测试功能。具体请看Fantasy.Benchmark/README.md
- Loading branch information
Showing
303 changed files
with
488 additions
and
71 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
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,2 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AKCPClientNetwork_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F345510aa2adc4dc692470d34421b7bf380400_003F47_003F946135ef_003FKCPClientNetwork_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary> |
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,138 @@ | ||
|
||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member | ||
|
||
namespace Fantasy | ||
{ | ||
/// <summary> | ||
/// 标准的控制台Log | ||
/// </summary> | ||
public sealed class ConsoleLog : ILog | ||
{ | ||
|
||
/// <summary> | ||
/// 记录跟踪级别的日志消息。 | ||
/// </summary> | ||
/// <param name="message">日志消息。</param> | ||
public void Trace(string message) | ||
{ | ||
System.Console.ForegroundColor = ConsoleColor.White; | ||
System.Console.WriteLine(message); | ||
} | ||
|
||
/// <summary> | ||
/// 记录警告级别的日志消息。 | ||
/// </summary> | ||
/// <param name="message">日志消息。</param> | ||
public void Warning(string message) | ||
{ | ||
System.Console.ForegroundColor = ConsoleColor.Yellow; | ||
System.Console.WriteLine(message); | ||
} | ||
|
||
/// <summary> | ||
/// 记录信息级别的日志消息。 | ||
/// </summary> | ||
/// <param name="message">日志消息。</param> | ||
public void Info(string message) | ||
{ | ||
System.Console.ForegroundColor = ConsoleColor.Gray; | ||
System.Console.WriteLine(message); | ||
} | ||
|
||
/// <summary> | ||
/// 记录调试级别的日志消息。 | ||
/// </summary> | ||
/// <param name="message">日志消息。</param> | ||
public void Debug(string message) | ||
{ | ||
System.Console.ForegroundColor = ConsoleColor.DarkGreen; | ||
System.Console.WriteLine(message); | ||
} | ||
|
||
/// <summary> | ||
/// 记录错误级别的日志消息。 | ||
/// </summary> | ||
/// <param name="message">日志消息。</param> | ||
public void Error(string message) | ||
{ | ||
System.Console.ForegroundColor = ConsoleColor.DarkRed; | ||
System.Console.WriteLine(message); | ||
} | ||
|
||
/// <summary> | ||
/// 记录严重错误级别的日志消息。 | ||
/// </summary> | ||
/// <param name="message">日志消息。</param> | ||
public void Fatal(string message) | ||
{ | ||
System.Console.ForegroundColor = ConsoleColor.Red; | ||
System.Console.WriteLine(message); | ||
} | ||
|
||
/// <summary> | ||
/// 记录跟踪级别的格式化日志消息。 | ||
/// </summary> | ||
/// <param name="message">日志消息模板。</param> | ||
/// <param name="args">格式化参数。</param> | ||
public void Trace(string message, params object[] args) | ||
{ | ||
System.Console.ForegroundColor = ConsoleColor.White; | ||
System.Console.WriteLine(message, args); | ||
} | ||
|
||
/// <summary> | ||
/// 记录警告级别的格式化日志消息。 | ||
/// </summary> | ||
/// <param name="message">日志消息模板。</param> | ||
/// <param name="args">格式化参数。</param> | ||
public void Warning(string message, params object[] args) | ||
{ | ||
System.Console.ForegroundColor = ConsoleColor.Yellow; | ||
System.Console.WriteLine(message, args); | ||
} | ||
|
||
/// <summary> | ||
/// 记录信息级别的格式化日志消息。 | ||
/// </summary> | ||
/// <param name="message">日志消息模板。</param> | ||
/// <param name="args">格式化参数。</param> | ||
public void Info(string message, params object[] args) | ||
{ | ||
System.Console.ForegroundColor = ConsoleColor.Gray; | ||
System.Console.WriteLine(message, args); | ||
} | ||
|
||
/// <summary> | ||
/// 记录调试级别的格式化日志消息。 | ||
/// </summary> | ||
/// <param name="message">日志消息模板。</param> | ||
/// <param name="args">格式化参数。</param> | ||
public void Debug(string message, params object[] args) | ||
{ | ||
System.Console.ForegroundColor = ConsoleColor.DarkGreen; | ||
System.Console.WriteLine(message, args); | ||
} | ||
|
||
/// <summary> | ||
/// 记录错误级别的格式化日志消息。 | ||
/// </summary> | ||
/// <param name="message">日志消息模板。</param> | ||
/// <param name="args">格式化参数。</param> | ||
public void Error(string message, params object[] args) | ||
{ | ||
System.Console.ForegroundColor = ConsoleColor.DarkRed; | ||
System.Console.WriteLine(message, args); | ||
} | ||
|
||
/// <summary> | ||
/// 记录严重错误级别的格式化日志消息。 | ||
/// </summary> | ||
/// <param name="message">日志消息模板。</param> | ||
/// <param name="args">格式化参数。</param> | ||
public void Fatal(string message, params object[] args) | ||
{ | ||
System.Console.ForegroundColor = ConsoleColor.Red; | ||
System.Console.WriteLine(message, args); | ||
} | ||
} | ||
} |
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,32 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> | ||
<DefineConstants>TRACE;FANTASY_CONSOLE</DefineConstants> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> | ||
<DefineConstants>TRACE;FANTASY_CONSOLE</DefineConstants> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" /> | ||
<PackageReference Include="MongoDB.Bson" Version="2.29.0" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> | ||
<PackageReference Include="protobuf-net" Version="3.2.30" /> | ||
<PackageReference Include="System.IO.Pipelines" Version="8.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Fantays.Console\Fantasy.Console.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,45 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Jobs; | ||
using BenchmarkDotNet.Running; | ||
using Fantasy.Async; | ||
using Fantasy.InnerMessage; | ||
using Fantasy.Network; | ||
using Fantasy.Platform.Console; | ||
|
||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. | ||
|
||
namespace Fantasy.Benchmark; | ||
[SimpleJob(RuntimeMoniker.Net80, baseline: true)] | ||
public class NetworkBenchmark | ||
{ | ||
private static Scene _scene; | ||
private static Session _session; | ||
private readonly BenchmarkRequest _benchmarkRequest = new BenchmarkRequest(); | ||
|
||
public static async FTask Initialize() | ||
{ | ||
// 注册日志实例到框架中 | ||
Log.Register(new ConsoleLog()); | ||
// 初始化框架 | ||
Entry.Initialize(); | ||
// 执行StartUpdate方法 | ||
Entry.StartUpdate(); | ||
_scene = await Entry.CreateScene(); | ||
// 创建远程连接 | ||
_session = _scene.Connect("127.0.0.1:20000", NetworkProtocolType.KCP, | ||
() => | ||
{ | ||
Log.Debug("连接到目标服务器成功"); | ||
var summary = BenchmarkRunner.Run<NetworkBenchmark>(); | ||
Console.WriteLine(summary); | ||
}, | ||
() => { Log.Debug("无法连接到目标服务器"); }, | ||
() => { Log.Debug("与服务器断开连接"); }, false); | ||
} | ||
|
||
[Benchmark] | ||
public async FTask Call() | ||
{ | ||
await _session.Call(_benchmarkRequest); | ||
} | ||
} |
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,2 @@ | ||
Fantasy.Benchmark.NetworkBenchmark.Initialize().Coroutine(); | ||
Console.ReadKey(); |
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,6 @@ | ||
# Fantasy.Benchmark | ||
使用 Fantasy.Benchmark 工具,我们能够快速评估框架网络的处理性能。目前,该工具提供的基准测试主要集中在 RPC(远程过程调用)消息 方面。这一项测试能够有效测量系统在处理远程调用时的响应时间、吞吐量和资源利用率,帮助开发者优化网络通信性能,确保在高负载情况下系统依然能够稳定运行 | ||
## 操作步骤 | ||
- 1.打开位于 Examples/Server/Server.sln 的解决方案文件。 | ||
- 2.在解决方案中选择并启动 Main 项目。 | ||
- 3.接着,启动 Fantasy.Benchmark 应用程序,并耐心等待其测试结果的生成。 |
25 changes: 25 additions & 0 deletions
25
Fantasy.Net/Fantasy.Net/Runtime/Core/Benchmark/Handler/BenchmarkRequestHandler.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,25 @@ | ||
using Fantasy.Async; | ||
using Fantasy.InnerMessage; | ||
using Fantasy.Network.Interface; | ||
|
||
#if FANTASY_NET | ||
namespace Fantasy.Network.Benchmark.Handler; | ||
|
||
/// <summary> | ||
/// BenchmarkRequestHandler | ||
/// </summary> | ||
public sealed class BenchmarkRequestHandler : MessageRPC<BenchmarkRequest, BenchmarkResponse> | ||
{ | ||
/// <summary> | ||
/// Run方法 | ||
/// </summary> | ||
/// <param name="session"></param> | ||
/// <param name="request"></param> | ||
/// <param name="response"></param> | ||
/// <param name="reply"></param> | ||
protected override async FTask Run(Session session, BenchmarkRequest request, BenchmarkResponse response, Action reply) | ||
{ | ||
await FTask.CompletedTask; | ||
} | ||
} | ||
#endif |
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 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 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
Fantasy.Unity/Fantasy.Unity/Runtime/Core/Benchmark/Handler.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.