.net性能测试和优化2 Profiling和提高的一些参考

简介: Application Profiling Using profiling tools to look for potential bottlenecks during development can significantly reduce the number of problems that show up later.

Application Profiling

Using profiling tools to look for potential bottlenecks during development can significantly reduce the number of problems that show up later. With the right tools and training, this can become a regular part of the development process without adding too much overhead.

Profilers retrieve performance and memory information from .NET applications in one of three ways:

• Sample based

The application function call stack is periodically recorded to give a low overhead, but equally low resolution analysis.

• Events based

The Common Language Runtime can be configured to send notifications to specific profiler DLLs. Key information on function execution, CPU, memory, and garbage collection can be collected using this mechanism.

• Instrumentation

Instrumentation code that measures the application is added to it at runtime, which can give very detailed and accurate results, but also comes with a high overhead.

http://blogs.msdn.com/b/tvoellm/archive/2007/08/02/what-is-the-difference-between-sample-and-instrumentation-based-profilers.aspx

When to use sample vs instrumenation based profilers:

Sample based - Good for CPU bound problems,

Instrumentation based profilers - Good for I/O, idle wait, memory, ...

Performance profiling

Performance profiling is all about discovering which parts of your application consume a disproportionate amount of time or system resource.

Memory profiling

Checking that an application doesn't have memory leaks, and that it uses memory efficiently, together with fixing any issues found, will improve its overall stability and performance.

工具

CLRProfier

Microsoft Visual Studio 2008 profiling tools

Red Gate's ANTS Memory and Performance Profilers

Microfocus DevPartner Studio Professional 9.1

SQL Profiler 2005/2008

分析

Performance analysis

High call count

Functions with very high call counts should be treated with suspicion and investigated. Often the high call count is valid, but sometimes it's due to an error in event handling, and can be a major source of unintended processing

Using the call graphing facility of your performance tool, it should be possible to trace back to where the calls to the function originate, and decide if it is acceptable behaviour. It's a very quick and easy check, and a very quick optimization if a problem is found.

I have actually lost count of the number of times I have found this issue in live code!

Slowest function excluding child calls

This is the slowest function where the body of the function itself is responsible for the time.

It includes time spent calling .NET framework functions, but excludes time spent calling

other source code functions. In other words, it's answering the question, "What's the slowest

function we have written?"

Identify the slowest functions excluding child calls and then, if available, look for the slowest

code lines and determine if they are optimizable. You will often see slow lines waiting for

database and web service calls to return.

Slowest function including child calls

This is the slowest function where the total cost of the functions, including time spent into

calls to child functions (we have written), is accounted for.

Use your tool's call graph facility to explore the slowest part of the call tree

Functions with high CPU utilization

Any function with high CPU utilization is a prime candidate for optimization, as high

resource demands can be a key bottleneck.

Identify the most CPU-intensive lines of code within the function and determine if there are

workable optimizations that may apply.

Functions with Wait time

Functions with Wait time can indicate performance problems in other application layers,

or problems with thread locking

Identify which resource the function is waiting for, e.g. database or web service, then

investigate the cause of the contention on that layer.

Functions generating disk activity

A function generating disk activity needs to be investigated further, as it is demanding

resources and is therefore a potential bottleneck

Make sure the disk activity is necessary, particularly if this is a server application. Even if it is

necessary, try to find an alternative if possible.

Functions generating network activity

A function generating network activity needs to be investigated further as another

potential bottleneck.

Make sure the network activity is valid and not an artifact left behind from prototyping or

developer testing. Ensure that the number of times this network activity occurs is as low as

possible, to reduce the effect of latency. If possible, get more data in one hit

Memory analysis

Memory leak detection

Finding memory leaks is all about identifying objects that are allocated but never garbage collected

Excessive memory usage

Reducing the overall memory footprint

Inefficient allocation and retention

Large Object Heap fragmentation

Common Areas for Performance Improvement

数据库

连接:连接是昂贵的资源

缓存:

Asp.net Cache: 如SqlCacheDependency

AppFabric: cache farm

Indexing

Database Engine Tuning Advisor

O/R框架

动态SQL的影响,separate views and functions, or perhaps a dedicated stored procedure

Reflection

Reflection is a very powerful mechanism

恰当的使用

String manipulation

StringBuilder和String的区别

Cryptographic functions

加密强度和性能

Network call latency

Protocol

Size of payload

Serialization/deserialization

Chatty vs. chunky: 请求的次数

Synchronous vs. asynchronous

 

Web

页面绑定的信息http://localhost:***/Trace.axd

OutputCache

web.config

<system.web>下的一些配置项

<compilation debug="false">

<trace enabled="false"/>

<deployment retail="true">

<httpHandlers>

