Skip to content

khdevnet/performance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Performance testing

Performance testing is the process of determining the speed, responsiveness and stability of a computer, network, software program or device under a workload.

Basic operating system terminology

  • Physical Memory — The actual physical memory chips in a computer. Only the operating system manages physical memory directly.
  • Virtual Memory — A logical organization of memory in a given process. Virtual memory size can be larger than physical memory. For example, 32-bit programs have a 4 GB address space, even if the computer itself only has 2 GB of RAM. Windows allows the program to access only 2 GB of that by default, but all 4 GB is possible if the executable is large-address aware. (On 32-bit versions of Windows, large-address aware programs are limited to 3 GB.) As of Windows 8.1 and Server 2012, 64-bit processes have a 128 TB process space, far larger than the 4 TB physical memory limit. Some of the virtual memory may be in RAM while other parts are stored on disk in a paging file. Contiguous blocks of virtual memory may not be contiguous in physical memory. All memory addresses in a process are for the virtual memory.
  • Reserved Memory — A region of virtual memory address space that has been reserved for the process and thus will not be allocated to a future requester. Reserved memory cannot be used for memory allocation requests because there is nothing backing it—it is just a description of a range of memory addresses.
  • Committed Memory — A region of memory that has a physical backing store. This can be RAM or disk.
  • Page — An organizational unit of memory. Blocks of memory are allocated in a page, which is usually a few KB in size.
  • Paging — The process of transferring pages between regions of virtual memory. The page can move to or from another process (soft paging) or the disk (hard paging). Soft paging can be accomplished very quickly by mapping the existing memory into the current process’s virtual address space. Hard paging involves a relatively slow transfer of data to or from disk. Your program must avoid this at all costs to maintain good performance.
  • Page In — Transfer a page from another location to the current
  • Page Out — Transfer a page from the current process to another location, such as disk.
  • Context Switch — The process of saving and restoring the state of a thread or process. Because there are usually more running threads than available processors, there are often many context switches per second.
  • Kernel Mode — A mode that allows the OS to modify low-level aspects of the hardware’s state, such as modifying certain registers or enabling/disabling interrupts. Transitioning to Kernel Mode requires an operating system call, and can be quite expensive.
  • User Mode — An unprivileged mode of executing instructions. There is no ability to modify low-level aspects of the system.

The Process category of counters surfaces much of this critical information via counters with instances for each process, including:

  • % Privileged Time—Amount of time spent in executing privileged (kernel mode) code.
  • % Processor Time—Percentage of a single processor the application is using. If your application is using two logical processor cores at 100% each, then this counter will read 200.
  • % User Time—Amount of time spent in executing unprivileged (user mode) code.
  • IO Data Bytes/sec—How much I/O your process is doing.
  • Page Faults/sec—Total number of page faults in your process. A page fault occurs when a page of memory is missing from the current working set. It is important to realize that this number includes both soft and hard page faults. Soft page faults are innocuous and can be caused by the page being in memory, but outside the current process (such as for shared DLLs). Hard page faults are more serious, indicating data that is on disk but not currently in memory. Unfortunately, you cannot track hard page faults per process with performance counters, but you can see it for the entire system with the Memory\Page Reads/sec counter. You can do some correlation with a process’s total page faults plus the system’s overall page reads (hard faults). You can definitively track a process’s hard faults with ETW tracing with the Windows Kernel/Memory/Hard Fault event.
  • Pool Nonpaged Bytes—Typically operating system and driver allocated memory for data structures that cannot be paged out such as operating system objects like threads and mutexes, but also custom data structures.
  • Pool Paged Bytes—Also for operating system data structures, but these are allowed to be paged out.
  • Private Bytes—Committed virtual memory private to the specific process (not shared with any other processes).
  • Virtual Bytes—Allocated memory in the process’s address space, some of which may be backed by the page file, shared with other processes, and memory private to the process.
  • Working Set—The amount of virtual memory currently resident in physical memory (usually RAM).
  • Working Set-Private—The amount of private bytes currently resident in physical memory.
  • Thread Count—The number of threads in the process. This may or may not be equal to the number of .NET threads. See Chapter 4 (Asynchronous Programming) for a discussion of .NET thread-related counters. There are a few other generally useful categories, depending on your application. You can use PerfMon to explore the specific counters found in these categories.
  • IPv4/IPv6—Internet Protocol-related counters for datagrams and fragments.
  • Memory—System-wide memory counters such as overall paging, available bytes, committed bytes, and much more.
  • Objects—Data about kernel-owned objects such as events, mutexes, processes, threads, semaphores, and sections.
  • Processor—Counters for each logical processor in the system.
  • System—Context switches, alignment fixes, file operations, process count, threads, and more.
  • TCPv4/TCPv6—Data for TCP connections and segment transfers.

