ASP.NET 性能优化

ASP.NET Core架构革命:从性能优化到架构升级,全面超越传统ASP.NET 摘要: ASP.NET Core重塑了现代Web开发范式,通过跨平台、模块化设计和异步编程解决了传统ASP.NET的局限。核心架构包括中间件管道(按需处理请求)和内置依赖注入(解耦服务管理)。性能优化方面,全面拥抱async/await实现异步非阻塞,结合响应压缩(GZIP/Brotli)和混合缓存策略(内存+Redis),显著提升并发能力与响应速度。实战代码演示了中间件链式调用、服务注入及缓存优化,体现从"黑盒"到透明化架构的升级,为高并发场景提供秒级性能保障。 阅读详情

原文:http://www.codeproject.com/Articles/23306/ASP-NET-Performance-and-Scalability-Secrets 

ASP.NET 2.0 has many secrets, which when revealed can give you big performance and scalability boost. For instance, there are secret bottlenecks in Membership and Profile provider which can be solved easily to make authentication and authorization faster. Furthermore, ASP.NET HTTP pipeline can be tweaked to avoid executing unnecessary code that gets hit on each and every request. Not only that, ASP.NET Worker Process can be pushed to its limit to squeeze out every drop of performance out of it. Page fragment output caching on the browser (not on the server) can save significant amount of download time on repeated visits. On demand UI loading can give your site a fast and smooth feeling. Finally, Content Delivery Networks (CDN) and proper use of HTTP Cache headers can make your website screaming fast when implemented properly. In this article, you will learn these techniques that can give your ASP.NET application a big performance and scalability boost and prepare it to perform well under 10 times to 100 times more traffic.

In this article we will discuss the following techniques:

  • ASP.NET pipeline optimization
  • ASP.NET process configuration optimization
  • Things you must do for ASP.NET before going live
  • Content Delivery Network
  • Caching AJAX calls on browser
  • Making best use of Browser Cache
  • On demand progressive UI loading for fast smooth experience
  • Optimize ASP.NET 2.0 Profile provider
  • How to query ASP.NET 2.0 Membership tables without bringing down the site
  • Prevent Denial of Service (DOS) attack

The above techniques can be implemented on any ASP.NET website, especially those who use ASP.NET 2.0's Membership and Profile provider.

You can learn a lot more about performance and scalability improvement of ASP.NET and ASP.NET AJAX websites from my book - Building a Web 2.0 portal using ASP.NET 3.5.

ASP.NET Pipeline Optimization

There are several ASP.NET default HttpModules which sit in the request pipeline and intercept each and every request. For example, SessionStateModule intercepts each request, parses the session cookie and then loads the proper session in the HttpContext. Not all of these modules are always necessary. For example, if you aren't using Membership and Profile provider, you don't need FormsAuthentication module. If you aren't using Windows Authentication for your users, you don't need WindowsAuthentication. These modules are just sitting in the pipeline, executing some unnecessary code for each and every request.

The default modules are defined in machine.config file (located in the$WINDOWS$\Microsoft.NET\Framework\$VERSION$\CONFIG directory).

<httpModules>
  <add name="OutputCache" type="System.Web.Caching.OutputCacheModule" />
  <add name="Session" type="System.Web.SessionState.SessionStateModule" />
  <add name="WindowsAuthentication" 
        type="System.Web.Security.WindowsAuthenticationModule" />
  <add name="FormsAuthentication" 
        type="System.Web.Security.FormsAuthenticationModule" />
  <add name="PassportAuthentication" 
        type="System.Web.Security.PassportAuthenticationModule" />
  <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule" />
  <add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule" />
  <add name="ErrorHandlerModule" type="System.Web.Mobile.ErrorHandlerModule, 
                             System.Web.Mobile, Version=1.0.5000.0, 
                             Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</httpModules>

You can remove these default modules from your Web application by adding <remove> nodes in your site'sweb.config. For example:

<httpModules>
         <!--<span class="code-comment"> Remove unnecessary Http Modules for faster pipeline --></span>
         <remove name="Session" />
         <remove name="WindowsAuthentication" />
         <remove name="PassportAuthentication" />
         <remove name="AnonymousIdentification" />
         <remove name="UrlAuthorization" />
         <remove name="FileAuthorization" />
</httpModules>

The above configuration is suitable for websites that use database based Forms Authentication and do not need any Session support. So, all these modules can safely be removed.

ASP.NET Process Configuration Optimization

