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
6 changed files
with
180 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{728EAD77-A9B7-412A-B4C9-E31066A6D4C1}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>LoadTest</RootNamespace> | ||
<AssemblyName>LoadTest</AssemblyName> | ||
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug</OutputPath> | ||
<DefineConstants>DEBUG;</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<ExternalConsole>true</ExternalConsole> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release</OutputPath> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<ExternalConsole>true</ExternalConsole> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="MainClass.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Telepathy\Telepathy.csproj"> | ||
<Project>{1D55A635-BC4E-4DDE-8D9A-044956F75A24}</Project> | ||
<Name>Telepathy</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="README.md" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | ||
</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,71 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading; | ||
|
||
namespace Telepathy.LoadTest | ||
{ | ||
class MainClass | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
// start server | ||
Server server = new Server(); | ||
server.Start(1337); | ||
int serverFrequency = 60; | ||
Thread serverThread = new Thread(() => | ||
{ | ||
Logger.Log("started server"); | ||
while (true) | ||
{ | ||
// reply to each incoming message | ||
Message msg; | ||
while (server.GetNextMessage(out msg)) | ||
{ | ||
if (msg.eventType == EventType.Data) | ||
server.Send(msg.connectionId, msg.data); | ||
} | ||
// sleep | ||
Thread.Sleep(1000 / serverFrequency); | ||
} | ||
}); | ||
serverThread.IsBackground = false; | ||
serverThread.Start(); | ||
|
||
// start n clients and get queue messages all in this thread | ||
int clientAmount = 1000; | ||
string message = "Sometimes we just need a good networking library"; | ||
byte[] messageBytes = Encoding.ASCII.GetBytes(message); | ||
int clientFrequency = 14; | ||
List<Client> clients = new List<Client>(); | ||
for (int i = 0; i < clientAmount; ++i) | ||
{ | ||
Client client = new Client(); | ||
client.Connect("127.0.0.1", 1337); | ||
clients.Add(client); | ||
Thread.Sleep(15); | ||
} | ||
Logger.Log("started all clients"); | ||
|
||
while (true) | ||
{ | ||
foreach (Client client in clients) | ||
{ | ||
// send 2 messages each time | ||
client.Send(messageBytes); | ||
client.Send(messageBytes); | ||
|
||
// get new messages from queue | ||
Message msg; | ||
while (client.GetNextMessage(out msg)) | ||
{ | ||
} | ||
} | ||
|
||
// client tick rate | ||
Thread.Sleep(1000 / clientFrequency); | ||
} | ||
} | ||
} | ||
} |
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,26 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
|
||
// Information about this assembly is defined by the following attributes. | ||
// Change them to the values specific to your project. | ||
|
||
[assembly: AssemblyTitle("LoadTest")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("")] | ||
[assembly: AssemblyCopyright("${AuthorCopyright}")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". | ||
// The form "{Major}.{Minor}.*" will automatically update the build and revision, | ||
// and "{Major}.{Minor}.{Build}.*" will update just the revision. | ||
|
||
[assembly: AssemblyVersion("1.0.*")] | ||
|
||
// The following attributes are used to specify the signing key for the assembly, | ||
// if desired. See the Mono documentation for more information about signing. | ||
|
||
//[assembly: AssemblyDelaySign(false)] | ||
//[assembly: AssemblyKeyFile("")] |
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,30 @@ | ||
## Telepathy Load Test ## | ||
|
||
Spawn 1 server and 1000 clients. | ||
|
||
Each client sends 100 bytes 14 per second and the server echoes back the same message. | ||
|
||
Test Computer: 2015 Macbook Pro with a 2,2 GHz Intel Core i7 processor.<br/> | ||
Test Results:<br/> | ||
|
||
| Clients | CPU Usage | Ram Usage | Bandwidth Client+Server | Result | | ||
| ------- | ----------| --------- | ------------------------ | ------ | | ||
| 128 | 7% | 26 MB | 1-2 MB/s | Passed | | ||
| 500 | 28% | 51 MB | 3-4 MB/s | Passed | | ||
| 1000 | 42% | 75 MB | 3-5 MB/s | Passed | | ||
|
||
_Note: results will be significantly better on a really powerful server. | ||
|
||
## Troubleshooting ## | ||
|
||
If you run this on a mac and you get the following error: | ||
``` | ||
Unhandled Exception: | ||
System.Net.Sockets.SocketException (0x80004005): Too many open files | ||
``` | ||
|
||
You will need to raise the open file limit. Issue the following command: | ||
|
||
``` | ||
ulimit -n 2048 | ||
``` |
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