Interested in Solving your Challenges with XenonStack Team

Get Started

Get Started with your requirements and primary focus, that will help us to make your solution

Proceed Next

TestOps

Performance Tuning Tools and Working Architecture

Navdeep Singh Gill | 06 April 2023

Performance Tuning

What is Performance Tuning?

The primary goal of performance tuning is to find bad parts /bottlenecks of code and to improve a bad parts/bottlenecks of codes. How is it possible to find bottlenecks of code and to overcome bottlenecks of a code? Consider the following example to understand a concept in a more explicit manner which is as explained below:

There is a problem or trouble. There are two ways or two algorithms by following them problem solved. To know that whether an algorithm A performs faster than Algorithm B. Then, it is not possible by looking at the algorithm which will give us a better result. In that case, problem can be solved by following both algorithms. While an execution of code which is written by following the first algorithm, though file contains a benchmarking and profiling result for this code. However, In the same way, write code by following the second algorithm. Execute a code and store a result in a second file.As the second file also contains a profiling and benchmark result.

A tool that is especially valuable for assisting in the design of particular mental, physical and professional training programs. Click to explore about, Performance Profiling Tools

Now result of two files can be compared to check that which algorithm is optimum. GoLang comes with two features profiling and benchmark. Both of these help to analyze which code is doing well. But a most important thing here is that a result to be stored in a file so that will help to make comparisons for results of code and choose an optimum result. The code is optimum in a sense that which is taking less memory, less resource usage, execution time.

How Does Performance Tuning Work?

  • Write a Golang code according to requirements in form of functions.
  • Write a BenchMark for written methods of Golang in a file with extension as “filename_test.go”.
  • Test all the BenchMarks for Golang code present in a file in which all the BenchMark specified along with this store a result in a BenchMark file “go test -run = xxx -bench =. -cpuprofile =cpu.out | tee bench3”.
  • Implement whatever you want at the code, to optimize code performance.
  • Test all the BenchMarks for Golang code present in a file in which all BenchMark specified along with this store a result in BenchMark file “go test -run = xxx -bench =. -cpuprofile =cpu.out | tee bench3”.
  • Compare the result of both files using Benchcmp.
  • Using following command compare BenchMarking result of two files “benchcmp bench1 bench2”.
  • After the execution of command output will be visible.

What are the best practices of Performance Tuning?

  • Content Delivery Network (CDN)
  • Shrink Libraries
  • Consider entire data flow
  • Performance Management
  • Check queries and shrink images
  • Use Top-Down Tuning Approach
  • Revise System Architecture and Configuration files
  • Proper Data Type and Constraints
  • Normalization
  • Indexing and Optimized Queries
  • Stored Procedures and Functions
  • Response-Time Analysis
A non-functional type of testing that measures the performance of an application or software under a certain workload. Click to explore about, Performance Testing Tools

What are the benefits of Performance Tuning?

  • The main focus of Performance Tuning is to find a bad part of the code and convert a lousy part of the code to good part. For this, every line of code which is present in our file converted into as an object in memory. There is an excellent relation between code quality and performance.
  • Let us consider that lousy code is optimized at the machine and now a good code 16% better than faulty code. Is it possible to achieve more than that? Yes, there is an excellent relation between code quality and performance. While writing code more simply, the code is refactored and decoupled from each other.
  • This step increases a code simplicity, but performance cannot request. Because when simplicity in our code increases, then in that case execution time increases. Thus, while achieving one factor other is overwhelmed. Here the most important thing to improve performance is to identify bottlenecks and then develop these by one.
  • Analyzing our code through profiling and benchmarking can identify these bottlenecks and loopholes. Profiling helps to identify each line of the method that at which of code is a problem. This decision better changed to code made. Then further current code’s result is compared with the previous code result.
  • Tracing identify each core of CPU. Here mean to say that at which core of processor our function is executing.

Check how all cores of the processor are used to execute a function. Click to explore about, Performance Tracing Tools and Architecture

Why Performance Tuning Matters?

It is mandatory in the case while finding a difference between benchmarking results of two codes -

Race Detector

It is used with both tests and benchmarks to check that if there is synchronization. However, this can be more clear by looking at the following example - Syntax -

go test -race
However this above is used in the same way both with tests and benchmarks. They make a call to

function "ParseAdexpMessage" to check any synchronization issue.

How to Adopt Performance Tuning?

Benchcmp Implementation

Benchmark is required in a condition, whenever there is a requirement to compare the result for two benchmarks. To use a Benchcmp, it is necessary files should be available at which this benchcmp command executed. As looking a below screenshot, it will be more clear that benchcmp applied on two files named as bench1 and bench2. Despite having two files, using a "benchmp "command will be useless. The syntax for "benchcmp" command as shown below -

Benchcmp "firstfile_contians_benchmark_Restult" "secondfile_having_benchamrk_result"
Commands required to understand Now let us look following to understand that how a result stored in a file required to compare the result using "benchcmp."If no file is present, how are the result of two files compared using a benchcmp? It will be more clear by looking at following commands explained along with an example - To Store result in a benchmark file - While storing the result in a file, following benchmarking command used - Syntax -

go test -run=xxx -bench=. -cpuprofile=cpu.out | tee bench3
Similarly, the result for memory profiling stored in a file as a reference to an above command. In another hand, both a memory and CPU profiling results stored in a single file.

Benchcmp Implementation

All other things are the same as doing profiling and benchmarking on go code using a benchmark file. However, the only difference is that result is stored in a file, so making comparisons later on that will be helpful for the optimization of code. Now, to get a result or compare two files, the following command is required used.

Syntax: benchcmp “filename_contianing_old_result” “filename-containing_new_result” 

Performance Tuning Tools

For Performance Tuning, though no need for any specific tool. Usually, the Testing package is required to do a benchmark and profiling on the code.

Conclusion

From all of the above, there is one important thing is that every time executing a code, its benchmarking and profiling results are required to be stored in a file. Otherwise, it is not possible to make comparisons of results.

Table of Contents

navdeep-singh-gill

Navdeep Singh Gill

Global CEO and Founder of XenonStack

Navdeep Singh Gill is serving as Chief Executive Officer and Product Architect at XenonStack. He holds expertise in building SaaS Platform for Decentralised Big Data management and Governance, AI Marketplace for Operationalising and Scaling. His incredible experience in AI Technologies and Big Data Engineering thrills him to write about different use cases and its approach to solutions.

Get the latest articles in your inbox

Subscribe Now