简体   繁体   English

为什么在向不同的 ASP.NET Core 端点发出大约 20 个请求后,Angular 应用程序的 http 请求会挂起?

[英]Why Angular app http requests hang after about 20 requests to different ASP.NET Core endpoints are made?

What is it它是什么

  1. Angular front-end app served via nginx on the server or cordova on android通过服务器上的 nginx 或 Android 上的cordova 提供的Angular 前端应用程序
  2. ASP.NET Core back-end, which connects to MySQL database via Pomelo connector. ASP.NET Core 后端,通过 Pomelo 连接器连接到 MySQL 数据库。 On production back-end app is served through nginx reverse proxy.在生产后端应用程序通过 nginx 反向代理提供服务。

Problem问题

Requests sent from the Angular app to api take long time (a minute or more) or completely timeout after around 20-50 requests on production (on my local dev environment with IIS server this may happen a couple times a day, sometimes doesn't happen at all for several days).从 Angular 应用程序发送到 api 的请求需要很长时间(一分钟或更长时间),或者在大约 20-50 个生产请求后完全超时(在我的本地开发环境中使用 IIS 服务器,这可能每天发生几次,有时不会发生好几天)。

Maybe this can give someone a clue.也许这可以给某人一个线索。 I thought that the problem is with EF queries since I retrieve an entity with its children entities (picture, comments, likes, other business-related entities).我认为问题出在 EF 查询上,因为我检索了一个实体及其子实体(图片、评论、喜欢、其他与业务相关的实体)。 But when I close angular app and open again - requests again work fine for the next 20-50 of them.但是当我关闭 angular 应用程序并再次打开时 - 请求对于接下来的 20-50 个请求再次正常工作。

I also assume that this may be because of DbContext issue, which I was told about by one developer.我还假设这可能是因为 DbContext 问题,一位开发人员告诉我。

Where it happens发生的地方

Both on the dev and prod environment.在开发和生产环境中。 However, on production it occurs sooner.然而,在生产中它发生得更快。 The production server has 1GB RAM and relatively slow CPU ($5 Digital Ocean droplet).生产服务器有 1GB RAM 和相对较慢的 CPU($5 Digital Ocean droplet)。

What I tried我试过的

  1. Rewritten EF queries according to the best practices described here根据此处描述的最佳实践重写 EF 查询

Filtered back-end out I realized that the bottleneck could be in my RxJs extensions in the Angular app.过滤掉后端后,我意识到瓶颈可能出在 Angular 应用程序中的 RxJs 扩展中。 I checked them and it turned out that notifications polling observable is created every time I navigate to a new route.我检查了它们,结果发现每次导航到新路线时都会创建轮询可观察的通知。 After 20-50 navigation events there are 20-50 polling requests which block everything.在 20-50 个导航事件之后,有 20-50 个轮询请求会阻止所有内容。 Polling mechanism re-write fixed the issue.轮询机制重写修复了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM