.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进行规格选择与性能压测。
相关文章
|
3天前
|
人工智能 前端开发 测试技术
探索软件测试中的自动化框架选择与优化策略####
本文深入剖析了当前主流的自动化测试框架,通过对比分析各自的优势、局限性及适用场景,为读者提供了一套系统性的选择与优化指南。文章首先概述了自动化测试的重要性及其在软件开发生命周期中的位置,接着逐一探讨了Selenium、Appium、Cypress等热门框架的特点,并通过实际案例展示了如何根据项目需求灵活选用与配置框架,以提升测试效率和质量。最后,文章还分享了若干最佳实践和未来趋势预测,旨在帮助测试工程师更好地应对复杂多变的测试环境。 ####
17 4
|
9天前
|
机器学习/深度学习 前端开发 测试技术
探索软件测试中的自动化测试框架选择与优化策略####
本文深入探讨了在当前软件开发生命周期中,自动化测试框架的选择对于提升测试效率、保障产品质量的重要性。通过分析市场上主流的自动化测试工具,如Selenium、Appium、Jest等,结合具体项目需求,提出了一套系统化的选型与优化策略。文章首先概述了自动化测试的基本原理及其在现代软件开发中的角色变迁,随后详细对比了各主流框架的功能特点、适用场景及优缺点,最后基于实际案例,阐述了如何根据项目特性量身定制自动化测试解决方案,并给出了持续集成/持续部署(CI/CD)环境下的最佳实践建议。 --- ####
|
28天前
|
测试技术 持续交付 API
深入挖掘探索.NET单元测试
【10月更文挑战第11天】
37 2
|
1月前
|
Web App开发 前端开发 JavaScript
探索Python科学计算的边界:利用Selenium进行Web应用性能测试与优化
【10月更文挑战第6天】随着互联网技术的发展,Web应用程序已经成为人们日常生活和工作中不可或缺的一部分。这些应用不仅需要提供丰富的功能,还必须具备良好的性能表现以保证用户体验。性能测试是确保Web应用能够快速响应用户请求并处理大量并发访问的关键步骤之一。本文将探讨如何使用Python结合Selenium来进行Web应用的性能测试,并通过实际代码示例展示如何识别瓶颈及优化应用。
98 5
|
1月前
|
缓存 监控 算法
软件测试中的性能瓶颈分析与优化策略
【10月更文挑战第6天】 性能测试是确保软件系统在高负载条件下稳定运行的重要手段。本文将深入探讨性能测试的常见瓶颈,包括硬件资源、网络延迟和代码效率等问题。通过具体案例分析,我们将展示如何识别并解决这些问题,从而提升软件的整体性能。最后,文章还将分享一些实用的性能优化技巧,帮助读者在日常开发和测试中更好地应对性能挑战。
82 3
|
2月前
|
监控 测试技术 持续交付
软件测试中的性能瓶颈分析与优化策略
性能瓶颈,如同潜伏于软件深处的隐形障碍,悄然阻碍着系统的流畅运行。本文旨在揭示这些瓶颈的形成机理,剖析其背后的复杂成因,并汇聚一系列针对性的优化策略,为软件开发者提供一套系统性的解决方案。
50 5
|
1月前
|
运维
【运维基础知识】用dos批处理批量替换文件中的某个字符串(本地单元测试通过,部分功能有待优化,欢迎指正)
该脚本用于将C盘test目录下所有以t开头的txt文件中的字符串“123”批量替换为“abc”。通过创建批处理文件并运行,可实现自动化文本替换,适合初学者学习批处理脚本的基础操作与逻辑控制。
134 56
|
9天前
|
缓存 监控 测试技术
全网最全压测指南!教你如何测试和优化系统极限性能
大家好,我是小米。本文将介绍如何在实际项目中进行性能压测和优化,包括单台服务器和集群压测、使用JMeter、监控CPU和内存使用率、优化Tomcat和数据库配置等方面的内容,帮助你在高并发场景下提升系统性能。希望这些实战经验能助你一臂之力!
23 3
|
28天前
|
测试技术 API 开发者
精通.NET单元测试:MSTest、xUnit、NUnit全面解析
【10月更文挑战第15天】本文介绍了.NET生态系统中最流行的三种单元测试框架:MSTest、xUnit和NUnit。通过示例代码展示了每种框架的基本用法和特点,帮助开发者根据项目需求和个人偏好选择合适的测试工具。
37 3
|
4天前
|
开发框架 安全 .NET
.NET使用Moq开源模拟库简化单元测试
.NET使用Moq开源模拟库简化单元测试~