Skip to content

Commit

Permalink
Include a load test project
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpach committed Aug 13, 2018
1 parent d118908 commit ff5d8a6
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 71 deletions.
46 changes: 46 additions & 0 deletions LoadTest/LoadTest.csproj
@@ -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>
71 changes: 71 additions & 0 deletions LoadTest/MainClass.cs
@@ -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);
}
}
}
}
26 changes: 26 additions & 0 deletions LoadTest/Properties/AssemblyInfo.cs
@@ -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("")]
30 changes: 30 additions & 0 deletions LoadTest/README.md
@@ -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
```
72 changes: 1 addition & 71 deletions README.md
Expand Up @@ -219,74 +219,4 @@ Test Results:<br/>

_Note: results will be significantly better on a really powerful server. Tests will follow._

The Connections Test can be reproduced with the following code:<br/>
```C#
using System.Collections.Generic;
using System.Text;
using System.Threading;
using Telepathy;

public class Test
{
static void Main()
{
// 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("localhost", 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);
}
}
}
```
You can run this test yourself by running the provided (LoadTest)
6 changes: 6 additions & 0 deletions Telepathy.sln
Expand Up @@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Telepathy", "Telepathy\Telepathy.csproj", "{1D55A635-BC4E-4DDE-8D9A-044956F75A24}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoadTest", "LoadTest\LoadTest.csproj", "{728EAD77-A9B7-412A-B4C9-E31066A6D4C1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -13,5 +15,9 @@ Global
{1D55A635-BC4E-4DDE-8D9A-044956F75A24}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D55A635-BC4E-4DDE-8D9A-044956F75A24}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D55A635-BC4E-4DDE-8D9A-044956F75A24}.Release|Any CPU.Build.0 = Release|Any CPU
{728EAD77-A9B7-412A-B4C9-E31066A6D4C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{728EAD77-A9B7-412A-B4C9-E31066A6D4C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{728EAD77-A9B7-412A-B4C9-E31066A6D4C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{728EAD77-A9B7-412A-B4C9-E31066A6D4C1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

0 comments on commit ff5d8a6

Please sign in to comment.