[英]Azure Web App and React SSR: Extremely slow loading times on initial load
I'm really intrigued by this, I've set up a Node 12 Azure Web App, with server-side rendering in React.我对此很感兴趣,我设置了一个 Node 12 Azure Web 应用程序,在 React 中进行服务器端渲染。
However, I fail to understand why the initial response time is slow (more than 3 minutes), but after this, the response time falls to about 1/2 seconds.但是,我无法理解为什么初始响应时间很慢(超过 3 分钟),但是在此之后,响应时间下降到大约 1/2 秒。
Why is the initial response so slow?为什么初始响应这么慢? I'm new to Azure and SSR web applications, but is the node server just shutting off from inactivity, and starting up the build again every few minutes?
我是 Azure 和 SSR web 应用程序的新手,但是节点服务器是否只是从不活动状态关闭,每隔几分钟再次启动构建?
Are there any ways to fix this, apart from scaling the web app up?除了放大 web 应用程序之外,还有什么方法可以解决这个问题吗?
The common cause for long application start times is a high number of files in the node_modules.应用程序启动时间长的常见原因是 node_modules 中有大量文件。 The application tries to load most of these files when starting.
应用程序会在启动时尝试加载其中的大部分文件。 By default, on App Service all the files are stored on the.network share (so loading many files can take time).
默认情况下,在 App Service 上,所有文件都存储在 .network 共享上(因此加载许多文件可能需要时间)。
1.If you haven't done this already, you may try to lazy load your node_modules and not load all of the modules at application start. 1.如果您还没有这样做,您可以尝试延迟加载您的node_modules而不是在应用程序启动时加载所有模块。 To Lazy load modules, the call to require('module') should be made when you actually need the module within the function before the first execution of module code.
要延迟加载模块,应在首次执行模块代码之前在 function 内实际需要模块时调用 require('module') 。 See, if this makes any difference.
看,这是否有任何区别。
Kindly check if Always On -Settings/feature is enabled and if it loads as expected.请检查Always On - 设置/功能是否已启用以及是否按预期加载。
If feasible, enable Local cache (firstly test, and then leverage if required)如果可行,启用本地缓存(首先测试,然后在需要时利用)
Local cache -copies the content from the.network share to the local disk on the VM.本地缓存 - 将内容从 .network 共享复制到 VM 上的本地磁盘。 Since the files are local, the load time of node_modules is much faster.
由于文件是本地的,因此node_modules的加载时间要快得多。
Note: Local cache is not supported in function apps or containerized App Service apps, such as in Windows Containers or in App Service on Linux.注意:function 应用或容器化应用服务应用不支持本地缓存,例如 Windows 容器或 Linux 上的应用服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.