30

做梦也没有想到:Windows 上的 .NET Core 表现更糟糕团队

 5 years ago
source link: https://www.cnblogs.com/cmt/p/11351367.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

做梦也没有想到:Windows 上的 .NET Core 版博客系统表现更糟糕

昨天晚上 18:15 左右我们发布了跑在 Windows 上 .NET Core 博客系统,本想与 .NET Framework 版进行同“窗”的较量,结果刚发布上线就发现 CPU 占用异常高,发布不到1小时就下线了,根本不是一个级别的较量,或者说 .NET Core 连较量的资格都没有,刚上台就趴下了。

如果与 Linux 上的 .NET Core 博客系统(docker swarm 与 docker-compose 部署方式)相比,也是不是一个级别的较量,部署在 Linux 上时是访问高峰撑不住,而部署在 Windows 上连访问低峰都撑不住。

在昨天发布失败后,我们怀疑 CPU 异常高可能是因为 memcached 客户端 EnyimMemcachedCore 使用异步方法时的并发性能问题,于是我们把异步改为同步。

今天我们在验证是否是 EnyimMemcachedCore 的并发性能问题时,我们采用了新的方法,接入部分流量,让单台服务器的 QPS 达到一定值,结果发现了另外一个做梦也没有想到的问题。

35695-20190814135021041-1634527956.png

在 QPS 不高时,跑在 Windows 上的 .NET Core 博客站点表现非常出色,响应速度飞快;但是当 QPS 高于一定值(我们测试时接入的流量让 QPS 在 300-500 左右),.NET Core 博客站点像变了个人似的,大量请求响应速度变慢,而且随着时间推移越来越慢(一种泄漏现象),先是很多请求响应时间5秒左右(我们是从5秒开始监控的),然后是10秒左右,然后是15秒左右。。。然后日志中出现大量下面的错误

2019-08-14 13:13:16.290 [Error] Failed executing DbCommand ("30,022"ms)
System.Data.SqlClient.SqlException (0x80131904): Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
 ---> System.ComponentModel.Win32Exception (258): The wait operation timed out.
   at System.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__126_0(Task`1 result)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)

EF Core 执行的很多 SQL 查询超时(超过30秒),而 EF Core 生成的这些 SQL 语句没有问题,我们都 review 过。

查看数据库服务库的监控,让人大吃一惊,就这点 QPS ,仅仅因为 .NET Core 在 Windows  上跑竟然造成数据库服务器 CPU 100% 。

35695-20190814140224764-1176510010.png

而只要将 .NET Core 博客站点一下线,数据库服务器 CPU 就立马恢复正常,问题非常奇怪。

今天微软也发布了 .NET Core 3.0 Preview 8 ,我们将 System.Data.SqlClient 升级到 4.7.0-preview8.19405.3 也是同样的问题。

我们的数据库服务器用的是阿里云 RDS SQL Server 2008 R2 ,EF Core 用的是 3.0.0-preview5.19227.1 ,由于 EF Core 3.0 从 Preview 6 开始不支持 UseRowNumberForPaging ,所以暂时无法升级到 EF Core 3.0 Preview 8 ,不知道最新版的 EF Core 是否也有这个问题,但我们怀疑应该是 System.Data.SqlClient 的问题,至少是 System.Data.SqlClient 对 Windows 的支持问题,或者是对 SQL Server 2008 R2 的支持问题。

.NET Core 升级之路又遇新障碍。

接下来,我们会进一步排查这 2 个 CPU 高的问题(web服务器与数据库服务器)。

EF Core 与 SqlClient 相关问题链接:

Powered by .NET Core 系列博文:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK