How to improve the performance of ASP.NET applications

xiaoxiao2021-03-06  50

How to improve the performance of the ASP.NET application has recently developed a professional website and has some tests and analysis of performance after work. Find a lot of places worthy of our attention. There are three layers: Control (UI), DataProvider (data), and components (base) background uses MS SQL Server 2000, and the data layer completes all data operations through the stored procedure. And written an IDATAPROVIDER interface to define all operations. The UI layer is just all functions only by calling iDataProvider. At first we use the method:

SqldataProvider DP = New SqlDataProvider (); dp.data_registeruser (user user);

This will have a problem, when a page contains a large number of controls, there will be a lot of SQLDATAPROVIDER objects, while the SqlDataProvider runtime is very large (reached around 250K). This is already more than 80K large objects in .NET. A large number of creation of large objects will affect performance. Then there is no good way to solve it? In fact, we don't need to create how many objects. As long as there is a SqlDataProvider object to be in memory. This way we think of the System.Web.Caching.cache class in ASP.NET, and we have modified the code. Added a class.

// -------------- buffer SqlDataProvider.sqldataProvide ---- Public class dataprovider {public static idataProvide instance () {cache cache = system.Web.httpContext.current.cache; IF (cache [ "IDataProviderBase"] == null) {String assemblyPath = "SqlDataPrvider.dll"; String className = "SqlDataProvider.SqlDataProvide"; assemblyPath = HttpContext.Current.Server.MapPath (HttpContext.Current.Request.ApplicationPath "/ bin / " assemblyPath); try {cache.Insert (" IDataProvide ", Assembly.LoadFrom (assemblyPath) .GetType (className) .GetConstructor (new Type [0]), new CacheDependency (assemblyPath));} catch (Exception) {HttpContext.current.response.write (" error: could not locate file: " assemblyPath or could not locate class " ClassName " < / CODE> IN file. "); httpContext.current.response.end ();}} Return (iDATAPROVIDE) (" iDataProvide ") (" iDataProvide "). Invoke (null);}} // ------------ Modified code ------ iDataProvide DP = DataProvider.instance (); dp.data_registeruser (use R user); through transformation, system performance is greatly improved. However, there are several places that can be optimized. Such as: the buffer of common data, paging data stored procedures, etc.

转载请注明原文地址:https://www.9cbs.com/read-91117.html

New Post(0)