[英].NET performance tips for enterprise web applications
For enterprise web apps, every little bit counts. 对于企业Web应用程序,每一点点都很重要。
What performance tips can you share to help programmers program more efficiently? 您可以分享哪些性能提示来帮助程序员更有效地编程?
To start it off: 开始吧:
Use StringBuilders over strings since strings are Mutable (they get re-created every time you modify them). 对字符串使用StringBuilders,因为字符串是可变的(每次修改它们时都会重新创建它们)。
Avoid using Datasets as they are very bloated, use SqlReader instead. 避免使用数据集,因为它们非常臃肿,请改用SqlReader。
The points made in the question are micro-optimisations. 问题中提出的观点是微观优化。 I disagree with the very premise that "every little bit helps" - particularly if it comes at the expense of readability. 我不同意“每一点点都有帮助”的前提 - 特别是如果以牺牲可读性为代价。
You see, if you can read and understand your code really easily, that means you can make architectural changes easily. 您知道,如果您能够轻松阅读和理解您的代码,那意味着您可以轻松地进行体系结构更改。 Those are where the really big wins are, not the micro-optimisation. 那些是真正的大赢家,而不是微优化。 The more you try to tune the heck out of every line of code, the harder it will be refactor the whole design. 你试图调整每行代码的次数越多,就越难以重构整个设计。
So my tips are: 所以我的提示是:
None of this is specific to web-apps, so far. 到目前为止,这些都不是特定于网络应用程序的。 For web apps (and server-side in general): 对于Web应用程序(以及一般的服务器端):
EDIT: I didn't address the database at all. 编辑:我根本没有解决数据库。 Kyle's answer is good on that front. 凯尔在这方面的答案很好。 Make sure your database can scale too, if possible :) 如果可能,请确保您的数据库也可以扩展:)
the biggest gains you're going to see in (almost) any application is tuning your database. 你几乎可以在任何应用程序中看到的最大收益是调整你的数据库。
Coding ... 编码......
Database ... 数据库......
And if all else fails, cache the shit out of it and throw more hardware at the problem! 如果所有其他方法都失败了,请将其中的狗屎缓存出来并为问题投入更多硬件! :) :)
We deal with this every day. 我们每天都在处理这个问题。
We DO cache some datasets that are used A LOT. 我们会缓存一些使用过的数据集。 We have a fairly complex data-layer caching mechanism that works well for us. 我们有一个相当复杂的数据层缓存机制,对我们很有用。
Lazy evaluation for just about everything. 几乎所有事情的懒惰评估。
Page- and partial-caching for user controls 用户控件的页面缓存和部分缓存
We do not use session state at all so we've disabled it altogether. 我们根本不使用会话状态,所以我们完全禁用它。
Configure websites to run as a known- low-prived user. 将网站配置为以已知低端用户身份运行。
Connect to SQL Server as the same low-prived user. 以同一个低级别用户身份连接到SQL Server。 This helps with connection pooling - all connections are essentially the same. 这有助于连接池 - 所有连接基本相同。
NO ad-hoc SQL. 没有ad-hoc SQL。 Stored procs ONLY. 仅存储过程。 Helps with performand AND SQL injection. 帮助执行performand和SQL注入。
string.Concat() instead of string + string + ... or StringBuilder string.Concat()而不是string + string + ...或StringBuilder
Except for manwood nobody mentioned ViewState and it's quite surprising. 除了曼伍德,没有人提到ViewState,这是非常令人惊讶的。 I would vote ViewState Management as the single most important considerations for performance improvment. 我会将ViewState Management视为性能提升的最重要考虑因素。
My list: 我的列表:
Edit: [added 6-8] 编辑:[添加6-8]
Microsoft has published a book called Improving .NET Application Performance and Scalability . Microsoft发布了一本名为“ 提高.NET应用程序性能和可伸缩性”的书 。 This is a must read book. 这是一本必读的书。
Aside from the database another very imporant thing to watch ... 除了数据库,另一个非常重要的事情是看...
page size and number of requests. 页面大小和请求数。 This should go without saying, but ASP.NET is notoriously bad at filling your pages with a bunch of crap output (driving up the size) and creating a million external script files (number of requests). 这应该是不言而喻的,但是ASP.NET充斥着大量的垃圾输出(增加大小)并创建了一百万个外部脚本文件(请求数量),这是非常糟糕的。
examine the log and minimize the amount of HTML being served per request. 检查日志并最小化每个请求所服务的HTML数量。 viewstate and bloated third party controls can ruin your application. viewstate和臃肿的第三方控件可能会破坏您的应用程序。 For example we used for a long time the grid from infragistics. 例如,我们长时间使用了来自infragistics的网格。 very very capable but even in its stripped form it made pages about 60-90k + a lot of java script. 非常有能力,但即使在它的剥离形式,它使页面大约60-90k +很多java脚本。 this severely limited the number of requests we could server, even on an internal gigabit connection. 这严重限制了我们可以服务的请求数量,即使在内部千兆位连接上也是如此。
In my experience, the following make a big difference: 根据我的经验,以下内容产生了很大的不同:
If your web servers are being pounded by huge number of simultaneous requests, and each page requests appear to take longer and longer to service, you may want to consider converting to asynchronous page processing model . 如果您的Web服务器受到大量并发请求的攻击,并且每个页面请求似乎需要更长时间的服务,您可能需要考虑转换为异步页面处理模型 。
Scalable Apps with Asynchronous Programming in ASP.NET ASP.NET中使用异步编程的可扩展应用程序
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.