Performance testing metrics

  • Availability: The amount of time an application is available to the end user.

  • Concurrency: is the number of active users generated by the software, which is not necessarily the same as the number of users concurrently accessing the application.

  • Throughput: how many units of information a system processes over a specified time;

  • Response time, or latency: the amount of time that elapses between a user-entered request and the start of a system's response to that request;

  • Bandwidth: the volume of data per second that can move between workloads, usually across a network;

  • Scalability: how system can scale (vertical/horizontal)

  • Reliability: number of errors should be less then number of requests

  • Memory: the working storage space available to a processor or workload;

  • CPU interrupts per second: the number of hardware interrupts a process receives per second.

Questions for system load checklist
  • How many end users will actually use the application?
  • Where are these end users located?
  • How many of these end users will use it concurrently?
  • How will the end users connect to the application? (Mobile device, descktop, HTTP, WebSocket etc...)
  • How many additional end users will require access to the application over time?
  • What will the final application landscape look like in terms of the number and location of the servers?
  • What effect will the application have on network capacity? What is the bandwith?
  • How many users plan for the peaks rather than the troughs.
  • What is the numbers of application network round-trips?
  • What is the amount of data delivered to end user? (from server to client)
  • Do you need to measure performance from a presentation layer perspective? (What delay user has when perform combobox change? etc)
Designing a Performance Test Environment
  • Is the number and specification of servers is the same as Production?
  • Is test environment in the same location as production? Is testing perform with same bihaviour asn on production? Bandwidth and connectivity of network infrastructure
  • Is database size the same?
  • Load balancing. Some load balancing strategies use the IP address of the incoming user to determine the server to which the user should be connected for the current session. If you don’t take this into consideration, then all users from a single injector will have the same IP address and may be allocated to the same server.

Examples of performance requirements

  • The system shall be able to process 100 payment transactions per second in peak load.
  • In standard workload, the CPU usage shall be less than 50%, leaving 50% for background jobs.
  • Production of a simple report shall take less than 20 seconds for 95% of the cases.
  • Scrolling one page up or down in a 200 page document shall take at most 1 second.

Resources

Performance optimization

Approach

Performance optimization process

  • Non-functional requirements
  • Performance reflects in architecture
  • Develop with real data
  • Avoid premature and micro optimization
  • Environment - maximum close to production or better to use production
  • Test data - real data
  • Build Configuration - Release
  • Performance benchmarking tools (Load UI, Apache, JMeter)

Tools

Visual Studio Performance Profiler
JetBrains dotTrace
Redgate ANTS

BOTTLENECKS IDENTIFICATION

  • Sub-Optimal Design
  • Resources usage
    CPU
    Memory
    IO: File System
    IO: Network
  • Tools
    Task Manager
    Resource Monitor
    Performance Monitor
  • Server Monitoring
    Application Insights
    New Relic
    Custom Logging
    Etc.

PERFORMANCE. TIPS AND TRICKS

  • Logical Problems / Not optimal code
  • Data Structure misuse – IEnumerable, List, Array, Dictionary, HashSet
  • Cache – cached repositories, etc.
  • Concurrent or Asynchronous code – async/await, TPL, Parallel.For
  • Use StringBuilder
  • Avoid Exceptions
  • Use XML Readers instead of LINQ to XML
  • Avoid Reflection/dynamic
  • Use memoization – if(lookup.TryGetValue(key, out value)) return value; lookup[key] = value.ToLower();
  • Override GetHashCode and Equals
  • Use as operator instead is
  • Use ref or out when you need copy structure by reference
  • Reduce methods size
  • Prefer local variables over fields
  • Use static readonly fields and constants
  • Use static methods and fields
  • Dictonary order, SortedDictionary
  • Make classes closed using paramater sealed

Performance Resources

Memory optimization

Tools

Visual Studio Managed Memory Debugger
Visual Studio Diagnostic Tools
Concurrency Visualizer for Visual Studio 2017
  • Look how often GC runned.
PerfView

Memory Tips and Tricks

  • Files, Connections, etc. – IDisposable – Dispose(), Close(), using
  • Clear events subscriptions – if you see +=, then there must be -=
  • Use StringBuilder
  • Static fields/properties
  • Define collections capacity – var list = new List(products.Length);
  • Use structs
  • Do not call GC.Collect() explicitly
  • Boxing/Unboxing
  • Use WeekReferences, ConditionalWeakTable

Resources

Database

Tools

MS SQL Profiler
MS SQL Management Studio
Redgate SQL Monitor

Tips and Tricks

  • Reduce number of queries
  • Use Indexes
  • Choose proper transaction isolation level
  • Retrieve only needed records - return context.Products.ToList().FirstOrDefault();
  • Don’t select unneeded columns – SELECT * FROM Products
  • Entity Framework – rewrite with stored procedures
  • Bulk Operations – use SQLBulkCopy class
  • Use Cache
  • Use IQueryable
  • Do not track changes – AutoDetectChangesEnabled; db.Products.Where(p => p.InStock). AsNoTracking().ToList();
  • Define length for nvarchar columns
  • Seek vs Scan, avoid functions in WHERE
  • Estimated vs Actual Query Plan
  • Update Statistics
  • Parameters Sniffing – local variables, OPTION (RECOMPILE)
  • Avoid transactions
  • Avoid cursors
  • Normalization\Denormalization
  • Partitioning

Resources

Web optimization

Resources

Tools

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published