相关实践学习
通过性能测试PTS对云服务器ECS进行规格选择与性能压测
本文为您介绍如何利用性能测试PTS对云服务器ECS进行规格选择与性能压测。
目录
打赏
0
0
0
0
9
分享
相关文章
探索软件测试中的自动化测试框架选择与优化策略
本文深入探讨了在现代软件开发流程中,如何根据项目特性、团队技能和长期维护需求,精准选择合适的自动化测试框架。
289 11
优化你的 REST Assured 测试:设置默认主机与端口、GET 请求与断言
REST Assured 是一个强大的 Java 库,用于简化 RESTful API 测试。本文详解了其核心功能:设置默认主机和端口以减少代码重复、发起 GET 请求并验证响应结果,以及通过断言确保接口行为符合预期。同时推荐 Apipost 工具,助力开发者提升 API 测试效率,实现更高效的接口管理与团队协作。掌握这些技巧,可显著优化测试流程与代码质量。
如何测试中间件优化后的 Pinia 状态管理?
如何测试中间件优化后的 Pinia 状态管理?
142 64
游戏开发者如何使用独享静态代理IP进行测试与优化
随着互联网技术的发展,使用代理IP的人数逐渐增加,特别是在业务需求中需要使用静态代理IP的情况越来越多。本文探讨了独享静态代理IP是否适用于游戏行业,分析了其优势如稳定性、不共享同一IP地址及地理位置选择等,同时也指出了需要注意的问题,包括可能的延迟、游戏兼容性和网络速度等。总体而言,选择合适的代理服务并正确配置,可以有效提升游戏体验。
143 2
探索软件测试中的自动化框架选择与优化策略####
本文深入剖析了当前主流的自动化测试框架,通过对比分析各自的优势、局限性及适用场景,为读者提供了一套系统性的选择与优化指南。文章首先概述了自动化测试的重要性及其在软件开发生命周期中的位置,接着逐一探讨了Selenium、Appium、Cypress等热门框架的特点,并通过实际案例展示了如何根据项目需求灵活选用与配置框架,以提升测试效率和质量。最后,文章还分享了若干最佳实践和未来趋势预测,旨在帮助测试工程师更好地应对复杂多变的测试环境。 ####
164 4
探索软件测试中的自动化测试框架选择与优化策略####
本文深入探讨了在当前软件开发生命周期中,自动化测试框架的选择对于提升测试效率、保障产品质量的重要性。通过分析市场上主流的自动化测试工具,如Selenium、Appium、Jest等,结合具体项目需求,提出了一套系统化的选型与优化策略。文章首先概述了自动化测试的基本原理及其在现代软件开发中的角色变迁,随后详细对比了各主流框架的功能特点、适用场景及优缺点,最后基于实际案例,阐述了如何根据项目特性量身定制自动化测试解决方案,并给出了持续集成/持续部署(CI/CD)环境下的最佳实践建议。 --- ####
探索软件测试中的自动化框架选择与优化策略####
【10月更文挑战第21天】 本文深入剖析了软件测试领域面临的挑战,聚焦于自动化测试框架的选择与优化这一核心议题。不同于传统摘要的概述方式,本文将以一个虚拟案例“X项目”为线索,通过该项目从手动测试困境到自动化转型的成功历程,生动展现如何根据项目特性精准匹配自动化工具(如Selenium、Appium等),并结合CI/CD流程进行深度集成与持续优化,最终实现测试效率与质量的双重飞跃。读者将跟随“X项目”团队的视角,直观感受自动化框架选型的策略性思考及实践中的优化技巧,获得可借鉴的实战经验。 ####
82 0
利用Postman和Apipost进行API测试的实践与优化-动态参数
在API测试中,Postman和Apipost是常用的工具。Postman内置变量功能有限,面对复杂场景时需编写JavaScript脚本,增加了维护成本。而Apipost提供丰富的内置变量、可视化动态值配置和低代码操作,支持生成真实随机数据,如邮箱、手机号等,显著提升测试效率和灵活性。对于复杂测试场景,Apipost是更好的选择,能有效降低开发与维护成本,提高测试工作的便捷性和可维护性。
使用 BenchmarkDotNet 对 .NET 代码进行性能基准测试
使用 BenchmarkDotNet 对 .NET 代码进行性能基准测试
156 13
Benchmark.NET:让 C# 测试程序性能变得既酷又简单
Benchmark.NET是一款专为 .NET 平台设计的性能基准测试框架,它可以帮助你测量代码的执行时间、内存使用情况等性能指标。它就像是你代码的 "健身教练",帮助你找到瓶颈,优化性能,让你的应用跑得更快、更稳!希望这个小教程能让你在追求高性能的路上越走越远,享受编程带来的无限乐趣!
265 13
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等