0

Update 2019-04-24

Problem TL;DR one controller call was causing the next few calls to have a ~15s delay before they even reached the controllers.

I've narrowed the cause to a large file write in the request that causes further delay File.WriteAllText(htmlFilePath, reportHTML);

Originial post

The Problem

I have a long running controller request for generating a report. After the report in generated, additional http requests are made to fetch resultant images.

However, the http calls for the images take about 15s between the ajax call in the browser and when the controller action is invoked. After that, the method runs speedily.

Evidence so far

Previously, we used WCF to run the report generation on a separate machine and there was no such delay. I've tried running both the report generation and image retrieval methods as async calls on their own threads (but on the same machine). However, that still has the delay.

The delay also only happens on the first image request after generating the report. Afterwards, there is no delay.

There is also no session state and disabling session state has no effect

The Ask

Does anyone know what might cause this delay? How can I get better insights into blocks in ASP.NET code or IIS processes?

Other details:

Using CoreHtmlToImage for report generation and azure storage emulator for image storage. ASP.NET MVC is version 5.2.3 (not core)

Community
  • 1
  • 1
farlee2121
  • 2,959
  • 4
  • 29
  • 41
  • The amount of data that you are sending through your ajax request.. One problem could be, you are sending like 100 fields along with your POST request, is that the case? – Bruno Apr 15 '19 at 20:13
  • @Bruno Fetching the images only passes an id via GET. The images are not called until after the report generation is already complete and images saved – farlee2121 Apr 15 '19 at 20:34

1 Answers1

0

Turns out that writing to the website's directory causes the webserver to restart the site

Source: Creating temporary files in wwroot folder ASP.Net MVC3

So if you write files using the assembly working directory like

var uriAssemblyPath = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
var assemblyPath = new Uri(uriAssemblyPath).LocalPath;
var baseDirectory = System.IO.Path.GetDirectoryName(assemblyPath);

You'll run into this issue.

If you need a consistent directory outside the webroot, you can use the designated temp directory

Path.GetTempPath()

Source: Where can I write a temp file from ASP.NET?

farlee2121
  • 2,959
  • 4
  • 29
  • 41