0

I have ASP.NET core 6.0 API project which internally calls other endpoints to get or set data from 3rd party applications.

Currently there is performance test going on , for which application is throwing 504 gateway timeout error.

I have set timeout span to be 10 mins in Program.cs file as below

enter image description here

Application is hosted on Azure app service and we are using profiler to capture the time taken for few endpoints.

One of the endpoints is taking 4 mins which is less than 10 mins timeout given , still we are getting 504 error.

We want to know if this timeout is being overridden at any level.

So is there any way to know and log how much time has been taken before throwing 504 gateway error?

RashmiMs
  • 129
  • 14

1 Answers1

1

You use .net core api project, and you want call third-party applications.

What I can confirm is that your requirements cannot be achieved in an Http Request. Because the default timeout time of the browser is about 4 minutes, different browsers may have different time, but the overall time will not exceed 5 minutes, and the browser will crash.

Blow answer is my test result.

The request timed out. The web server failed to respond within the specified time

enter image description here

enter image description here

I am sure even we get 500 error in broswer, the job still running in backend server. The options.Limits.KeepAliveTimeout = 10 configuration should be used for requests sent by the backend HttpClient, not for requests sent by the browser.

Suggestion

Through the above test results and analysis, I feel that this requirement needs to be implemented in another way.

  1. If there is such a long http request, I recommend creating httpclient and making get and post requests on the backend. The interactive request used by the browser can be directly implemented by calling the controller method. The shorter the time, the better the interactive experience.

  2. Take your needs as an example:

    ① The front-end browser sends a request, submits a task, and returns a jobId after it is submitted, and the Status should be creating. The jobId and Status can be stored in redis or other cache.

    ② After the task is submitted, httpclient makes an asynchronous request and waits for the operation to complete. Assuming that the task is completed after 10 minutes, the jobId can be marked as completed.

    ③ This is just an example, suggested. We can create a key-value pair in the front-end localStorage to store the jobId. When the jobId is not completed, we can send a request every ten seconds to ask the server whether the task is over. If finished, terminate the loop. Clear jobId information in localStorage.


How to design it needs further research. This is just an idea. Because of the limitation of the browser, we encountered the 504 error, and the app service cannot directly obtain the running time before the 504 error. At most, log can be used to record some information, but this will definitely put pressure on the server, and it will not solve the problem.

The common application scenario I encountered is the azure portal. When creating resources in it, some resources take more than half an hour. Through the above design, we have shortened the time spent on a single browser http request to a minimum.

Jason Pan
  • 15,263
  • 1
  • 14
  • 29
  • Thank you for the feedback! We use httpclient to call our 3rd party APIs. Flow is like, Client -> Our App(has its own SQL db) -> 3rd party API( using httpclient to connect), we use in most cases either to update data or get the data to validate the request, Once we get response from 3rd party app, we store something in our Db or we send back the Data coming from 3rd party to client. – RashmiMs May 18 '22 at 06:34
  • I like the idea of storing in cache, that is what we are planning to do for huge reports which take more than 30 minutes, but the problem that we are facing is happening when there is load on application , it does not take 4 minutes (may be in seconds) when created normally – RashmiMs May 18 '22 at 06:36
  • @RashmiMs I wonder if the 504 is returned by the Azure webapp, or is it returned by the 3rd party APIs? – Jason Pan May 18 '22 at 06:40
  • That is what we are working on now, currently we are running queries which hit only our app and not 3rd party to know the same. – RashmiMs May 18 '22 at 06:58