ASP.NET Process Model configuration defines some process level properties like how many number of threads ASP.NET uses, how long it blocks a thread before timing out, how many requests to keep waiting for IO works to complete and so on. The default is in many cases too limiting. Nowadays hardware has become quite cheap and dual core with gigabyte RAM servers have become a very common choice. So, the process model configuration can be tweaked to make ASP.NET process consume more system resources and provide better scalability from each server.

A regular ASP.NET installation will create machine.config with the following configuration:

<system.web>
    <processModel autoConfig="true" />  

You need to tweak this auto configuration and use some specific values for different attributes in order to customize the way ASP.NET worker process works. For example:

<processModel 
   enable="true" 
   timeout="Infinite" 
   idleTimeout="Infinite" 
   shutdownTimeout="00:00:05" 
   requestLimit="Infinite" 
   requestQueueLimit="5000" 
   restartQueueLimit="10" 
   memoryLimit="60" 
   webGarden="false" 
   cpuMask="0xffffffff" 
   userName="machine" 
   password="AutoGenerate" 
   logLevel="Errors" 
   clientConnectedCheck="00:00:05" 
   comAuthenticationLevel="Connect" 
   comImpersonationLevel="Impersonate" 
   responseDeadlockInterval="00:03:00" 
   responseRestartDeadlockInterval="00:03:00" 
   autoConfig="false" 
   maxWorkerThreads="100" 
   maxIoThreads="100" 
   minWorkerThreads="40" 
   minIoThreads="30" 
   serverErrorMessageFile="" 
   pingFrequency="Infinite" 
   pingTimeout="Infinite" 
   asyncOption="20" 
   maxAppDomains="2000" 
/>

Here all the values are default values except for the following ones:

  • maxWorkerThreads - This is default to 20 per process. On a dual core computer, there'll be 40 threads allocated for ASP.NET. This means at a time ASP.NET can process 40 requests in parallel on a dual core server. I have increased it to 100 in order to give ASP.NET more threads per process. If you have an application which is not that CPU intensive and can easily take in more requests per second, then you can increase this value. Especially if your Web application uses a lot of Web service calls or downloads/uploads a lot of data which does not put pressure on the CPU. When ASP.NET runs out of worker threads, it stops processing more requests that come in. Requests get into a queue and keeps waiting until a worker thread is freed. This generally happens when site starts receiving much more hits than you originally planned. In that case, if you have CPU to spare, increase the worker threads count per process.
  • maxIOThreads - This is default to 20 per process. On a dual core computer, there'll be 40 threads allocated for ASP.NET for I/O operations. This means at a time ASP.NET can process 40 I/O requests in parallel on a dual core server. I/O requests can be file read/write, database operations, web service calls, HTTP requests generated from within the Web application and so on. So, you can set this to 100 if your server has enough system resource to do more of these I/O requests. Especially when your Web application downloads/uploads data, calls many external webservices in parallel.
  • minWorkerThreads - When a number of free ASP.NET worker threads fall below this number, ASP.NET starts putting incoming requests into a queue. So, you can set this value to a low number in order to increase the number of concurrent requests. However, do not set this to a very low number because Web application code might need to do some background processing and parallel processing for which it will need some free worker threads.
  • minIOThreads - Same as minWorkerThreads but this is for the I/O threads. However, you can set this to a lower value than minWorkerThreads because there's no issue of parallel processing in case of I/O threads.
  • memoryLimit - Specifies the maximum allowed memory size, as a percentage of total system memory, that the worker process can consume before ASP.NET launches a new process and reassigns existing requests. If you have only your Web application running in a dedicated box and there's no other process that needs RAM, you can set a high value like 80. However, if you have a leaky application that continuously leaks memory, then it's better to set it to a lower value so that the leaky process is recycled pretty soon before it becomes a memory hog and thus keep your site healthy. Especially when you are using COM components and leaking memory. However, this is a temporary solution, you of course need to fix the leak.

Besides the processModel, there's another very important section with the system.net where you can specify the maximum number of outbound requests that can be made to a single IP.

<system.net>
  <connectionManagement>
    <add address="*" maxconnection="100" />
  </connectionManagement>
</system.net>

Default is 2, which is just too low. This means you cannot make more than 2 simultaneous connections to an IP from your Web application. Sites that fetch external content a lot suffer from congestion due to the default setting. Here I have set it to 100. If your Web applications make a lot of calls to a specific server, you can consider setting an even higher value.

You can learn more about these configuration settings from "Improving ASP.NET Performance".

Things You Must Do for ASP.NET Before Going Live

