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

本文涉及的产品
性能测试 PTS,5000VUM额度
简介: 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进行规格选择与性能压测。
相关文章
|
11天前
|
测试技术 持续交付 API
深入挖掘探索.NET单元测试
【10月更文挑战第11天】
29 2
|
20天前
|
Web App开发 前端开发 JavaScript
探索Python科学计算的边界:利用Selenium进行Web应用性能测试与优化
【10月更文挑战第6天】随着互联网技术的发展,Web应用程序已经成为人们日常生活和工作中不可或缺的一部分。这些应用不仅需要提供丰富的功能,还必须具备良好的性能表现以保证用户体验。性能测试是确保Web应用能够快速响应用户请求并处理大量并发访问的关键步骤之一。本文将探讨如何使用Python结合Selenium来进行Web应用的性能测试,并通过实际代码示例展示如何识别瓶颈及优化应用。
65 5
|
19天前
|
缓存 监控 算法
软件测试中的性能瓶颈分析与优化策略
【10月更文挑战第6天】 性能测试是确保软件系统在高负载条件下稳定运行的重要手段。本文将深入探讨性能测试的常见瓶颈,包括硬件资源、网络延迟和代码效率等问题。通过具体案例分析,我们将展示如何识别并解决这些问题,从而提升软件的整体性能。最后,文章还将分享一些实用的性能优化技巧,帮助读者在日常开发和测试中更好地应对性能挑战。
59 3
|
2月前
|
监控 测试技术 持续交付
软件测试中的性能瓶颈分析与优化策略
性能瓶颈,如同潜伏于软件深处的隐形障碍,悄然阻碍着系统的流畅运行。本文旨在揭示这些瓶颈的形成机理,剖析其背后的复杂成因,并汇聚一系列针对性的优化策略,为软件开发者提供一套系统性的解决方案。
44 5
|
17天前
|
运维
【运维基础知识】用dos批处理批量替换文件中的某个字符串(本地单元测试通过,部分功能有待优化,欢迎指正)
该脚本用于将C盘test目录下所有以t开头的txt文件中的字符串“123”批量替换为“abc”。通过创建批处理文件并运行,可实现自动化文本替换,适合初学者学习批处理脚本的基础操作与逻辑控制。
111 56
|
11天前
|
测试技术 API 开发者
精通.NET单元测试:MSTest、xUnit、NUnit全面解析
【10月更文挑战第15天】本文介绍了.NET生态系统中最流行的三种单元测试框架:MSTest、xUnit和NUnit。通过示例代码展示了每种框架的基本用法和特点,帮助开发者根据项目需求和个人偏好选择合适的测试工具。
27 3
|
24天前
|
缓存 监控 测试技术
软件测试中的性能瓶颈分析与优化策略
本文深入探讨了在软件测试过程中,如何有效地识别和解决性能瓶颈问题。通过对性能瓶颈的定义、分类以及常见原因的分析,结合实际案例,提出了一系列针对性的优化策略和方法。这些策略旨在帮助测试人员和开发人员提高软件的性能表现,确保软件在高负载条件下依然能够稳定运行。
|
2月前
|
监控 算法 测试技术
软件测试中的性能瓶颈分析与优化策略
本文旨在深入探讨软件测试过程中性能瓶颈的识别与优化方法。通过对性能瓶颈的概念、分类及其成因进行分析,结合实际案例,提出一套系统的性能瓶颈诊断流程和针对性的优化策略。文章首先概述了性能瓶颈的基本特征,随后详细介绍了内存泄漏、资源竞争、算法效率低下等常见瓶颈类型,并阐述了如何通过代码审查、性能监测工具以及负载测试等手段有效定位问题。最后,结合最佳实践,讨论了代码级优化、系统配置调整、架构改进等多方面的解决措施,旨在为软件开发和测试人员提供实用的性能优化指导。
62 4
|
2月前
|
关系型数据库 MySQL 测试技术
《性能测试》读书笔记_数据库优化
《性能测试》读书笔记_数据库优化
30 7
|
2月前
|
缓存 监控 算法
软件测试中的性能瓶颈定位与优化策略
性能瓶颈,如同隐藏在系统深处的“拦路虎”,悄无声息地制约着软件的表现。本文将揭示如何通过一系列科学方法,识别并消除这些障碍,从而显著提升软件性能,确保用户享受到流畅无阻的数字体验。