Huge delay on first browser-request to Mono XSP ho

2019-04-09 11:24发布

问题:

We are using the Mono (2.10) XSP4 webserver to host an ASP.Net MVC3 web-application running on an open-embedded Linux (ARM). When starting XSP4 it takes some seconds until it is ready and accepts requests. No problem with that so far.

But when the first request from a browser / website-visitor is made XSP4 uses all CPU it can get for about 55 seconds until the webpage is (successfully) shown in the webbrowser. This happens after each start/restart of XSP.

My first thought was that this is the just-in-time compiling of the entire web-application. So I built a deployment package that only contains the the binaries, .css, .js and the views (.cshtml). It worked but still had this huge delay.

Then I tried to pre-compile that web-application using Visual Studio (as stated in some Mono release notes). Again the website worked well but the huge delay was still present.

Some questions that are actually in my mind:

  1. Does anybody know what the XSP webserver is doing when the first browser-request is coming in? Is this the just-in-time compilation even if its a pre-compiled webapplication?
  2. Why is it doing it after each start again?
  3. Can the huge delay be reduced generally somehow?
  4. Can the huge delay be reduced so it is only done on the very first browser request after a webapplication update (cached between subsequent runs of XSP)?

Any help/ideas would be great.

Update: In the meanwhile I found that the delay is caused by the Mono / ASP.Net compiler dcms building and compiling the MVC3 razor views into /tmp/root-aspnet.../ which is mapped to memory and therefore is not persistent. I am now looking for a way to control where XSP4 / Mono.WebServer / Mono-Asp.Net stores these compiled files. If anybody is familiar with this let me know ;-)

回答1:

This might be native compilation overhead (which is separate from what pre-compiling does). You could check if AOTing the system libraries give you a speedup:

mono --aot /usr/lib/mono/1.0/mscorlib.dll
for i in /usr/lib/mono/gac/*/*/*.dll; do mono --aot $i; done


回答2:

To prevent the raspberry to compile your website every time XSP4 is starting, you must precompile your website using aspnet_compiler.exe and is located in the %WINDIR%\Microsoft.NET\Framework\v4.0.30319 folder.

Here is an example:

aspnet_compiler.exe -p "d:\original website" -v / -c "d:\compiled website"

Once your website is compiled, upload it to your raspberry and XSP/mono will use the compiled version of your site. Your first request will be much faster.

Here is few reference links:

Precompiling Your Website (C#)

ASP.NET Compilation Tool (Aspnet_compiler.exe)