Windows服务中RuntimeHelpers.PrepareMethod的缺点 [英] Disadvantages of RuntimeHelpers.PrepareMethod in a windows service

查看:62
本文介绍了Windows服务中RuntimeHelpers.PrepareMethod的缺点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调查服务器(具有多个服务)启动后不久发生的问题延迟问题.

I am investigating an issue latency issues that happens soon after a server (having multiple services) starts.

我添加了一个简单的方法,该方法可以加载引用的DLL,并对这些DLL中每个程序集中的每种类型中的每种方法的每个方法执行RuntimeHelpers.PrepareMethod,从而有效地将整个代码库(一种特定服务)JIT化.这是使用Parallel.ForEach执行的,只需几秒钟(四核处理器为100%).这样可以将首次调用的延迟问题减少到几乎没有(因为我不是JIT-ing通用方法).它的价格也很低,服务初始化只需几秒钟.

I've added a simple method that loads of referenced DLLs and performs RuntimeHelpers.PrepareMethod on every method in every type in every assembly in those DLLs, effectively JIT-ing the entire codebase (of one specific service). This is performed using Parallel.ForEach and takes just a couple of seconds (with 100% on a quad-core processor). This reduces the latency issues on the first calls to almost nothing (because I am not JIT-ing generic methods). It also comes with a very low price, just a couple of seconds in the initialization of the service.

但是,我的团队负责人声称,这种对服务器的修改不会投入生产,因为它不安全",并且可能带来意想不到的结果,他提到动态加载(和卸载?)DLL.

However my team leader claims that this type of modification to the server will not go in production because it's "not safe" and might bring unexpected results, and he mentioned dynamically loading (and unloading?) DLLs.

我描述的内容确实会带来意想不到的结果,异常等吗?

Is it true that what I have described might bring unexpected results, exceptions, etc?

Windows管理服务的方式是否会影响RuntimeHelpers.PrepareMethod(反之亦然)?

Is the way Windows manages services affects RuntimeHelpers.PrepareMethod (or vice-versa) ?

与在常规Windows应用程序中执行相同操作(对所有方法进行预JIT处理)不同吗?

Is it different then doing the same (pre JIT-ing all methods) in a regular Windows Application?

它是否与DI(我们正在使用IOC)相冲突?

Does it conflict with a DI (we are using IOC) ?

如果我们正在动态加载DLL,它会以任何方式干扰吗?

If we are dynamically loading DLLs, can it interfere in any way?

一般来说,它会带来什么危害?

And generally, what harm can it give?

推荐答案

他几乎肯定是错误的.

调用此函数不会破坏" CLR.​​

Calling this function will not "break" the CLR.

但是,它可能导致JITter提前加载程序集.
如果以后添加AssemblyResolve处理程序,它们将不再有帮助,因为CLR已经尝试加载相关程序集.

However, it can cause the JITter to load assemblies earlier than it otherwise would have.
If you add AssemblyResolve handlers later, they will no longer help, since the CLR will have already tried to load the relevant assemblies.

这篇关于Windows服务中RuntimeHelpers.PrepareMethod的缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