Search code examples
asp.net-mvc-3mobiledetectionasp.net-mvc-451degrees

51Degrees reloading on each request slows ASP.NET MVC to a crawl


My ASP.NET MVC 3 project slows to a crawl after adding the 51Degrees mobile detection library. The 51Degrees log file defined by <log logFile="~/bin/App_Data/51Log.txt" logLevel="Info" /> in the <fiftyOne> section reveals that the device library is reloaded for each request, adding a 2-3 seconds delay for each request:

2011-10-22T14:17:34.9863774Z - 8436 - Info - Loaded 14691 devices using 11640 strings in 1882ms
2011-10-22T14:17:50.8442844Z - 8436 - Info - Loaded 14691 devices using 11640 strings in 1820ms
2011-10-22T14:17:57.2756523Z - 8436 - Info - Loaded 14691 devices using 11640 strings in 1928ms
2011-10-22T14:18:01.0488681Z - 8436 - Info - Loaded 14691 devices using 11640 strings in 1886ms
2011-10-22T14:18:04.6790757Z - 8436 - Info - Loaded 14691 devices using 11640 strings in 1862ms

Furthermore, setting <fiftyOne> <log ... logLevel="Debug"> in web.config throws the following exception on start:

Storage scopes cannot be created when _AppStart is executing.

MVC 4 Update

Everything works perfectly if I create a blank ASP.NET MVC 4 application and add the latest 51Degrees 2.0.3.2 NuGet package. As expected, the log reflects that the binary data as only being loaded once despite multiple requests (51Degrees.mobi-Lite-2012.01.05.dat).

Carefully optimistic, I copied all my main MVC 3 project code over to a new ASP.NET MVC 4 project and re-added the latest 51Degrees package, but the problem recurs. Must be an incompatibility with one of my packages, or a weird setting.

The log shows that the library is being reloaded for each request:

2012-01-18T11:50:02.5026920Z - 11928 - Info - Creating provider from binary data file '~\App_Data\51Degrees.mobi-Lite-2012.01.05.dat'.
2012-01-18T11:50:02.8137098Z - 11928 - Info - Created provider from binary data file '~\App_Data\51Degrees.mobi-Lite-2012.01.05.dat'.
2012-01-18T11:50:07.7419917Z - 11928 - Info - Creating provider from binary data file '~\App_Data\51Degrees.mobi-Lite-2012.01.05.dat'.
2012-01-18T11:50:08.0170074Z - 11928 - Info - Created provider from binary data file '~\App_Data\51Degrees.mobi-Lite-2012.01.05.dat'.
2012-01-18T11:50:10.4191448Z - 11928 - Info - Creating provider from binary data file '~\App_Data\51Degrees.mobi-Lite-2012.01.05.dat'.
2012-01-18T11:50:10.7251623Z - 11928 - Info - Created provider from binary data file '~\App_Data\51Degrees.mobi-Lite-2012.01.05.dat'.

The delay is much less than the XML data file (300ms vs 3000ms), but it's still causing a noticeable delay.

The two projects' 51Degrees.mobi.config files are identical and in my web.config, this is the module I have loaded:

<modules>
    <remove name="Detector"/>
    <add name="Detector" type="FiftyOne.Foundation.Mobile.Detection.DetectorModule, FiftyOne.Foundation"/>
</modules>

What could be causing the 51Degrees library to reload on each request?


Solution

  • This is happening because the log file is placed in the bin folder. Whenever anything changes in the bin folder the worker process will restart. Move the log file to the ~/App_Data folder and you'll find the problem will be resolved. Thank you for using 51Degrees.mobi.