Slow ApplicationSettingsBase
The application settings mechanism (derived from ApplicationSettingsBase) seems to be a real bottleneck when used in multithreading scenarios. 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? Why does it seem to lock access from multiple threads at all? What could be a common workaround?
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. I think a redesign of your settings request mechanism would help performmance considerably.
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.
精彩评论