Skip to content

Commit

Permalink
Performance issue (#95)
Browse files Browse the repository at this point in the history
* Tweaks to run performance sampling

* Defining new Targets

* Resolution of some issues of the EmbedIO framework:
- Line 26. StaticFilesSample.cs. Parent removed.

Changing of the url:
- Line 19. Program.cs (Samples). New URL: http://*:8787/

* Changes to travis targets

* Upgrade nugets

* My bad

* Minor change

* Add WatchDog to WebModules

* Some cache paths and removing abstract method

* Refactoring StaticFilesModule

* Improvements in VirtualPaths

* Resolving issues with Unit testing

* Fixed issue with Virtual Path cache

* Code Style

* Change default value of Watchdog WebModule and change Redirect unit test to run on linux.

* Trying to fix issues unit test travis

* Remove issue with PR build

* Test DebugType hack

* Fix Redirect
  • Loading branch information
geoperez authored Sep 21, 2017
1 parent 82f56dd commit 43099cf
Show file tree
Hide file tree
Showing 47 changed files with 587 additions and 632 deletions.
21 changes: 7 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,24 @@ matrix:
mono: latest
sudo: required
- os: linux
dotnet: 1.0.1
dotnet: 2.0.0
mono: none
env: DOTNETCORE=1
dist: trusty
sudo: false
- os: osx
dotnet: 1.0.1
dotnet: 2.0.0
mono: none
env: DOTNETCORE=1
- os: osx
mono: latest
install:
- if [[ $DOTNETCORE == "1" ]]; then dotnet restore Unosquare.Labs.EmbedIO.sln; else msbuild /t:restore Unosquare.Labs.EmbedIO.sln; fi
- if [[ $DOTNETCORE == "" ]]; then nuget install NUnit.ConsoleRunner -OutputDirectory testrunner; fi
before_script:
- if [[ $DOTNETCORE == "" ]]; then export LD_LIBRARY_PATH=/usr/local/lib; fi
- if [[ $DOTNETCORE == "" && $TRAVIS_OS_NAME = "linux" ]]; then sed -i 's/uap10.0;netstandard1.6;netstandard1.3;net46;net462/net46;net462/g' ./src/Unosquare.Labs.EmbedIO/Unosquare.Labs.EmbedIO.csproj; fi
- if [[ $DOTNETCORE == "" && $TRAVIS_OS_NAME = "linux" ]]; then sed -i 's/net46;net462;netcoreapp1.1/net46;net462/g' ./src/Unosquare.Labs.EmbedIO.Command/Unosquare.Labs.EmbedIO.Command.csproj; fi
- if [[ $DOTNETCORE == "" && $TRAVIS_OS_NAME = "linux" ]]; then sed -i 's/netcoreapp1.1;net462;net46/net46;net462/g' ./src/Unosquare.Labs.EmbedIO.Samples/Unosquare.Labs.EmbedIO.Samples.csproj; fi
- if [[ $DOTNETCORE == "" && $TRAVIS_OS_NAME = "linux" ]]; then sed -i 's/netcoreapp1.1;net462;net46/net46;net462/g' ./test/Unosquare.Labs.EmbedIO.Tests/Unosquare.Labs.EmbedIO.Tests.csproj; fi
- if [[ $DOTNETCORE == "" && $TRAVIS_OS_NAME = "osx" ]]; then sed -i '' 's/uap10.0;netstandard1.6;netstandard1.3;net46;net462/net46;net462/g' ./src/Unosquare.Labs.EmbedIO/Unosquare.Labs.EmbedIO.csproj; fi
- if [[ $DOTNETCORE == "" && $TRAVIS_OS_NAME = "osx" ]]; then sed -i '' 's/net46;net462;netcoreapp1.1/net46;net462/g' ./src/Unosquare.Labs.EmbedIO.Command/Unosquare.Labs.EmbedIO.Command.csproj; fi
- if [[ $DOTNETCORE == "" && $TRAVIS_OS_NAME = "osx" ]]; then sed -i '' 's/netcoreapp1.1;net462;net46/net46;net462/g' ./src/Unosquare.Labs.EmbedIO.Samples/Unosquare.Labs.EmbedIO.Samples.csproj; fi
- if [[ $DOTNETCORE == "" && $TRAVIS_OS_NAME = "osx" ]]; then sed -i '' 's/netcoreapp1.1;net462;net46/net46;net462/g' ./test/Unosquare.Labs.EmbedIO.Tests/Unosquare.Labs.EmbedIO.Tests.csproj; fi
- if [[ $DOTNETCORE == "" && $TRAVIS_OS_NAME = "linux" ]]; then sed -i 's/uap10.0;netstandard1.3;net46;netstandard2.0/net46/g' ./src/Unosquare.Labs.EmbedIO/Unosquare.Labs.EmbedIO.csproj; fi
- if [[ $DOTNETCORE == "" && $TRAVIS_OS_NAME = "linux" ]]; then sed -i 's/net46;netcoreapp2.0/net46/g' ./src/Unosquare.Labs.EmbedIO.Command/Unosquare.Labs.EmbedIO.Command.csproj; fi
- if [[ $DOTNETCORE == "" && $TRAVIS_OS_NAME = "linux" ]]; then sed -i 's/net46;netcoreapp2.0/net46/g' ./src/Unosquare.Labs.EmbedIO.Samples/Unosquare.Labs.EmbedIO.Samples.csproj; fi
- if [[ $DOTNETCORE == "" && $TRAVIS_OS_NAME = "linux" ]]; then sed -i 's/net46;netcoreapp2.0/net46/g' ./test/Unosquare.Labs.EmbedIO.Tests/Unosquare.Labs.EmbedIO.Tests.csproj; fi
script:
- if [[ $DOTNETCORE == "" ]]; then msbuild Unosquare.Labs.EmbedIO.sln /p:Configuration=Release; else dotnet test ./test/Unosquare.Labs.EmbedIO.Tests/Unosquare.Labs.EmbedIO.Tests.csproj -f netcoreapp1.1; fi
- if [[ $DOTNETCORE == "" ]]; then msbuild Unosquare.Labs.EmbedIO.sln /p:Configuration=Release; else dotnet test ./test/Unosquare.Labs.EmbedIO.Tests/Unosquare.Labs.EmbedIO.Tests.csproj -f netcoreapp2.0; fi
- if [[ $DOTNETCORE == "" ]]; then mono ./testrunner/NUnit.ConsoleRunner.*/tools/nunit3-console.exe --process=Single ./test/Unosquare.Labs.EmbedIO.Tests/bin/Release/net46/Unosquare.Labs.EmbedIO.Tests.dll; fi
- if [[ $DOTNETCORE == "" ]]; then cat TestResult.xml; fi
8 changes: 7 additions & 1 deletion Unosquare.Labs.EmbedIO.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.3
VisualStudioVersion = 15.0.26730.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{97BC259A-4E78-4BA8-8F4D-2656BC78BB34}"
EndProject
Expand All @@ -24,6 +24,9 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Unosquare.Labs.EmbedIO.Samples", "src\Unosquare.Labs.EmbedIO.Samples\Unosquare.Labs.EmbedIO.Samples.csproj", "{5B312B76-1C92-4C50-9A44-BAF738377306}"
EndProject
Global
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Expand Down Expand Up @@ -58,4 +61,7 @@ Global
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {197F095C-03FC-4632-8C1F-CC038D75CEAB}
EndGlobalSection
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
EndGlobal
8 changes: 6 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ before_build:
build_script:
- msbuild /p:Configuration=%CONFIGURATION% Unosquare.Labs.EmbedIO.sln
test_script:
- dotnet test test\Unosquare.Labs.EmbedIO.Tests\Unosquare.Labs.EmbedIO.Tests.csproj -c %CONFIGURATION% -f net46
- dotnet test test\Unosquare.Labs.EmbedIO.Tests\Unosquare.Labs.EmbedIO.Tests.csproj -c %CONFIGURATION% -f netcoreapp2.0
- tools\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"%ProgramFiles%\dotnet\dotnet.exe" -targetargs:"test test\Unosquare.Labs.EmbedIO.Tests\Unosquare.Labs.EmbedIO.Tests.csproj -c %CONFIGURATION% -f net46" -output:coverage.xml -filter:"+[Unosquare.Labs.EmbedIO*]* -[Unosquare.Labs.EmbedIO.Test*]*" -register:userdotnet
- tools\coveralls.net.0.7.0\tools\csmacnz.Coveralls.exe --opencover -i coverage.xml --serviceName appveyor --jobId %APPVEYOR_BUILD_NUMBER%
- ps: |
if(-Not $env:APPVEYOR_PULL_REQUEST_TITLE)
{
tools\coveralls.net.0.7.0\tools\csmacnz.Coveralls.exe --opencover -i coverage.xml --serviceName appveyor --jobId %APPVEYOR_BUILD_NUMBER%
}
after_build:
- ps: |
if(-Not $env:APPVEYOR_PULL_REQUEST_TITLE)
Expand Down
12 changes: 4 additions & 8 deletions src/Unosquare.Labs.EmbedIO.Command/Options.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Unosquare.Swan;

namespace Unosquare.Labs.EmbedIO.Command
namespace Unosquare.Labs.EmbedIO.Command
{
using Swan.Attributes;

/// <summary>
/// CLI options container
/// </summary>
Expand All @@ -12,11 +12,7 @@ internal class Options

[ArgumentOption('o', "port", HelpText = "HTTP port.", DefaultValue = 9696)]
public int Port { get; set; }

// TODO: Add support to OptionList at SWAN
//[OptionList('a', "api", Separator = ',', HelpText = "Specify assemblies to load, separated by a comma.")]
//public IList<string> ApiAssemblies { get; set; }


[ArgumentOption('a', "api", HelpText = "Specify assembly to load.")]
public string ApiAssemblies { get; set; }

Expand Down
11 changes: 1 addition & 10 deletions src/Unosquare.Labs.EmbedIO.Command/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
{
using Swan;
using System;
#if !NETCOREAPP1_1
using System.Reflection;
#else
using System.Runtime.Loader;
#endif

/// <summary>
/// Entry point
Expand Down Expand Up @@ -40,7 +36,7 @@ private static void Main(string[] args)
//server.Module<StaticFilesModule>().DefaultExtension = Properties.Settings.Default.HtmlDefaultExtension;
//server.Module<StaticFilesModule>().UseRamCache = Properties.Settings.Default.UseRamCache;

if (string.IsNullOrEmpty(options.ApiAssemblies))
if (string.IsNullOrEmpty(options.ApiAssemblies) == false)
{
$"Registering Assembly {options.ApiAssemblies}".Debug();
LoadApi(options.ApiAssemblies, server);
Expand All @@ -61,12 +57,7 @@ private static void LoadApi(string apiPath, WebServer server)
{
try
{
#if !NETCOREAPP1_1
var assembly = Assembly.LoadFile(apiPath);
#else
var assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(apiPath);
#endif
if (assembly == null) return;

server.LoadApiControllers(assembly).LoadWebSockets(assembly);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Unosquare.Labs.EmbedIO.Command/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ Start any web folder or EmbedIO-enabled DLL from command line.
### Run web folder (static content only)

```
$ embediocli -p c:\wwwroot
$ Unosquare.Labs.EmbedIO.Command -p c:\wwwroot
```

### Run web folder with WebAPI or WebSocket Assembly

```
$ embediocli -p c:\wwwroot --api mywebapi.dll
$ Unosquare.Labs.EmbedIO.Command -p c:\wwwroot --api mywebapi.dll
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<PropertyGroup>
<Description>Portable web server ready to use</Description>
<Copyright>Copyright (c) 2016 - Unosquare</Copyright>
<Copyright>Copyright (c) 2016-2017 - Unosquare</Copyright>
<AssemblyTitle>EmbedIO CLI</AssemblyTitle>
<TargetFrameworks>net46;net462;netcoreapp1.1</TargetFrameworks>
<TargetFrameworks>net46;netcoreapp2.0</TargetFrameworks>
<AssemblyName>Unosquare.Labs.EmbedIO.Command</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>Unosquare.Labs.EmbedIO.Command</PackageId>
Expand All @@ -19,21 +19,4 @@
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net46' ">
<DefineConstants>$(DefineConstants);NETFX</DefineConstants>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.1' ">
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>

</Project>
10 changes: 6 additions & 4 deletions src/Unosquare.Labs.EmbedIO.Samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ internal class Program
/// <param name="args">The arguments.</param>
private static void Main(string[] args)
{
Terminal.Settings.DisplayLoggingMessageType = LogMessageType.Error;

$"Running on Mono Runtime: {Runtime.IsUsingMonoRuntime}".Info();

var url = "http://localhost:8787/";
var url = "http://*:8787/";

if (args.Length > 0)
url = args[0];
Expand Down Expand Up @@ -60,7 +62,7 @@ private static void Main(string[] args)
// Set the CORS Rules
server.RegisterModule(new CorsModule(
// Origins, separated by comma without last slash
"http://client.cors-api.appspot.com,http://unosquare.github.io,http://run.plnkr.co",
"http://unosquare.github.io,http://run.plnkr.co",
// Allowed headers
"content-type, accept",
// Allowed methods
Expand All @@ -84,10 +86,10 @@ private static void Main(string[] args)
server.RunAsync();

// Fire up the browser to show the content!
#if DEBUG && !NETCOREAPP1_1
#if DEBUG && !NETCOREAPP2_0
var browser = new System.Diagnostics.Process()
{
StartInfo = new System.Diagnostics.ProcessStartInfo(url)
StartInfo = new System.Diagnostics.ProcessStartInfo(url.Replace("*", "localhost"))
{
UseShellExecute = true
}
Expand Down
2 changes: 1 addition & 1 deletion src/Unosquare.Labs.EmbedIO.Samples/StaticFilesSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static string HtmlRootPath

// This lets you edit the files without restarting the server.
#if DEBUG && !MONO
return Path.Combine(Directory.GetParent(assemblyPath).Parent.Parent.Parent.FullName, "html");
return Path.Combine(Directory.GetParent(assemblyPath).Parent.Parent.FullName, "html");
#else
// This is when you have deployed the server.
return Path.Combine(assemblyPath, "html");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp1.1;net462;net46</TargetFrameworks>
<TargetFrameworks>net46;netcoreapp2.0</TargetFrameworks>
<AssemblyName>Unosquare.Labs.EmbedIO.Samples</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>Unosquare.Labs.EmbedIO.Samples</PackageId>
Expand All @@ -23,13 +23,7 @@
<PackageReference Include="Tubular.ServerSide" Version="1.4.4" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net462' ">
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">
<DefineConstants>$(DefineConstants);NET47</DefineConstants>
</PropertyGroup>

Expand Down
4 changes: 1 addition & 3 deletions src/Unosquare.Labs.EmbedIO.Samples/WebSocketsSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static void Setup(WebServer server)
public class WebSocketsChatServer : WebSocketsServer
{
public WebSocketsChatServer()
: base(true, 0)
: base(true)
{
// placeholder
}
Expand Down Expand Up @@ -200,9 +200,7 @@ protected override void OnClientConnected(WebSocketContext context)
StartInfo = new ProcessStartInfo()
{
CreateNoWindow = true,
#if !NETCOREAPP1_1
ErrorDialog = false,
#endif
FileName = "cmd.exe",
RedirectStandardError = true,
RedirectStandardInput = true,
Expand Down
6 changes: 3 additions & 3 deletions src/Unosquare.Labs.EmbedIO/Constants/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal static class Strings
/// The format culture used for header outputs
/// </summary>
internal static CultureInfo StandardCultureInfo { get; } =
#if NETFX
#if !NETSTANDARD1_3 && !UWP
CultureInfo.CreateSpecificCulture("en-US");
#else
new CultureInfo("en-US");
Expand All @@ -44,7 +44,7 @@ internal static class Strings
/// The standard string comparer
/// </summary>
internal static StringComparer StandardStringComparer { get; } =
#if NETFX
#if !NETSTANDARD1_3 && !UWP
StringComparer.InvariantCultureIgnoreCase;
#else
StringComparer.OrdinalIgnoreCase;
Expand All @@ -54,7 +54,7 @@ internal static class Strings
/// The static file string comparer
/// </summary>
internal static StringComparer StaticFileStringComparer { get; } =
#if NETFX
#if !NETSTANDARD1_3 && !UWP
StringComparer.InvariantCulture;
#else
StringComparer.Ordinal;
Expand Down
37 changes: 6 additions & 31 deletions src/Unosquare.Labs.EmbedIO/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,15 @@ public static SessionInfo GetSession(this WebServer server, WebSocketContext con
/// <param name="context">The context.</param>
/// <returns>Path for the specified context</returns>
public static string RequestPath(this HttpListenerContext context)
{
return context.Request.Url.LocalPath.ToLowerInvariant();
}
=> context.Request.Url.LocalPath.ToLowerInvariant();

/// <summary>
/// Gets the request path for the specified context case sensitive.
/// </summary>
/// <param name="context">The context.</param>
/// <returns>Path for the specified context</returns>
public static string RequestPathCaseSensitive(this HttpListenerContext context)
{
return context.Request.Url.LocalPath;
}
=> context.Request.Url.LocalPath;

/// <summary>
/// Retrieves the Request HTTP Verb (also called Method) of this context.
Expand Down Expand Up @@ -179,9 +175,7 @@ public static bool InQueryString(this HttpListenerContext context, string key)
/// <param name="headerName">Name of the header.</param>
/// <returns>Specified request the header when is true; otherwise, empty string </returns>
public static string RequestHeader(this HttpListenerContext context, string headerName)
{
return context.HasRequestHeader(headerName) == false ? string.Empty : context.Request.Headers[headerName];
}
=> context.Request.Headers[headerName] ?? string.Empty;

/// <summary>
/// Determines whether [has request header] [the specified context].
Expand All @@ -190,9 +184,7 @@ public static string RequestHeader(this HttpListenerContext context, string head
/// <param name="headerName">Name of the header.</param>
/// <returns>True if request headers is not a null; otherwise, false</returns>
public static bool HasRequestHeader(this HttpListenerContext context, string headerName)
{
return context.Request.Headers[headerName] != null;
}
=> context.Request.Headers[headerName] != null;

/// <summary>
/// Retrieves the request body as a string.
Expand Down Expand Up @@ -355,9 +347,7 @@ public static T ParseJson<T>(this string requestBody)
/// <param name="requestBody">The request body.</param>
/// <returns>A collection that represents KVPs from request data</returns>
public static Dictionary<string, object> RequestFormDataDictionary(this string requestBody)
{
return FormDataParser.ParseAsDictionary(requestBody);
}
=> FormDataParser.ParseAsDictionary(requestBody);

/// <summary>
/// Returns dictionary from Request POST data
Expand All @@ -366,9 +356,7 @@ public static Dictionary<string, object> RequestFormDataDictionary(this string r
/// <param name="context">The context to request body as string</param>
/// <returns>A collection that represents KVPs from request data</returns>
public static Dictionary<string, object> RequestFormDataDictionary(this HttpListenerContext context)
{
return RequestFormDataDictionary(context.RequestBody());
}
=> RequestFormDataDictionary(context.RequestBody());

#endregion

Expand Down Expand Up @@ -456,18 +444,5 @@ public static byte[] Compress(this byte[] buffer, CompressionMethod method = Com
}

#endregion

internal static T GetValueOrDefault<T>(this Dictionary<T, T> dict, T key, T defaultValue = default(T))
{
return dict.ContainsKey(key) ? dict[key] : defaultValue;
}

internal static void ForEach<T>(this Dictionary<T, T> dict, Action<T, T> itemAction)
{
foreach (var kvp in dict)
{
itemAction(kvp.Key, kvp.Value);
}
}
}
}
Loading

0 comments on commit 43099cf

Please sign in to comment.