- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我的问题
由于有一些代码可以支持这个问题 - 我会提前询问。在 linux/mono 上运行的 Servicestack 自托管服务(或任何 http 监听器)是否存在任何已知的性能问题?
我的实际用例是用于调用多个其他(非公共(public))Web 服务的 Web 服务。在 windows 下运行时,我注意到性能快得令人眼花缭乱,但在 linux/mono 下运行时 - 它似乎变慢了,请求的长度最多可能需要 15 秒(与在 windows 下运行的 0.2 秒相比)。
我的后续问题是 - 我在这里做错了什么(如果有的话)?
.
我的环境
我正在运行 Windows 10 PC - i7-6700 @ 3.4ghz 4 核 -(超线程 - 所以 8 个逻辑核),32GB 内存,并且有一个使用 hyper V 的 Linux VM(Ubuntu 16.04)。它有 2 个核(i7-6500 @3.4ghz - 分配给它的 4GB Ram)。基本上 - 下面的代码中的任何内容都不应该对下面的服务定义下的硬件过度征税。我也试过将它托管在其他虚拟机上,以确保它不是我的本地硬件 - 但无论我在哪里尝试,我似乎都能得到一致的结果。
我使用 mono:latest 图像和 xbuild 我的 C# 解决方案来创建我在 linux 机器上托管的 docker 图像。
另外 - 我对 Linux 世界还很陌生 - 不太确定如何在这个平台上进行故障排除(还!)
其中一项服务的示例
程序类:适用于 windows/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);
// check if we're running on mono
if (Type.GetType("Mono.Runtime") != null)
{
// on mono, processes will usually run as daemons - this allows you to listen
// for termination signals (ctrl+c, shutdown, etc) and finalize correctly
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)
{
}
}
契约(Contract):
[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/")) //Specify Linux box IP here!
{
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();
}
结果:
所以在我的本地 Windows 机器上,每个请求可能需要 0.1 秒到 0.02 秒。多次尝试后,100 个请求的平均耗时约为 0.1 秒。
如果我将测试应用程序指向 linux box - 指向在 docker 容器中用 mono 编译并在 mono 下运行的相同代码 - 我看到大多数请求在 0.8 秒到 0.05 秒之间得到响应,但我确实看到(几乎每次尝试时)某些请求需要 15 秒才能得到服务。这在 Mono/linux 上比在 .NET/Windows 上慢很多!
顺便说一句,如果我将并行循环从 100 增加到 500,我发现 Windows 服务可以毫不费力地处理所有请求,但是客户端应用程序(我的测试程序)将因 IO 错误而失败:
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 机器上的“top”或“docker stats”,CPU 使用率从未超过 4%。该服务并没有做任何繁重的工作。
请注意 - 我正在尝试让多个服务相互通信 - 此处显示的服务是“测试用户”服务的精简版本。我发现当服务调用其他服务时(每个服务都在它自己的 docker 容器中运行)——服务之间通信所花费的时间长得令人无法接受。
我在这里只向您展示所有一项服务的原因是,可以证明对一项服务的多次调用似乎明显变慢。
我不确定这是由服务堆栈引起的问题,因为我也有一个自托管的 Nancyfx 服务正在运行,并且该服务也有同样的行为。帮助!
最佳答案
ServiceStack 在其 v4.5.2 Release 中添加了对 .NET Core 的支持这是现在在 Linux 上运行 ServiceStack 的推荐和支持选项。
Are there any known performance issues with a Servicestack self host service (or indeed any http listener) running on linux/mono?
Mono 的 HTTP 堆栈对于繁重的工作负载来说速度慢且不稳定,它适用于小型工作负载,但我们不建议将其用于生产工作负载。我们已经记录了我们发现使用 HyperFastCI + nginx 在 Mono 上运行的最可靠的设置,例如:
在 Linux 上托管 ServiceStack 和 .NET 的 future 是 .NET Core这是快速,稳定和良好的支持。 ServiceStack 对 .NET Core 的支持将在本周晚些时候发布的下一个 v4.5.2 发行说明中公布。
关于c# - linux/mono 上的 HTTP 性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40094337/
#include using namespace std; class C{ private: int value; public: C(){ value = 0;
这个问题已经有答案了: What is the difference between char a[] = ?string?; and char *p = ?string?;? (8 个回答) 已关闭
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 此帖子已于 8 个月
除了调试之外,是否有任何针对 c、c++ 或 c# 的测试工具,其工作原理类似于将独立函数复制粘贴到某个文本框,然后在其他文本框中输入参数? 最佳答案 也许您会考虑单元测试。我推荐你谷歌测试和谷歌模拟
我想在第二台显示器中移动一个窗口 (HWND)。问题是我尝试了很多方法,例如将分辨率加倍或输入负值,但它永远无法将窗口放在我的第二台显示器上。 关于如何在 C/C++/c# 中执行此操作的任何线索 最
我正在寻找 C/C++/C## 中不同类型 DES 的现有实现。我的运行平台是Windows XP/Vista/7。 我正在尝试编写一个 C# 程序,它将使用 DES 算法进行加密和解密。我需要一些实
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
有没有办法强制将另一个 窗口置于顶部? 不是应用程序的窗口,而是另一个已经在系统上运行的窗口。 (Windows, C/C++/C#) 最佳答案 SetWindowPos(that_window_ha
假设您可以在 C/C++ 或 Csharp 之间做出选择,并且您打算在 Windows 和 Linux 服务器上运行同一服务器的多个实例,那么构建套接字服务器应用程序的最明智选择是什么? 最佳答案 如
你们能告诉我它们之间的区别吗? 顺便问一下,有什么叫C++库或C库的吗? 最佳答案 C++ 标准库 和 C 标准库 是 C++ 和 C 标准定义的库,提供给 C++ 和 C 程序使用。那是那些词的共同
下面的测试代码,我将输出信息放在注释中。我使用的是 gcc 4.8.5 和 Centos 7.2。 #include #include class C { public:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的客户将使用名为 annoucement 的结构/类与客户通信。我想我会用 C++ 编写服务器。会有很多不同的类继承annoucement。我的问题是通过网络将这些类发送给客户端 我想也许我应该使用
我在 C# 中有以下函数: public Matrix ConcatDescriptors(IList> descriptors) { int cols = descriptors[0].Co
我有一个项目要编写一个函数来对某些数据执行某些操作。我可以用 C/C++ 编写代码,但我不想与雇主共享该函数的代码。相反,我只想让他有权在他自己的代码中调用该函数。是否可以?我想到了这两种方法 - 在
我使用的是编写糟糕的第 3 方 (C/C++) Api。我从托管代码(C++/CLI)中使用它。有时会出现“访问冲突错误”。这使整个应用程序崩溃。我知道我无法处理这些错误[如果指针访问非法内存位置等,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一些 C 代码,将使用 P/Invoke 从 C# 调用。我正在尝试为这个 C 函数定义一个 C# 等效项。 SomeData* DoSomething(); struct SomeData {
这个问题已经有答案了: Why are these constructs using pre and post-increment undefined behavior? (14 个回答) 已关闭 6
我是一名优秀的程序员,十分优秀!