Skip to content
This repository was archived by the owner on Jan 9, 2021. It is now read-only.

Commit ca66ddc

Browse files
committed
测试例程跑起来
1 parent dedd9e9 commit ca66ddc

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,4 @@ __pycache__/
261261
*.pyc
262262
/BinEcho
263263
/BinNC
264+
/BinAgent

Benchmark/Config.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ class Config
88
#region 属性
99
public String Address { get; set; }
1010

11-
public Int32 Times { get; set; }
11+
public Int32 Times { get; set; } = 10000;
1212

13-
public Int32 Thread { get; set; }
13+
public Int32 Thread { get; set; } = 100;
1414

1515
public String Content { get; set; }
1616
#endregion

Benchmark/Program.cs

+29-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
using System.Linq;
44
using System.Reflection;
55
using System.Text;
6+
using System.Threading;
67
using System.Threading.Tasks;
8+
using NewLife.Data;
79
using NewLife.Log;
810
using NewLife.Net;
911
using NewLife.Reflection;
@@ -54,6 +56,7 @@ static void Work(Config cfg)
5456
{
5557
var uri = new NetUri(cfg.Address);
5658
if (cfg.Content.IsNullOrEmpty()) cfg.Content = "学无先后达者为师";
59+
var pk = new Packet(cfg.Content.GetBytes());
5760

5861
Console.ForegroundColor = ConsoleColor.Red;
5962
Console.WriteLine("NewLife.NC v{0}", AssemblyX.Entry.Version);
@@ -62,9 +65,33 @@ static void Work(Config cfg)
6265
Console.WriteLine("目标:{0}", uri);
6366
Console.WriteLine("请求:{0:n0}", cfg.Times);
6467
Console.WriteLine("并发:{0:n0}", cfg.Thread);
65-
var buf = cfg.Content.GetBytes();
66-
Console.WriteLine("并发:[{0:n0}] {1}", buf.Length, cfg.Content);
68+
Console.WriteLine("并发:[{0:n0}] {1}", pk.Count, cfg.Content);
6769
Console.ResetColor();
70+
Console.WriteLine();
71+
72+
// 多线程
73+
var ts = new List<Task>();
74+
var total = 0;
75+
for (var i = 0; i < cfg.Thread; i++)
76+
{
77+
var tsk = Task.Run(() =>
78+
{
79+
try
80+
{
81+
var client = uri.CreateRemote();
82+
client.Open();
83+
for (var k = 0; k < cfg.Times; k++)
84+
{
85+
client.Send(pk);
86+
Interlocked.Increment(ref total);
87+
}
88+
}
89+
catch { }
90+
});
91+
ts.Add(tsk);
92+
}
93+
Task.WaitAll(ts.ToArray());
94+
Console.WriteLine("完成:{0:n0}", total);
6895
}
6996
}
7097
}

EchoAgent/EchoAgent.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<DebugSymbols>true</DebugSymbols>
1818
<DebugType>full</DebugType>
1919
<Optimize>false</Optimize>
20-
<OutputPath>bin\Debug\</OutputPath>
20+
<OutputPath>..\BinAgent\</OutputPath>
2121
<DefineConstants>DEBUG;TRACE</DefineConstants>
2222
<ErrorReport>prompt</ErrorReport>
2323
<WarningLevel>4</WarningLevel>
@@ -27,7 +27,7 @@
2727
<PlatformTarget>AnyCPU</PlatformTarget>
2828
<DebugType>pdbonly</DebugType>
2929
<Optimize>true</Optimize>
30-
<OutputPath>bin\Release\</OutputPath>
30+
<OutputPath>..\BinAgent\</OutputPath>
3131
<DefineConstants>TRACE</DefineConstants>
3232
<ErrorReport>prompt</ErrorReport>
3333
<WarningLevel>4</WarningLevel>

0 commit comments

Comments
 (0)