You should do some tweaking on your web.config if you are using ASP.NET 2.0 Membership Provider before you go live on your production server:

  • Add applicationname attribute in Profile Provider. If you do not add a specific name here, Profile provider will use a GUID. So, on your local machine you will have one GUID and on the production server you will have another GUID. If you copy your local DB to the production server, you won't be able to reuse the records available in your local DB and ASP.NET will create a new application on production. Here's where you need to add it:

    <profile enabled="true"> 
    <providers> 
    <clear /> 
    <add name="..." type="System.Web.Profile.SqlProfileProvider" 
    connectionStringName="..." applicationName="YourApplicationName" 
    description="..." /> 
    </providers> 
  • Profile provider will automatically save the profile whenever a page request completes. So, this might result in an unnecessary UPDATE on your DB which has significant performance penalty. So, turn off automatic save and do it explicitly from your code using Profile.Save(); 

    <profile enabled="true" automaticSaveEnabled="false" >
  • Role Manager always queries the database in order to get the user roles. This has significant performance penalty. You can avoid this by letting the Role Manager cache role information on a cookie. But this will work for users who do not have a lot of roles assigned to them which exceeds the 2 KB limit of Cookie. But it's not a common scenario. So, you can safely store role info on a cookie and save one DB roundtrip on every request to*.aspx and *.asmx. 

    <roleManager enabled="true" cacheRolesInCookie="true" >

The above three settings are must haves for high volume websites.


asp.net EXCEL.exe进程结束 asp.net 上传或者下载excel表格时,EXCEL.exe进程结束问题 立即下载

相关推荐

Asp.Net在IIS下Excel文件权限不足解决方法

aspNet在IIS下操作Excel文件权限不足的解决方法

使用cmd命令在IIS上部署Asp.Net core网站

    由于是外包项目需要实施人员去现场部署IIS网站,所以就想做个批处理文件去一键执行安装部署IIS网站。于是就有了这篇文章。废话少说先上代码。 echo Please use administrator privileges to run. ::请使用管理员权限执行 cd /d %~dp0 ::站点名称 set name="test" ::绑定域名和端口号 set domain=*:500...

笔记本~ 4313

ASP.Net Web应用程序与EXCEL交互时遇到的权限问题

ASP.Net Web应用程序与EXCEL交互时遇到的权限问题解决方案

4种方法解决IIS 不能运行asp.net

<!-- --> 一般IIS运行不了ASP.NET,试一下下面四种方法,99%有效:       1.  .NET 安装的顺序应该是先装IIS,再装VS.NET,如果次序反了,或者IIS重装了,就需要使用aspnet_regiis.exe -i来重新安装IIS Mapping(主要用于aspx, asmx等文件的Extention的匹配)。到所有程序-〉Microsoft Visua

开心每天,水滴石穿。 1440

嵌入式常用通信协议 #概述

嵌入式通信协议

AFK3060的博客 2114

Windows系统下AutoDock 4.2.6安装避坑指南(附MGLTools配置技巧)

本文详细介绍了在Windows系统下安装和配置AutoDock 4.2.6的完整流程,特别针对分子对接研究中常见的软件安装问题提供了解决方案。从环境准备、分步安装到常见报错处理,涵盖MGLTools配置技巧、工作目录设置和环境变量优化,帮助科研人员快速搭建稳定的分子对接平台。

weixin_29234239的博客 311

ASP.NET比较常用的26个性能优化技巧

1. 数据库访问性能优化 数据库的连接和关闭访问数据库资源需要创建连接、打开连接和关闭连接几个操作。这些过程需要多次与数据库交换信息以通过身份验证,比较耗费服务器资源。ASP.NET中提供了连接池(Connection Pool)改善打开和关闭数据库对性能的影响。系统将用户的数据库连接放在连接池中,需要时取出,关闭时收回连接,等待下一次的连接请求。连接池的大小是有限的,如果在连接池达到最大限度后仍...

li123128的博客 1919

保姆级教程:用Ubuntu 22.04搭建RustDesk中继服务器(含Cloudflare避坑指南)

本教程详细指导如何在Ubuntu 22.04上搭建RustDesk中继服务器,解决跨国远程协作的延迟问题。涵盖环境配置、Rust编译优化、服务部署及Cloudflare代理设置等关键步骤,帮助用户实现高性能的私有中继服务。

weixin_29002209的博客 525

ASP.NET性能优化整理

正好最近在做.net性能方面的资料查询,现作一个整理主要参考:MSDN网站资料 1.1         ASP.NET性能优化对于asp.net的性能优化。1.1.1   工具软件性能计数器运行à输入perfmon,可以打开系统自带的性能监视器,可以添加性能计数器。性能对象性能计数器ASP.NETApplication

