Session, Application, and Cache Performance

Source: Internet
Author: User

Session, Application, and Cache Usage will affect the system performance.

1. Session

If the application is not used, disable the session Status of the Page. ASP. NET enables the session status by default. You can set the EnableSessionState attribute in the @ Page command:

Show row number copy code?
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" EnableSessionState="False" %>

The Enable attribute does not affect the Cache or Application object. This attribute applies only to specific Web pages (or user controls that inherit the page ). If the EnableSessionState attribute is set to false, a page exception is thrown when session variables are set or retrieved. When EnableSessionState is true based on the page size, the page loading time is increased because ASP. NET requires the State management overhead of the Session object.

If the ASP. NET page requires access to Session variables but never operates on these variables, you can set EnableSessionState to "ReadOnly" if the page only accesses the Session and does not set the Session ".

You can set the Session status through the Web. config file:

Show row number copy code?
  1. <configuration>    <system.web>        <sessionState mode="Off"/>    </system.web></configuration>

In ASP. NET, the method of storing session status information is flexible. When the situation changes, asp.netuses the model storage state of in-proc, and is also used to execute the same process of asp.net (aspnet_wp.exe.

Method 2: Use a status server to store session status information on an external State server process on a local Web server or on a remote server. The State Fu Rong district is actually a Windows Service of aspnet_state.exe. Windows Services can be used for management on any machine installed with. NET. To change the session Status mode to the status server, you can edit the Web for a specific Web. config file, or in the Machine. in the Config file, set it to the default mode of all Web on the machine.

Show row number copy code?
  1. <configuration>    <system.web>        <sessionState mode="StateServer" stateConnectionString="127.0.0.1:42424"/>    </system.web></configuration>

The status server must start ASP. NET State Service. The server uses port 42424 by default. The port must be opened between the Web server and the status server. You can modify the port value by modifying the registry: HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ services \ aspnet_state \ Parameters \ Port. The status server has performance loss compared to the In-Proc mode. data must be stored and retrieved across processes or remotely connected to the server. NET must be serialized and deserialized, and in ASP. NET Web applications and status services provide cross-process data groups.

Mode 3: SQL Server. This mode stores session status information in an SQL Server database created for status management. The SQL Server Session state mode is the slowest of the three methods, but it is the strongest and will hardly cause Session loss.

Show row number copy code?
  1. <configuration>    <system.web>       <sessionState mode="SQLServer" sqlConnectionString="server=.;uid=sa;pwd="/> 
  2.     </system.web></configuration>

The life cycle of a Session. The life cycle can be configured in the Web. config or Machine. config configuration file, timeout (in minutes ).

Show row number copy code?
  1. <configuration>    <system.web>       <sessionState timeout=”20”/> 
  2.     </system.web></configuration>

The application needs to carefully analyze and speculate on the usability during the lifecycle of the application to optimize the session state, the time required to recreate the value stored in the session state is balanced with the performance gain because the reference is essentially a cached value. If you want to store the value of a custom object (reference type) to the session state, ASP. NET checks its structure when saving the object to the state, uses an algorithm to optimize the bucket to store the object, and ensures that the specified type is within the byte boundary. When this information is restored, ASP. NET needs to create a copy of the object to check its structure, and then execute the same stored procedure in reverse order.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.