加密的 app.config 文件的性能问题
我正在开发一个应用程序,出于多种原因,我们决定对 app.config 文件进行加密。我们使用 SectionInformation.ProtectSection
和 RsaProtectedConfigurationProvider
来加密所有部分。这部分工作正常,应用程序能够读取加密信息。我对这种方法的问题是关于性能的。我在对我们的应用程序进行负载测试时遇到了一个问题,其中使用加密配置在负载下比使用未加密配置几乎慢 2 倍。那么,当我的应用程序启动时,配置是否未加密并缓存在内存中?或者它实际上每次都会进入磁盘吗?我已经做了很多搜索,但还没有找到这里到底发生了什么的明确答案。感谢您的帮助!
我想补充一点,该应用程序大量使用 connectionString 属性来访问数据库。
i am working on an application where we have decided for a number of reasons that the app.config file should be encrypted. We are using SectionInformation.ProtectSection
with the RsaProtectedConfigurationProvider
to encrypt all of the sections. This part works fine and the application is able to read the encrypted information. My question with this approach is about performance. I have run into an issue load testing our application where using the encrpyted config is almost 2x slower under load than with an unencrypted config. So when my application starts up does the config get unencrypted and cached in memory or not? Or does it actually go to disk everytime? I have done alot of searching and have not found a difinitive answer to what exactly is going on here. Thanks for your help!
I'd like to add that this application uses the connectionString property a great deal to access the DB.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我做了一个快速测试,看起来它已加载到内存中。下面是我运行的代码。在第一个 WriteLine() 之后,我打开配置,手动更改它,并保存配置文件。第二个 WriteLine() 打印出旧值而不是新值,因此我得出的结论是,它在读取一次后不会重新打开文件。
I did a quick test and it looks like it's loaded into memory. Below is the code I ran. After the first WriteLine() I opened the config, manually changed it, and saved the config file. The second WriteLine() printed out the old value and not the new one,so I would conclude that it doesn't open the file back up after it reads it once.
好吧,我找到了我自己问题的答案。事实证明,加密配置对性能的影响与我们解决方案框架代码中的错误有关。基本上,我们尝试实现的代码中留下了一些代码,每次我们访问连接字符串或任何应用程序设置时都会从磁盘打开配置:
我将此代码更改为仅使用
ConfigurationManager.AppSettings[]< /code> 现在一切都运行良好。所以我发现,
ConfigurationManager
在您第一次访问属性时从磁盘读取,并且仅在第一次时解密文件。之后,它只是从内存中解密的部分读取值。Okay, i found the answer to my own question. As it turned out the performance hit i was taking with the encrypted config was related to a bug in our solution's framework code. Basically, there was left over code from something we were attemting to implement which was opening the config from disk everytime we went to access the connection string or any app setting:
I changed this code to just use
ConfigurationManager.AppSettings[]
and everything is working great now. So what I found out was thatConfigurationManager
reads from disk the first time you access a property and also decrypts the file that first time only. After that it's just reading the values from the decrypted sections in memory.您可以尝试以下操作:
http://www.dotnetprofessional.com/blog/post/2008/03/03/Encrypt-sections-of-WebConfig-or-AppConfig.aspx
很难击败这种性能
You can try the following:
http://www.dotnetprofessional.com/blog/post/2008/03/03/Encrypt-sections-of-WebConfig-or-AppConfig.aspx
hard to beat that performance