饭太稀
This commit is contained in:
138
Fantasy/Fantasy.Benchmark/ConsoleLog.cs
Normal file
138
Fantasy/Fantasy.Benchmark/ConsoleLog.cs
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
33
Fantasy/Fantasy.Benchmark/Fantasy.Benchmark.csproj
Normal file
33
Fantasy/Fantasy.Benchmark/Fantasy.Benchmark.csproj
Normal file
@@ -0,0 +1,33 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
|
||||
<LangVersion>default</LangVersion>
|
||||
</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>
|
||||
45
Fantasy/Fantasy.Benchmark/NetworkBenchmark.cs
Normal file
45
Fantasy/Fantasy.Benchmark/NetworkBenchmark.cs
Normal file
@@ -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());
|
||||
// 初始化框架
|
||||
await Entry.Initialize();
|
||||
// 执行StartUpdate方法
|
||||
Entry.StartUpdate();
|
||||
_scene = await Entry.CreateScene();
|
||||
// 创建远程连接
|
||||
_session = _scene.Connect("127.0.0.1:20000", NetworkProtocolType.WebSocket,
|
||||
() =>
|
||||
{
|
||||
Log.Debug("连接到目标服务器成功");
|
||||
var summary = BenchmarkRunner.Run<NetworkBenchmark>();
|
||||
Console.WriteLine(summary);
|
||||
},
|
||||
() => { Log.Debug("无法连接到目标服务器"); },
|
||||
() => { Log.Debug("与服务器断开连接"); }, false);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public async FTask Call()
|
||||
{
|
||||
await _session.Call(_benchmarkRequest);
|
||||
}
|
||||
}
|
||||
2
Fantasy/Fantasy.Benchmark/Program.cs
Normal file
2
Fantasy/Fantasy.Benchmark/Program.cs
Normal file
@@ -0,0 +1,2 @@
|
||||
Fantasy.Benchmark.NetworkBenchmark.Initialize().Coroutine();
|
||||
Console.ReadKey();
|
||||
6
Fantasy/Fantasy.Benchmark/README.md
Normal file
6
Fantasy/Fantasy.Benchmark/README.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# Fantasy.Benchmark
|
||||
使用 Fantasy.Benchmark 工具,我们能够快速评估框架网络的处理性能。目前,该工具提供的基准测试主要集中在 RPC(远程过程调用)消息 方面。这一项测试能够有效测量系统在处理远程调用时的响应时间、吞吐量和资源利用率,帮助开发者优化网络通信性能,确保在高负载情况下系统依然能够稳定运行
|
||||
## 操作步骤
|
||||
- 1.打开位于 Examples/Server/Server.sln 的解决方案文件。
|
||||
- 2.在解决方案中选择并启动 Main 项目。
|
||||
- 3.接着,启动 Fantasy.Benchmark 应用程序,并耐心等待其测试结果的生成。
|
||||
Reference in New Issue
Block a user