shllove的专栏 1105

KNX智能家居工程设计应用

KNX,是一个起源于欧洲的总线标准,主要应用于家居和楼宇中,对末端电气设备进行总线式的控制,比如照明、空调、地暖、电动窗帘和遮阳设备等等。根据2017年英国著名咨询公司BSRIA的数据报告显示,在中国的智能家居和灯光控制市场,KNX产品的市场份额为各类产品中排名第一,占据了42%的市场份额,远远领先于其他的标准协议。设备中一个继电器表示一路输出,某些功能可能需要用到多个输出,比如1个窗帘AC输出需要占用两路继电器输出,一个继电器用于控制正转,一个用于控制反转,而普通开关输出则需要占用一路继电器输出即可。

hhhh5555666的博客 934

激光雷达-IMU标定工具lidar_imu_calib保姆级教程(VLP-16实测)

本文提供激光雷达与IMU联合标定的详细实战教程,重点解析lidar_imu_calib工具在VLP-16上的应用。从环境部署、数据采集技巧到参数配置与结果验证,手把手指导完成标定全流程,并详解如何在LIO-SAM等SLAM系统中应用标定结果,确保传感器融合精度。

food6的博客 475

ASP.NET性能优化

ASP.NET性能优化[日期:2005-04-12]来源:csdn  作者:[字体:大 中 小] 衡量Web性能的方法 l         衡量web服务器性能的唯一方式是对服务器进行压力测试(stress testing) 1.        自动压力测试工具是衡量的唯一方式 2.        浏览器的点击刷新并不能作为痕量手段……   l         收集多个典型应用场景方案: 1.  

网际浪子专栏(曾用名littlehb) 1986

手把手教学,Python 游戏编程之实现飞机大战(含源代码)

我想大家都是有玩过类似飞机大战的射击类游戏,也享受目标被消除通过后带来的愉悦感。那么如果用Python来实现飞机大战游戏?下面就跟大家一起用Python来做一个小游戏,不仅可以从中感受到乐趣,还可以提升自己的能力。

veratata的博客 1万+

Asp.Net性能优化.

(一).选择会话状态存储方式    在Webconfig文件配置:             sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"       cookieless="false" timeout="20"/>           Asp.net有三种方式存储会话状态信息:     1. 存储在进程中:

★(ChengKing)【夜战鹰】【产品级性能调优与故障诊断分析】★ 1万+

DPABISurf使用教材

严老师的官方教程:http://rfmri.org/Course DPABISurf版本:dpabi50docker.tar.gz MATLAB版本:2018b 一、数据准备 (1)如果是数据的DICOM格式,整理成以下格式(注意文件夹的命名方式): 如果觉得不是很清楚,可以在官网下载Demo数据(http://rfmri.org/DemoData),参照里面的文件格式进行整理即可。 (2)如果数据是nii格式,整理成以下格式: 这里没有使用官网的demo数据进行学习,而是..

从事脑科学核磁共振方法学研究,在Nature communications等权威期刊发表研究论文,熟练掌握磁共振处理方法和统计学方法,欢迎大家和我交流。 8514

A算法的蒙特卡洛树搜索

A*算法的蒙特卡洛树搜索 作者:禅与计算机程序设计艺术 1. 背景介绍 在人工智能和游戏开发领域,搜索算法是一个非常重要的研究方向。其中A算法和蒙特卡洛树搜索是两种广泛应用的经典算法。A算法是一种启发式搜索算法,通过评估各个节点到目标节点的启发式代价来引导搜索方向,在

AI天才研究院 1730

Asp.net 网站性能优化

ASP.NET性能优化小结:https://www.cnblogs.com/wwy224y/p/3788519.html ASP.NET性能优化之让浏览器缓存动态网页:https://www.cnblogs.com/luminji/archive/2011/09/13/2172737.html 不修改代码就能优化ASP.NET网站性能的一些方法:https://www.cnblogs.com/...

wangyihero8的专栏 353

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Asp.net网站速度性能优化总结

<br />1. 使用存储过程(如果在程序里用exec 存储过程参数,这样执行似乎并没有快多少)。<br />    在数据库里是预编译的,也不需要在字符串传输上花费大量时间。 防sql注入攻击。<br />  2. 尽量优化数据库语句,使逻辑尽量简单<br />        a) 还有就是在使用函数时,charindex >like > padindex  效率依次递减。<br />    b) 查询字段是否包含在以,分隔的字段串时,最好不要用in  速度非常慢。<br />    还有好多,可以总结的

