添加 51Degrees 移动检测库后,我的 ASP.NET MVC 3 项目速度慢得像爬行一样。 51Degrees 日志文件定义为<log logFile="~/bin/App_Data/51Log.txt" logLevel="Info" />
in the <fiftyOne>
部分显示设备库会针对每个请求重新加载,为每个请求添加 2-3 秒的延迟:
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
此外,设置<fiftyOne>
<log ... logLevel="Debug">
在 web.config 中启动时抛出以下异常:
Storage scopes cannot be created when _AppStart is executing.
MVC 4 更新
如果我创建一个空白的 ASP.NET MVC 4 应用程序并添加最新的 51Degrees 2.0.3.2 NuGet 包,一切都会完美运行。正如预期的那样,日志反映二进制数据尽管有多个请求,但仅加载一次 (51Degrees.mobi-Lite-2012.01.05.dat)。
谨慎乐观的是,我将所有主要 MVC 3 项目代码复制到新的 ASP.NET MVC 4 项目中,并重新添加了最新的 51Degrees 包,但问题再次出现。一定是与我的某个软件包不兼容,或者是一个奇怪的设置。
日志显示正在为每个请求重新加载库:
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'.
延迟远小于 XML 数据文件(300 毫秒与 3000 毫秒),但仍然造成明显的延迟。
这两个项目的 51Degrees.mobi.config 文件是相同的,在我的 web.config 中,这是我加载的模块:
<modules>
<remove name="Detector"/>
<add name="Detector" type="FiftyOne.Foundation.Mobile.Detection.DetectorModule, FiftyOne.Foundation"/>
</modules>
是什么导致 51Degrees 库在每次请求时重新加载?