Performance penalties for .NET app running from shared network folder

天涯浪子 提交于 2021-02-07 18:10:19

问题


Are there any performance penalties running .NET 4.0 app from shared network folder? I found what app starts slower but didn't noticed any slow down while using it, but not sure about it.


回答1:


When running an executable over the network, Windows does not bring the entire application over the network at application startup. This is done to speed startup times (and there's no point is downloading that 700MB embedded AVI resource if you never actually use it).

This means that periodically, as new pages from the executable image are required, Windows will go back to the network to retrieve them.

The method in which this is accomplished is that if your application happens to hit a page of memory that is not present, a standard page fault will trigger, telling Windows it needs to fill that page. If the network happens to be down at that moment, Windows will be unable to satisfy the page-fault. There's no way to recover from this, so Windows throws an EXCEPTION_IN_PAGE_ERROR (0xC0000005).

There are three ways to handle this:

  • do nothing and let the application die. Tell the customer to fix their network
  • trap the error, explaining that the application must be terminated now, and telling the user that their network is to blame
  • set the IMAGE_FILE_NET_RUN_FROM_SWAP PE image option. This will instruct Windows to copy the entire executable over the network at application load time. This will increase network traffic and user wait times (at application launch time), but avoid the error



回答2:


Yes, this is heavily optimized in Windows. Loading a .NET assembly does not in fact involve reading the assembly. Much like native code, the CLR creates a memory-mapped file for the assembly file. A chunk of virtual memory that's as large as the file and whose pages are marked as "not yet loaded".

The JIT compiler then goes about its business reading IL and generating machine code for it. Inevitably, it will try to read a memory page that is still in the "not yet loaded" state and that will generate a low-level processor page fault. Windows traps that fault and will then actually read the file content and load it into RAM. The jitter continues as though nothing happened.

Reading that page will be slower when the assembly is located on a network share. But since the jitter only compiles IL when actually needed to execute the program, that slow-down is hard to notice, it only adds a handful of milliseconds to each page fault. It will be most noticeable when your program starts up, the only real time that a lot of IL needs to be compiled before the program can do something like showing its main window.



来源:https://stackoverflow.com/questions/8310391/performance-penalties-for-net-app-running-from-shared-network-folder

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!