Angular universal Web App with SSR randomly slow (15s per request)

Remy Villain 16 Reputation points
2021-03-10T15:52:49.07+00:00

Hi,

We are trying to publish an SSR (Server side rendering) Angular App on an Azure Web App running on Node 14.
Everything is working very well, pages are rendered server side nicely but sometimes we have very slow requests but without errors or logs. Just slow requests.
The problem seems to happen only when the SSR render function needs to execute external http requests.

We tried different versions of Angular, different project templates but every time SSR is slow randomly on pages with external http requests.

So pages are rendered in less than 1 second most of the time, and sometimes they are in ~15 seconds
Here a request duration distribution of a test page:

76374-image.png

We also try many plan app service level and many external apis with no effect.
Have you got any tips to configure Azure Web App for Angular Universal in production mode ?

Thanks

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,865 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Shubham Anand 36 Reputation points
    2021-08-09T08:12:21.563+00:00

    Hi Everyone ( @04821556 , @julian ,@Remy Villain ,@Alvin Ho & others who are facing similar issue),

    I have debugged the reported issue with Universal Angular Web App with SSR & making HTTP Requests where you have reported random slowness & after thorough testing, we have identified that the issue is only happening when using Codeless integration of Application insights.

    The reason for same is that for Nodejs SDK for Application Insights (when using SSR in Angular, it is used by default), the value of maxBatchIntervalMs is specified as 15000ms (15 seconds) by default, if no other value is specified as shown below:

    maxBatchIntervalMs: The maximum amount of time to wait to for a payload to reach maxBatchSize (Default 15000 ms or 15 seconds).

    Please refer to following link for more information:

    Monitor Node.js services with Azure Application Insights - Azure Monitor | Microsoft Learn

    So,unless the payload size reaches maxBatchSize the http requests are blocked to be sent to telemetry end point (Azure). This causes intermittent delays.

    Resolution:

    The issue is resolved after specifying a custom value for maxBatchIntervalMs (example 100 ms) as shown in the code sample below:

    https://github.com/shuanand/angularuniversalSSRApplicationInsight/blob/main/server.ts

    To configure the same, firstly disable the Application Insights from the Azure portal of the Webapp after copying Instrumentation key from the App Insights Dashboard by clicking on Overview blade as shown below:

    121584-app-insights.png

    You can then update the instrumentation key for your application in server.ts file as shown below:

    appInsights.setup("PLEASE_ENTER_YOUR_APPLICATION_INSIGHTS_INSTRUMENTATION_KEY_HERE")

    Once, it’s done, there is no random delay even after using the Application Insights as shown below and all the metrics are available in Application Insights Dashboard:

    121538-view-insight-data.png

    Angular universal App using SSR & Http Requests on Linux App Service:

    angularssrdemo.azurewebsites.net

    The code is working on Windows & Container App Service too after making the mentioned changes.

    Thanks to @julian for sharing the sample code to quick do a repro for the issue.

    Please comment, if you are still facing the issue with sample code and I will check the same.

    6 people found this answer helpful.

  2. 04821556 31 Reputation points
    2021-06-29T13:17:57.513+00:00

    We also tried creating our Docker container, but it didn't help

    0 comments No comments

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  4. 88082004 0 Reputation points
    2023-11-04T21:11:20.7933333+00:00

    Hi Everyone, are you aware if do we still need this workaround ?

    0 comments No comments