dongtianbuluo 892

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

ASP.NET程序性能优化的七个方面

 一、数据库操作1、用完马上关闭数据库连接   访问数据库资源需要创建连接、打开连接和关闭连接几个操作。这些过程需要多次与数据库交换信息以通过身份验证,比较耗费服务器资源。ASP.NET中提供了连接池(Connection Pool)改善打开和关闭数据库对性能的影响。系统将用户的数据库连接放在连接池中,需要时取出,关闭时收回连接,等待下一次的连接请求。   连接池的大小是有限的

孤夜寒心泪学习随笔 1374

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

ASP.NET性能优化小结

ASP.NET: 一、返回多个数据集   检查你的访问数据库的代码,看是否存在着要返回多次的请求。每次往返降低了你的应用程序的每秒能够响应请求的次数。通过在单个数据库请求中返回多个结果集,可以减少与数据库通信的时间,使你的系统具有扩展性,也可以减少数据库服务器响应请求的工作量。   如果用动态的SQL语句来返回多个数据集,那用存储过程来替代动态的SQL语句会更好些。是否把

乘风破浪 548

ASP.NET夜话之二十一asp.net网站的性能优化

说明,本篇是《ASP.NET夜话》第21章草稿,因为写作时间是2009年12月左右,当时还没有出现ASP.NET4.0正式版和VS2010正式版,在它们出现之后有些地方略有些小变化。在本篇讲得是从代码和配置上提高性能,没有讲述如何使用集群、负载均衡等方法来提高性能,因为这超出了ASP.NET范围之外。在这里发表这篇文章主要是周公最近要讲讲利用工具来优化数据和代码,这个只是作为引子。本篇主要讲述在ASP.NET中如何提高程序性能。提高程序性能的方法主要从编码和数据操作及优化配置三方面,本章要讲述的知识点有:程

周公(周金桥)的专栏 1万+

asp.net常用性能优化方法

对于网站开发人员来说,在编写ASP.NET应用程序时注意性能问题,养成良好的习惯,提高应用程序性能,至少可以推迟必需的硬件升级,降低网站的成本。

a376590153的专栏 338

Asp.net程序性能优化的七个方面

一、数据库操作1、用完马上关闭数据库连接  访问数据库资源需要创建连接、打开连接和关闭连接几个操作。这些过程需要多次与数据库交换信息以通过身份验证,比较耗费服务器资源。ASP.NET中提供了连接池(Connection Pool)改善打开和关闭数据库对性能的影响。系统将用户的数据库连接放在连接池中,需要时取出,关闭时收回连接,等待下一次的连接请求。   连接池的大小是有限的,如果在

736

ASP.NET 应用程序性能优化

导读:   1 前言   性能优化的主要目标是提高“并发用户数量”,“吞吐量”,“可靠性”这样几个指标。   本质上说,性能优化的工作应该是多方面的,要做到“点面结合、由表及里”。比如:从代价的角度来考虑,应尽量做到改动量小,易实施;从用户角度看,应做到快速响应或快速提示;从软件结构的角度看,又要兼顾到系统结构的合理性和可扩展性。由此不难发现,在尝试一些改进方法时往往很难做到面面俱到。   举一个

软件开发资料汇总 399

ASP.NET26个性能优化方法

1.数据库访问性能优化   (1)数据库的连接和关闭  访问数据库资源需要创建连接、打开连接和关闭连接几个操作。这些过程需要多次与数据库交换信息以通过身份验证,比较耗费服务器资源。 ASP.NET中提供了连接池(Connection Pool)改善打开和关闭数据库对性能的影响。系统将用户的数据库连接放在连接池中,需要时取出,关闭时收回连接,等待下一次的连接请求。连接池的大小是有限...

weixin_34082789的博客 469

[ASP.NET] ASP.NET性能优化

  ASP.NET性能优化 1. 数据库访问性能优化   数据库的连接和关闭   访问数据库资源需要创建连接、打开连接和关闭连接几个操作。这些过程需要多次与数据库交换信息以通过身份验证,比较耗费服务器资源。ASP.NET中提供了连接池(ConnectionPool)改善打开和关闭数据库对性能的影响。系统将用户的数据库连接放在连接池中,需要时取出,关

火星人的充电房 478
上一篇: 让Windows Server 2008 + IIS 7+ ASP.NET 支持10万并发请求
ArvinStudy
博客等级 码龄15年 83粉丝 193原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值