简体   繁体   English

慢ApplicationSettingsBase

[英]Slow ApplicationSettingsBase

The application settings mechanism (derived from ApplicationSettingsBase) seems to be a real bottleneck when used in multithreading scenarios. 当在多线程场景中使用时,应用程序设置机制(派生自ApplicationSettingsBase)似乎是一个真正的瓶颈。 Especially, when properties are queried often, the concurrency they introduce is slowing down my loops. 特别是,当经常查询属性时,它们引入的并发性会减慢我的循环。 I like to use them anyway to have those nice application configuration option. 无论如何我喜欢使用它们来获得那些不错的应用程序配置选项。 But maybe I need to wrap them into my own cache or so? 但也许我需要将它们包装到我自己的缓存中呢?

Anyone having the same issue? 谁有同样的问题? Am I missing something? 我错过了什么吗? I thought, the ApplicationSettingsBase does cache all settings already? 我想,ApplicationSettingsBase是否已经缓存了所有设置? Why does it seem to lock access from multiple threads at all? 为什么它似乎从多个线程锁定访问? What could be a common workaround? 什么是常见的解决方法?

I'd really suggest wrapping any sort of "get settings" functionality in an object and hiding it behind an interface. 我真的建议在对象中包装任何类型的“获取设置”功能并将其隐藏在接口后面。 We strongly-type this, so we have: 我们强烈打字,所以我们有:

public class Worker 
{
    private readonly ISettings settings;
    public Worker (ISettings settings)
    {
        this.settings = settings;
    }

    public void Work ()
    {
        for (int i = 0; i < settings.MaxWorkerIterations (); i++)
        { ... }
    }
}

public interface ISettings
{
    int MaxWorkerIterations ();
}

public class AppConfigSettings
{
    public int MaxWorkerIterations ()
    {
        return (int) ApplicationSettings["MaxWorkerIterations"];
    }
}

This has the benefit of (mostly) compile-time checking and easy testability. 这具有(主要)编译时检查和易测试性的好处。 You can also override your AppConfigSettings class to be a CachingAppConfigSettings class that does the obvious. 您还可以将AppConfigSettings类重写为CachingAppConfigSettings类,它可以实现显而易见的功能。

I dont see annything strange in having a thread safe settings mechanismm? 在线程安全设置机制中我没有看到奇怪的东西? If it is slowing your hihgly concurrent theads down, you should try to use local variables istead of querying the getsetting fast again. 如果它使你的高速并发theads减慢,你应该尝试使用局部变量而不是再次快速查询getsetting。 I think a redesign of your settings request mechanism would help performmance considerably. 我认为重新设计您的设置请求机制将有助于大大提高性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM