My question (s)
Since there is some code to back up this question - I will ask it in advance. Are there any known performance issues with the Servicestack self-service (or indeed any HTTP listener) running on linux / mono?
My actual use case is for a web service invoking several other (non-public) web services. When working under windows, I notice that performance is fast, but when working under Linux / mono, it slows down and the request can take up to 15 seconds (compared to 0.2 seconds running under windows).
My next question is: what (if anything) am I doing wrong here?
.
My environment (s)
I run Windows 10 PC - i7-6700 @ 3.4ghz 4 cores - (hyperthreaded - so 8 logical cores), 32 GB of RAM and Linux VM (Ubuntu 16.04) using hyper V. It has 2 cores ( i7-6500 @ 3.4ghz - 4 GB assigned to it). In principle, nothing in the code below should be an excessive taxation of the equipment that underlies the definition of a service below. I also tried to host this on another virtual machine to make sure that this is not my local hardware, but I seem to get consistent results wherever I try. I am using mono: the last image and xbuild my C # solution to create a docker image that I host on a linux machine.
Also, I'm pretty new to the Linux world - not quite sure how to troubleshoot this platform (yet!)
: /linux:
class Program
{
static void Main(string[] args)
{
var listeningOn = args.Length == 0 ? "http://*:32700/api/user/" : args[0];
var appHost = new AppHost()
.Init()
.Start(listeningOn);
Console.WriteLine("AppHost Created at {0}, listening on {1}",
DateTime.Now, listeningOn);
if (Type.GetType("Mono.Runtime") != null)
{
UnixSignal.WaitAny(new[]
{
new UnixSignal(Signum.SIGINT),
new UnixSignal(Signum.SIGTERM),
new UnixSignal(Signum.SIGQUIT),
new UnixSignal(Signum.SIGHUP)
});
}
else
{
Console.ReadLine();
}
}
}
:
public class AppHost : AppSelfHostBase
{
public AppHost() : base("Test User Service", typeof(AppHost).Assembly)
{
Plugins.Add(new PostmanFeature());
Plugins.Add(new CorsFeature());
}
public override void Configure(Container container)
{
}
}
:
[Api("Get User"), Route("/getUserByUserIdentifier/{Tenant}/{Identifier}", "GET")]
public class GetUserByUserIdentifierRequest : IReturn<GetUserByUserIdentifierResponse>
{
public string Tenant { get; set; }
public string Identifier { get; set; }
}
public class GetUserByUserIdentifierResponse
{
public UserDto User { get; set; }
}
public class UserDto
{
public string UserName { get; set; }
public string UserIdentifier { get; set; }
}
, :
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Starting...");
ConcurrentBag<long> timings = new ConcurrentBag<long>();
Parallel.For(0, 100, new ParallelOptions { MaxDegreeOfParallelism = 8 }, x =>
{
Console.WriteLine("Attempt #{0}", x);
using (JsonServiceClient client = new JsonServiceClient("http://127.0.0.1:32700/api/user/"))
{
Stopwatch sw = new Stopwatch();
Console.WriteLine("Stopwatch started...");
sw.Start();
GetUserByUserIdentifierResponse response = client.Get(new GetUserByUserIdentifierRequest {Tenant = "F119A0DF-5002-4FF1-A0CE-8B60CFEE16A2", Identifier = "3216C49E-80C9-4249-9407-3E636E8C58AC"});
sw.Stop();
Console.WriteLine("Stopwatch stopped... got value [{0}] back in {1}ms", response.ToJson(), sw.ElapsedMilliseconds);
timings.Add(sw.ElapsedMilliseconds);
}
});
var allTimes = timings.ToList();
Console.WriteLine("Longest time taken = {0}ms", allTimes.Max());
Console.WriteLine("Shortest time taken = {0}ms", allTimes.Min());
Console.WriteLine("Avg time taken = {0}ms", allTimes.Average());
Console.WriteLine("Done!");
Console.ReadLine();
}
}
:
, 0,1 0,02 . 0,1 100 .
linux - , , , 0,8 0,05 , ( , ), 15 . Mono/linux, .NET/Windows!
, , 100 500, , Windows , , ( ) -:
System.IO.IOException was unhandled by user code
HResult=-2146232800
Message=Unable to read data from the transport connection: The connection was closed.
Source=System
StackTrace:
at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.IO.StreamReader.ReadBuffer()
at System.IO.StreamReader.ReadToEnd()
at ServiceStack.Text.JsonSerializer.DeserializeFromStream[T](Stream stream)
at ServiceStack.Serialization.JsonDataContractSerializer.DeserializeFromStream[T](Stream stream)
at ServiceStack.JsonServiceClient.DeserializeFromStream[T](Stream stream)
at ServiceStack.ServiceClientBase.GetResponse[TResponse](WebResponse webResponse)
at ServiceStack.ServiceClientBase.Send[TResponse](String httpMethod, String relativeOrAbsoluteUrl, Object request)
at ServiceStack.ServiceClientBase.Get[TResponse](IReturn`1 requestDto)
at httppoke.Program.<>c__DisplayClass0_0.<Main>b__0(Int32 x) in <Redacted>\Program.cs:line 30
at System.Threading.Tasks.Parallel.<>c__DisplayClass17_0`1.<ForWorker>b__1()
InnerException:
, , , , , .
, , "" " " linux , 4%. - .
: , - , , " ". , ( ) - , .
, , , , .
, , , Nancyfx, .
!