Skip to content

Managed RIO Server #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions benchmarks.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,52 +23,78 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PureNativeHttpServer", "exp
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Benchmarks", "src\Benchmarks\Benchmarks.xproj", "{EC62ACF4-8B19-41C2-B699-D75CAB7763DF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManagedRIOHttpServer", "experimental\ManagedRIOHttpServer\ManagedRIOHttpServer.csproj", "{E635C37F-65EA-422C-A3E5-6B48422BF23F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{07773C38-B3F3-4D6C-B318-29C88F016AA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07773C38-B3F3-4D6C-B318-29C88F016AA9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07773C38-B3F3-4D6C-B318-29C88F016AA9}.Debug|x64.ActiveCfg = Debug|Any CPU
{07773C38-B3F3-4D6C-B318-29C88F016AA9}.Debug|x86.ActiveCfg = Debug|Any CPU
{07773C38-B3F3-4D6C-B318-29C88F016AA9}.Debug|x86.Build.0 = Debug|Any CPU
{07773C38-B3F3-4D6C-B318-29C88F016AA9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07773C38-B3F3-4D6C-B318-29C88F016AA9}.Release|Any CPU.Build.0 = Release|Any CPU
{07773C38-B3F3-4D6C-B318-29C88F016AA9}.Release|x64.ActiveCfg = Release|Any CPU
{07773C38-B3F3-4D6C-B318-29C88F016AA9}.Release|x86.ActiveCfg = Release|Any CPU
{07773C38-B3F3-4D6C-B318-29C88F016AA9}.Release|x86.Build.0 = Release|Any CPU
{1AE4BE9E-0E15-4B91-A32C-46DB4E1710BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1AE4BE9E-0E15-4B91-A32C-46DB4E1710BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1AE4BE9E-0E15-4B91-A32C-46DB4E1710BF}.Debug|x64.ActiveCfg = Debug|Any CPU
{1AE4BE9E-0E15-4B91-A32C-46DB4E1710BF}.Debug|x86.ActiveCfg = Debug|Any CPU
{1AE4BE9E-0E15-4B91-A32C-46DB4E1710BF}.Debug|x86.Build.0 = Debug|Any CPU
{1AE4BE9E-0E15-4B91-A32C-46DB4E1710BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1AE4BE9E-0E15-4B91-A32C-46DB4E1710BF}.Release|Any CPU.Build.0 = Release|Any CPU
{1AE4BE9E-0E15-4B91-A32C-46DB4E1710BF}.Release|x64.ActiveCfg = Release|Any CPU
{1AE4BE9E-0E15-4B91-A32C-46DB4E1710BF}.Release|x86.ActiveCfg = Release|Any CPU
{1AE4BE9E-0E15-4B91-A32C-46DB4E1710BF}.Release|x86.Build.0 = Release|Any CPU
{4A829ECA-062D-4C1F-BE88-E72E7BC972C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4A829ECA-062D-4C1F-BE88-E72E7BC972C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4A829ECA-062D-4C1F-BE88-E72E7BC972C3}.Debug|x64.ActiveCfg = Debug|Any CPU
{4A829ECA-062D-4C1F-BE88-E72E7BC972C3}.Debug|x86.ActiveCfg = Debug|Any CPU
{4A829ECA-062D-4C1F-BE88-E72E7BC972C3}.Debug|x86.Build.0 = Debug|Any CPU
{4A829ECA-062D-4C1F-BE88-E72E7BC972C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4A829ECA-062D-4C1F-BE88-E72E7BC972C3}.Release|Any CPU.Build.0 = Release|Any CPU
{4A829ECA-062D-4C1F-BE88-E72E7BC972C3}.Release|x64.ActiveCfg = Release|Any CPU
{4A829ECA-062D-4C1F-BE88-E72E7BC972C3}.Release|x86.ActiveCfg = Release|Any CPU
{4A829ECA-062D-4C1F-BE88-E72E7BC972C3}.Release|x86.Build.0 = Release|Any CPU
{A27BFB9B-3CA6-4A26-A7BD-66854399BED3}.Debug|Any CPU.ActiveCfg = Debug|Win32
{A27BFB9B-3CA6-4A26-A7BD-66854399BED3}.Debug|x64.ActiveCfg = Debug|Win32
{A27BFB9B-3CA6-4A26-A7BD-66854399BED3}.Debug|x86.ActiveCfg = Debug|Win32
{A27BFB9B-3CA6-4A26-A7BD-66854399BED3}.Debug|x86.Build.0 = Debug|Win32
{A27BFB9B-3CA6-4A26-A7BD-66854399BED3}.Release|Any CPU.ActiveCfg = Release|Win32
{A27BFB9B-3CA6-4A26-A7BD-66854399BED3}.Release|x64.ActiveCfg = Release|Win32
{A27BFB9B-3CA6-4A26-A7BD-66854399BED3}.Release|x86.ActiveCfg = Release|Win32
{A27BFB9B-3CA6-4A26-A7BD-66854399BED3}.Release|x86.Build.0 = Release|Win32
{EC62ACF4-8B19-41C2-B699-D75CAB7763DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EC62ACF4-8B19-41C2-B699-D75CAB7763DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC62ACF4-8B19-41C2-B699-D75CAB7763DF}.Debug|x64.ActiveCfg = Debug|Any CPU
{EC62ACF4-8B19-41C2-B699-D75CAB7763DF}.Debug|x86.ActiveCfg = Debug|Any CPU
{EC62ACF4-8B19-41C2-B699-D75CAB7763DF}.Debug|x86.Build.0 = Debug|Any CPU
{EC62ACF4-8B19-41C2-B699-D75CAB7763DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC62ACF4-8B19-41C2-B699-D75CAB7763DF}.Release|Any CPU.Build.0 = Release|Any CPU
{EC62ACF4-8B19-41C2-B699-D75CAB7763DF}.Release|x64.ActiveCfg = Release|Any CPU
{EC62ACF4-8B19-41C2-B699-D75CAB7763DF}.Release|x86.ActiveCfg = Release|Any CPU
{EC62ACF4-8B19-41C2-B699-D75CAB7763DF}.Release|x86.Build.0 = Release|Any CPU
{E635C37F-65EA-422C-A3E5-6B48422BF23F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E635C37F-65EA-422C-A3E5-6B48422BF23F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E635C37F-65EA-422C-A3E5-6B48422BF23F}.Debug|x64.ActiveCfg = Debug|Any CPU
{E635C37F-65EA-422C-A3E5-6B48422BF23F}.Debug|x64.Build.0 = Debug|Any CPU
{E635C37F-65EA-422C-A3E5-6B48422BF23F}.Debug|x86.ActiveCfg = Debug|Any CPU
{E635C37F-65EA-422C-A3E5-6B48422BF23F}.Debug|x86.Build.0 = Debug|Any CPU
{E635C37F-65EA-422C-A3E5-6B48422BF23F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E635C37F-65EA-422C-A3E5-6B48422BF23F}.Release|Any CPU.Build.0 = Release|Any CPU
{E635C37F-65EA-422C-A3E5-6B48422BF23F}.Release|x64.ActiveCfg = Release|Any CPU
{E635C37F-65EA-422C-A3E5-6B48422BF23F}.Release|x64.Build.0 = Release|Any CPU
{E635C37F-65EA-422C-A3E5-6B48422BF23F}.Release|x86.ActiveCfg = Release|Any CPU
{E635C37F-65EA-422C-A3E5-6B48422BF23F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -79,5 +105,6 @@ Global
{4A829ECA-062D-4C1F-BE88-E72E7BC972C3} = {C2EB60CC-CA5A-4E49-A3F8-4432FB117869}
{A27BFB9B-3CA6-4A26-A7BD-66854399BED3} = {C2EB60CC-CA5A-4E49-A3F8-4432FB117869}
{EC62ACF4-8B19-41C2-B699-D75CAB7763DF} = {995FCFF9-E5F6-4BDD-8E5B-FBDEA21145F9}
{E635C37F-65EA-422C-A3E5-6B48422BF23F} = {C2EB60CC-CA5A-4E49-A3F8-4432FB117869}
EndGlobalSection
EndGlobal
11 changes: 11 additions & 0 deletions experimental/ManagedRIOHttpServer/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
</startup>
<runtime>
<Thread_UseAllCpuGroups enabled="true"/>
<GCCpuGroup enabled="true"/>
<gcServer enabled="true"/>
</runtime>
</configuration>
12 changes: 12 additions & 0 deletions experimental/ManagedRIOHttpServer/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Copyright (c) Illyriad Games. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use
these files except in compliance with the License. You may obtain a copy of the
License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
88 changes: 88 additions & 0 deletions experimental/ManagedRIOHttpServer/ManagedRIOHttpServer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E635C37F-65EA-422C-A3E5-6B48422BF23F}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ManagedRIOHttpServer</RootNamespace>
<AssemblyName>ManagedRIOHttpServer</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x64</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>x64</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Numerics.Vectors.4.1.0-beta-23019\lib\net46\System.Numerics.Vectors.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RegisteredIO\RIOReceiveTask.cs" />
<Compile Include="RegisteredIO\RIOBufferPool.cs" />
<Compile Include="RegisteredIO\RIOImports.cs" />
<Compile Include="RegisteredIO\RIOPooledSegment.cs" />
<Compile Include="RegisteredIO\RIOTcpServer.cs" />
<Compile Include="RegisteredIO\RIOThreadPool.cs" />
<Compile Include="RegisteredIO\RIOWorkBundle.cs" />
<Compile Include="RegisteredIO\RIO_BUFSEGMENT.cs" />
<Compile Include="RegisteredIO\RIO_NOTIFICATION_COMPLETION.cs" />
<Compile Include="RegisteredIO\RIO_NOTIFICATION_COMPLETION_EVENT.cs" />
<Compile Include="RegisteredIO\RIO_NOTIFICATION_COMPLETION_IOCP.cs" />
<Compile Include="RegisteredIO\RIO_RESULT.cs" />
<Compile Include="RegisteredIO\RIOTcpConnection.cs" />
<Compile Include="RegisteredIO\RIO_NOTIFICATION_COMPLETION_TYPE.cs" />
<Compile Include="RIOServer.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="app.manifest" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
75 changes: 75 additions & 0 deletions experimental/ManagedRIOHttpServer/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (c) Illyriad Games. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Numerics;
using System.Threading;

namespace ManagedRIOHttpServer
{
public sealed class Program
{
static void Main(string[] args)
{
if (IntPtr.Size != 8)
{
Console.WriteLine("ManagedRIOHttpServer needs to be run in x64 mode");
return;
}

ThreadPool.SetMinThreads(100, 100);

Console.WriteLine("Starting Managed Registered IO Server");
Console.WriteLine("* Hardware Accelerated SIMD: {0}", Vector.IsHardwareAccelerated);
Console.WriteLine("* Vector<byte>.Count: {0}", Vector<byte>.Count);

try
{
var server = new RIOServer(5000);
server.Start();
}
catch (Exception ex)
{
Console.WriteLine("Start up issue {0}", ex.Message);
}
}

//static byte[] careBytes = new byte[] {
// 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
// 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
// 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
// 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
// 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
// 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
// 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
// 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
//};

//public static void LowerCaseSIMD(ArraySegment<byte> data)
//{
// if (data.Offset + data.Count + Vector<byte>.Count < data.Array.Length)
// {
// throw new ArgumentOutOfRangeException("Nope");
// }
// var A = new Vector<byte>(65); // A
// var Z = new Vector<byte>(90); // Z

// for (var o = data.Offset; o < data.Count - Vector<byte>.Count; o += Vector<byte>.Count)
// {
// var v = new Vector<byte>(data.Array, o);

// v = Vector.ConditionalSelect(
// Vector.BitwiseAnd(
// Vector.GreaterThanOrEqual(v, A),
// Vector.LessThanOrEqual(v, Z)
// ),
// Vector.BitwiseOr(new Vector<byte>(0x20), v), // 0010 0000
// v
// );
// v.CopyTo(data.Array, o);
// }
//}
}

}

36 changes: 36 additions & 0 deletions experimental/ManagedRIOHttpServer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ManagedRIOServer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Illyriad Games")]
[assembly: AssemblyProduct("ManagedRIOServer")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("e635c37f-65ea-422c-a3e5-6b48422bf23f")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
45 changes: 45 additions & 0 deletions experimental/ManagedRIOHttpServer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Managed C# Registered IO Http Server
Mostly an exploration into calling the [Winsock high-speed networking Registered I/O extensions](https://msdn.microsoft.com/en-us/library/windows/desktop/ms740642(v=vs.85).aspx)
from managed code.

A variation of the ```NativeHttpServer``` behaviour

# Caution
It runs.

Horribly, **horribly** hacky.

There is precious little documentation about even using RIO from native code; so at the moment its more like a trial and error,
organically grown testbed of functions to call and their signatures than even a sensibly organised bit of code :(

But looks like it can be done! :)

# How to run

Needs the x64 v4.6 CLR; compile release and run the ```ManagedRIOHttpServer.exe``` in the ```bin\Release``` folder from a command prompt.

Or double click on ```ManagedRIOHttpServer.exe``` from windows explorer.

Listens on port 5000

# Todo
* Potentially higher read thoughput by posting multiple receives at a time to and to allow read buffering
(application managed rather than Winsock managed for RIO);
as sends are read dependant in this test - may increase overall throughput.
* Deallocate resources correctly.
* Clean up code.

# About Registered IO

Registered RIO //build/ announce from 2011
http://channel9.msdn.com/events/Build/BUILD2011/SAC-593T

> Microsoft Windows 8 and Windows Server 2012 introduce new Windows Sockets programming elements.

>A set of high-speed networking extensions are available for increased networking performance with lower latency and jitter. These extensions targeted primarily for server applications use pre-registered data buffers and completion queues to increase performance.

>The following are new Windows Sockets functions added to support Winsock high-speed networking Registered I/O extensions:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms740642(v=vs.85).aspx


Loading