Slow ApplicationSettingsBase

The application settings mechanism (derived from ApplicationSettingsBase) seems like a real bottleneck when used in multithreading scenarios. Especially when properties are requested frequently, the concurrency that they enter slows my cycles. I like to use them anyway to have such a good app configuration. But maybe I need to wrap them in my cache or so?

Does anyone have the same problem? Am I missing something? I thought ApplicationSettingsBase already caches all settings already? Why does it seem to block access from multiple threads? What could be a common workaround?

+4
source share
2 answers

I don’t see anything strange in that you have a secure thread mechanism. If it slows down your matching matches, you should try using istead local variables to retry getetting fast. I think that redesigning your settings request mechanism will greatly improve performance.

+2
source

I really suggest wrapping any β€œget settings” function in the object and hiding it behind the interface. We are gaining this much, 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 advantage of (mostly) compile time checking and ease of testing. You can also override the AppConfigSettings class as the CachingAppConfigSettings class, which makes it obvious.

+2
source

Source: https://habr.com/ru/post/1346069/


All Articles