FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add support UDS(Unix Domain Socket) - Server/Client #135 · kdevil2k/NetCoreServer@c259786 · GitHub

Repository navigation

Commit c259786

Browse files
committed
Add support UDS(Unix Domain Socket) - Server/Client chronoxor#135
1 parent 2bf5d96 commit c259786

13 files changed

Lines changed: 761 additions & 5 deletions

File tree

‎NetCoreServer.sln‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UdsChatClient", "examples\U
9595
EndProject
9696
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UdsChatServer", "examples\UdsChatServer\UdsChatServer.csproj", "{F69349F3-47EE-4C82-B714-83E9B6E931CC}"
9797
EndProject
98+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UdsEchoClient", "performance\UdsEchoClient\UdsEchoClient.csproj", "{CA20DA7E-5E5E-4495-9F02-6D5D18558C77}"
99+
EndProject
100+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UdsEchoServer", "performance\UdsEchoServer\UdsEchoServer.csproj", "{13567A7F-923D-42C0-9451-A1821E087A69}"
101+
EndProject
102+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UdsMulticastClient", "performance\UdsMulticastClient\UdsMulticastClient.csproj", "{B1D5EA8F-9A1E-4AD6-9C40-A6A5EFDDE044}"
103+
EndProject
104+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UdsMulticastServer", "performance\UdsMulticastServer\UdsMulticastServer.csproj", "{80C95510-AF12-4CF0-8852-B21241F6C1F3}"
105+
EndProject
98106
Global
99107
GlobalSection(SolutionConfigurationPlatforms) = preSolution
100108
Debug|Any CPU = Debug|Any CPU
@@ -455,6 +463,38 @@ Global
455463
{F69349F3-47EE-4C82-B714-83E9B6E931CC}.Release|Any CPU.Build.0 = Release|Any CPU
456464
{F69349F3-47EE-4C82-B714-83E9B6E931CC}.Release|x64.ActiveCfg = Release|Any CPU
457465
{F69349F3-47EE-4C82-B714-83E9B6E931CC}.Release|x64.Build.0 = Release|Any CPU
466+
{CA20DA7E-5E5E-4495-9F02-6D5D18558C77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
467+
{CA20DA7E-5E5E-4495-9F02-6D5D18558C77}.Debug|Any CPU.Build.0 = Debug|Any CPU
468+
{CA20DA7E-5E5E-4495-9F02-6D5D18558C77}.Debug|x64.ActiveCfg = Debug|Any CPU
469+
{CA20DA7E-5E5E-4495-9F02-6D5D18558C77}.Debug|x64.Build.0 = Debug|Any CPU
470+
{CA20DA7E-5E5E-4495-9F02-6D5D18558C77}.Release|Any CPU.ActiveCfg = Release|Any CPU
471+
{CA20DA7E-5E5E-4495-9F02-6D5D18558C77}.Release|Any CPU.Build.0 = Release|Any CPU
472+
{CA20DA7E-5E5E-4495-9F02-6D5D18558C77}.Release|x64.ActiveCfg = Release|Any CPU
473+
{CA20DA7E-5E5E-4495-9F02-6D5D18558C77}.Release|x64.Build.0 = Release|Any CPU
474+
{13567A7F-923D-42C0-9451-A1821E087A69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
475+
{13567A7F-923D-42C0-9451-A1821E087A69}.Debug|Any CPU.Build.0 = Debug|Any CPU
476+
{13567A7F-923D-42C0-9451-A1821E087A69}.Debug|x64.ActiveCfg = Debug|Any CPU
477+
{13567A7F-923D-42C0-9451-A1821E087A69}.Debug|x64.Build.0 = Debug|Any CPU
478+
{13567A7F-923D-42C0-9451-A1821E087A69}.Release|Any CPU.ActiveCfg = Release|Any CPU
479+
{13567A7F-923D-42C0-9451-A1821E087A69}.Release|Any CPU.Build.0 = Release|Any CPU
480+
{13567A7F-923D-42C0-9451-A1821E087A69}.Release|x64.ActiveCfg = Release|Any CPU
481+
{13567A7F-923D-42C0-9451-A1821E087A69}.Release|x64.Build.0 = Release|Any CPU
482+
{B1D5EA8F-9A1E-4AD6-9C40-A6A5EFDDE044}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
483+
{B1D5EA8F-9A1E-4AD6-9C40-A6A5EFDDE044}.Debug|Any CPU.Build.0 = Debug|Any CPU
484+
{B1D5EA8F-9A1E-4AD6-9C40-A6A5EFDDE044}.Debug|x64.ActiveCfg = Debug|Any CPU
485+
{B1D5EA8F-9A1E-4AD6-9C40-A6A5EFDDE044}.Debug|x64.Build.0 = Debug|Any CPU
486+
{B1D5EA8F-9A1E-4AD6-9C40-A6A5EFDDE044}.Release|Any CPU.ActiveCfg = Release|Any CPU
487+
{B1D5EA8F-9A1E-4AD6-9C40-A6A5EFDDE044}.Release|Any CPU.Build.0 = Release|Any CPU
488+
{B1D5EA8F-9A1E-4AD6-9C40-A6A5EFDDE044}.Release|x64.ActiveCfg = Release|Any CPU
489+
{B1D5EA8F-9A1E-4AD6-9C40-A6A5EFDDE044}.Release|x64.Build.0 = Release|Any CPU
490+
{80C95510-AF12-4CF0-8852-B21241F6C1F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
491+
{80C95510-AF12-4CF0-8852-B21241F6C1F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
492+
{80C95510-AF12-4CF0-8852-B21241F6C1F3}.Debug|x64.ActiveCfg = Debug|Any CPU
493+
{80C95510-AF12-4CF0-8852-B21241F6C1F3}.Debug|x64.Build.0 = Debug|Any CPU
494+
{80C95510-AF12-4CF0-8852-B21241F6C1F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
495+
{80C95510-AF12-4CF0-8852-B21241F6C1F3}.Release|Any CPU.Build.0 = Release|Any CPU
496+
{80C95510-AF12-4CF0-8852-B21241F6C1F3}.Release|x64.ActiveCfg = Release|Any CPU
497+
{80C95510-AF12-4CF0-8852-B21241F6C1F3}.Release|x64.Build.0 = Release|Any CPU
458498
EndGlobalSection
459499
GlobalSection(SolutionProperties) = preSolution
460500
HideSolutionNode = FALSE
@@ -502,6 +542,10 @@ Global
502542
{20E95322-2F84-4147-8014-E50312D86CE5} = {8965E5CD-E36E-4DC5-A36E-827AFFC642D1}
503543
{7ED276AD-8EF0-44A5-87B6-60AAA822C5FF} = {81ED94B5-0C65-432C-AEF5-67C3DFF7F2EE}
504544
{F69349F3-47EE-4C82-B714-83E9B6E931CC} = {81ED94B5-0C65-432C-AEF5-67C3DFF7F2EE}
545+
{CA20DA7E-5E5E-4495-9F02-6D5D18558C77} = {8965E5CD-E36E-4DC5-A36E-827AFFC642D1}
546+
{13567A7F-923D-42C0-9451-A1821E087A69} = {8965E5CD-E36E-4DC5-A36E-827AFFC642D1}
547+
{B1D5EA8F-9A1E-4AD6-9C40-A6A5EFDDE044} = {8965E5CD-E36E-4DC5-A36E-827AFFC642D1}
548+
{80C95510-AF12-4CF0-8852-B21241F6C1F3} = {8965E5CD-E36E-4DC5-A36E-827AFFC642D1}
505549
EndGlobalSection
506550
GlobalSection(ExtensibilityGlobals) = postSolution
507551
SolutionGuid = {64415837-63D9-474E-A25C-EE91C9CA90C5}

‎README.md‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ Has integration with message protocol based on [Fast Binary Encoding](https://gi
4545
* [TCP echo server](#tcp-echo-server)
4646
* [SSL echo server](#ssl-echo-server)
4747
* [UDP echo server](#udp-echo-server)
48+
* [Unix Domain Socket echo server](#unix-domain-socket-echo-server)
4849
* [WebSocket echo server](#websocket-echo-server)
4950
* [WebSocket secure echo server](#websocket-secure-echo-server)
5051
* [Benchmark: Multicast](#benchmark-multicast)
5152
* [TCP multicast server](#tcp-multicast-server)
5253
* [SSL multicast server](#ssl-multicast-server)
5354
* [UDP multicast server](#udp-multicast-server)
55+
* [Unix Domain Socket multicast server](#unix-domain-socket-multicast-server)
5456
* [WebSocket multicast server](#websocket-multicast-server)
5557
* [WebSocket secure multicast server](#websocket-secure-multicast-server)
5658
* [Benchmark: Web Server](#benchmark-web-server)
@@ -2643,6 +2645,48 @@ Message latency: 15.950 mcs
26432645
Message throughput: 62693 msg/s
26442646
```
26452647

2648+
### Unix Domain Socket echo server
2649+
2650+
* [UdsEchoServer](https://github.com/chronoxor/NetCoreServer/blob/master/performance/UdsEchoServer/Program.cs)
2651+
* [UdsEchoClient](https://github.com/chronoxor/NetCoreServer/blob/master/performance/UdsEchoClient/Program.cs) --clients 1
2652+
2653+
```
2654+
Server Unix Domain Socket path: C:\Users\chronoxor\AppData\Local\Temp\echo.sock
2655+
Working clients: 1
2656+
Working messages: 1000
2657+
Message size: 32
2658+
Seconds to benchmarking: 10
2659+
2660+
Errors: 0
2661+
2662+
Total time: 10.016 s
2663+
Total data: 208.657 MiB
2664+
Total messages: 6836769
2665+
Data throughput: 20.850 MiB/s
2666+
Message latency: 1.465 mcs
2667+
Message throughput: 682575 msg/s
2668+
```
2669+
2670+
* [UdsEchoServer](https://github.com/chronoxor/NetCoreServer/blob/master/performance/UdsEchoServer/Program.cs)
2671+
* [UdsEchoClient](https://github.com/chronoxor/NetCoreServer/blob/master/performance/UdsEchoClient/Program.cs) --clients 100
2672+
2673+
```
2674+
Server Unix Domain Socket path: C:\Users\chronoxor\AppData\Local\Temp\echo.sock
2675+
Working clients: 100
2676+
Working messages: 1000
2677+
Message size: 32
2678+
Seconds to benchmarking: 10
2679+
2680+
Errors: 0
2681+
2682+
Total time: 12.253 s
2683+
Total data: 602.320 MiB
2684+
Total messages: 19736578
2685+
Data throughput: 49.157 MiB/s
2686+
Message latency: 620 ns
2687+
Message throughput: 1610666 msg/s
2688+
```
2689+
26462690
### WebSocket echo server
26472691

26482692
* [WsEchoServer](https://github.com/chronoxor/NetCoreServer/blob/master/performance/WsEchoServer/Program.cs)
@@ -2866,6 +2910,46 @@ Message latency: 10.682 mcs
28662910
Message throughput: 93606 msg/s
28672911
```
28682912

2913+
### Unix Domain Socket multicast server
2914+
2915+
* [UdsMulticastServer](https://github.com/chronoxor/NetCoreServer/blob/master/performance/UdsMulticastServer/Program.cs)
2916+
* [UdsMulticastClient](https://github.com/chronoxor/NetCoreServer/blob/master/performance/UdsMulticastClient/Program.cs) --clients 1
2917+
2918+
```
2919+
Server Unix Domain Socket path: C:\Users\chronoxor\AppData\Local\Temp\multicast.sock
2920+
Working clients: 1
2921+
Message size: 32
2922+
Seconds to benchmarking: 10
2923+
2924+
Errors: 0
2925+
2926+
Total time: 10.015 s
2927+
Total data: 204.127 MiB
2928+
Total messages: 6688763
2929+
Data throughput: 20.390 MiB/s
2930+
Message latency: 1.497 mcs
2931+
Message throughput: 667869 msg/s
2932+
```
2933+
2934+
* [UdsMulticastServer](https://github.com/chronoxor/NetCoreServer/blob/master/performance/UdsMulticastServer/Program.cs)
2935+
* [UdsMulticastClient](https://github.com/chronoxor/NetCoreServer/blob/master/performance/UdsMulticastClient/Program.cs) --clients 100
2936+
2937+
```
2938+
Server Unix Domain Socket path: C:\Users\chronoxor\AppData\Local\Temp\multicast.sock
2939+
Working clients: 100
2940+
Message size: 32
2941+
Seconds to benchmarking: 10
2942+
2943+
Errors: 0
2944+
2945+
Total time: 10.033 s
2946+
Total data: 124.463 MiB
2947+
Total messages: 4078051
2948+
Data throughput: 12.413 MiB/s
2949+
Message latency: 2.460 mcs
2950+
Message throughput: 406451 msg/s
2951+
```
2952+
28692953
### WebSocket multicast server
28702954

28712955
* [WsMulticastServer](https://github.com/chronoxor/NetCoreServer/blob/master/performance/WsMulticastServer/Program.cs)

‎examples/UdsChatClient/Program.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Program
5454
static void Main(string[] args)
5555
{
5656
// Unix Domain Socket path
57-
string path = Path.GetTempPath() + Path.DirectorySeparatorChar + "chat.sock";
57+
string path = Path.Combine(Path.GetTempPath(), "chat.sock");
5858
if (args.Length > 0)
5959
path = args[0];
6060

‎examples/UdsChatServer/Program.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Program
6060
static void Main(string[] args)
6161
{
6262
// Unix Domain Socket path
63-
string path = Path.GetTempPath() + Path.DirectorySeparatorChar + "chat.sock";
63+
string path = Path.Combine(Path.GetTempPath(), "chat.sock");
6464
if (args.Length > 0)
6565
path = args[0];
6666

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Net.Sockets;
5+
using System.Threading;
6+
using NetCoreServer;
7+
using NDesk.Options;
8+
9+
namespace UdsEchoClient
10+
{
11+
class EchoClient : UdsClient
12+
{
13+
public EchoClient(string path, int messages) : base(path)
14+
{
15+
_messages = messages;
16+
}
17+
18+
protected override void OnConnected()
19+
{
20+
for (long i = _messages; i > 0; i--)
21+
SendMessage();
22+
}
23+
24+
protected override void OnSent(long sent, long pending)
25+
{
26+
_sent += sent;
27+
}
28+
29+
protected override void OnReceived(byte[] buffer, long offset, long size)
30+
{
31+
_received += size;
32+
while (_received >= Program.MessageToSend.Length)
33+
{
34+
SendMessage();
35+
_received -= Program.MessageToSend.Length;
36+
}
37+
38+
Program.TimestampStop = DateTime.UtcNow;
39+
Program.TotalBytes += size;
40+
}
41+
42+
protected override void OnError(SocketError error)
43+
{
44+
Console.WriteLine($"Client caught an error with code {error}");
45+
Program.TotalErrors++;
46+
}
47+
48+
private void SendMessage()
49+
{
50+
SendAsync(Program.MessageToSend);
51+
}
52+
53+
private long _sent;
54+
private long _received;
55+
private long _messages;
56+
}
57+
58+
class Program
59+
{
60+
public static byte[] MessageToSend;
61+
public static DateTime TimestampStart = DateTime.UtcNow;
62+
public static DateTime TimestampStop = DateTime.UtcNow;
63+
public static long TotalErrors;
64+
public static long TotalBytes;
65+
public static long TotalMessages;
66+
67+
static void Main(string[] args)
68+
{
69+
bool help = false;
70+
string path = Path.Combine(Path.GetTempPath(), "echo.sock");
71+
int clients = 100;
72+
int messages = 1000;
73+
int size = 32;
74+
int seconds = 10;
75+
76+
var options = new OptionSet()
77+
{
78+
{ "h|?|help", v => help = v != null },
79+
{ "p|path=", v => path = v },
80+
{ "c|clients=", v => clients = int.Parse(v) },
81+
{ "m|messages=", v => messages = int.Parse(v) },
82+
{ "s|size=", v => size = int.Parse(v) },
83+
{ "z|seconds=", v => seconds = int.Parse(v) }
84+
};
85+
86+
try
87+
{
88+
options.Parse(args);
89+
}
90+
catch (OptionException e)
91+
{
92+
Console.Write("Command line error: ");
93+
Console.WriteLine(e.Message);
94+
Console.WriteLine("Try `--help' to get usage information.");
95+
return;
96+
}
97+
98+
if (help)
99+
{
100+
Console.WriteLine("Usage:");
101+
options.WriteOptionDescriptions(Console.Out);
102+
return;
103+
}
104+
105+
Console.WriteLine($"Server Unix Domain Socket path: {path}");
106+
Console.WriteLine($"Working clients: {clients}");
107+
Console.WriteLine($"Working messages: {messages}");
108+
Console.WriteLine($"Message size: {size}");
109+
Console.WriteLine($"Seconds to benchmarking: {seconds}");
110+
111+
Console.WriteLine();
112+
113+
// Prepare a message to send
114+
MessageToSend = new byte[size];
115+
116+
// Create echo clients
117+
var echoClients = new List<EchoClient>();
118+
for (int i = 0; i < clients; i++)
119+
{
120+
var client = new EchoClient(path, messages);
121+
echoClients.Add(client);
122+
}
123+
124+
TimestampStart = DateTime.UtcNow;
125+
126+
// Connect clients
127+
Console.Write("Clients connecting...");
128+
foreach (var client in echoClients)
129+
client.ConnectAsync();
130+
Console.WriteLine("Done!");
131+
foreach (var client in echoClients)
132+
while (!client.IsConnected)
133+
Thread.Yield();
134+
Console.WriteLine("All clients connected!");
135+
136+
// Wait for benchmarking
137+
Console.Write("Benchmarking...");
138+
Thread.Sleep(seconds * 1000);
139+
Console.WriteLine("Done!");
140+
141+
// Disconnect clients
142+
Console.Write("Clients disconnecting...");
143+
foreach (var client in echoClients)
144+
client.Disconnect();
145+
Console.WriteLine("Done!");
146+
foreach (var client in echoClients)
147+
while (client.IsConnected)
148+
Thread.Yield();
149+
Console.WriteLine("All clients disconnected!");
150+
151+
Console.WriteLine();
152+
153+
Console.WriteLine($"Errors: {TotalErrors}");
154+
155+
Console.WriteLine();
156+
157+
TotalMessages = TotalBytes / size;
158+
159+
Console.WriteLine($"Total time: {Utilities.GenerateTimePeriod((TimestampStop - TimestampStart).TotalMilliseconds)}");
160+
Console.WriteLine($"Total data: {Utilities.GenerateDataSize(TotalBytes)}");
161+
Console.WriteLine($"Total messages: {TotalMessages}");
162+
Console.WriteLine($"Data throughput: {Utilities.GenerateDataSize((long)(TotalBytes / (TimestampStop - TimestampStart).TotalSeconds))}/s");
163+
if (TotalMessages > 0)
164+
{
165+
Console.WriteLine($"Message latency: {Utilities.GenerateTimePeriod((TimestampStop - TimestampStart).TotalMilliseconds / TotalMessages)}");
166+
Console.WriteLine($"Message throughput: {(long)(TotalMessages / (TimestampStop - TimestampStart).TotalSeconds)} msg/s");
167+
}
168+
}
169+
}
170+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="NDesk.Options.Core" Version="1.2.5" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\..\source\NetCoreServer\NetCoreServer.csproj" />
14+
</ItemGroup>
15+
16+
</Project>

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL