c# - Overhead with Linq-to-SQL -


We are currently Aspiknet MVC experiencing problems with performance website went written in 4, especially the Link- To-SQL, thus resulting in (with other things) the CPU jumbs up to 100% for every page request where Linq-to-SQL is used.

I am analyzing applications with ANTS Display Professor 8.5 Pro, and I am experiencing the same results in both Dev and production environments. However, the development is far worse in production than the environment.

Through the anti-I think Linq-to-starting the SQL data references and examples of very simple query:

  (var db = New D. DataClasses DataContext (Configuration Manager Connection Connection ["Master"]. ConnectionString) {db.ObjectTrackingEnabled = false; HttpContext.Cache [ "WebPageTemplateCapabilities"] = (in db.Clients X where x.ClientID Select == this.ClientID x.WebPageTemplateCapabilities) .SingleOrDefault (); }  

I lasted 1.5 seconds to run can not figure it out for your life that can actually hit a performance due to a simple query in this code snippet, which That's crazy than executing the same query in SSMS. I am at this point that high CPU utilization can be a result of any database communication of this website.

What am I missing? This is for the record, the first data reference is made immediately and the queries made during the life cycle of the website.

If you are using Linq for SQL and you call the same query multiple times So, I recommend using compiled functions. The above query can be written as follows:

  Private Stable Function & lt; Dataclass dataTyText, string, string & gt; MyCompiledFunction = CompiledQuery.Compile ((DataClassesDataContext pContext, string pClientID) = & gt; (choose where x.ClientID == pClientID the X pContext.Clients x.WebPageTemplateCapabilities) .SingleOrDefault ();  
< p> If you do not specify a return type or client ID, so I assumed that they would string. Note

that function has been compiled for the first time, an overhead above - then It's very fast, we were getting 5 or 6 times faster in our code. If you have been called only once, do not worry.


Comments