The gap is more than a star and a half! Github star 85K performance optimization rule bible

Java performance optimization_5 tips for Java performance optimization

java performance optimization

Optimizing Java code requires understanding how different elements in Java interact and how to interact with the operating system running Java. Use these five tips and resources to start learning how to analyze and optimize code.

You may worry about licensing issues until we get the benefit. Java is owned by Oracle and is subject to the Oracle BCL license, which is not a free/open source license. Even so, Oracle Java is part of many open source projects. OpenJDK is a free software implementation of the Java platform and has been licensed under GPL v2. (For more information, see the free Java implementation on Wikipedia.)

getting Started

Performance optimization depends on a variety of factors, including garbage collection, virtual machines, and basic operating system (OS) settings. Developers can use a variety of tools for analysis and optimization, and can read Java tools for source code optimization and analysis to understand some of these tools  . If you have trouble using terminology and Java basics, please check the Livecoding Java category page for live streams, archived videos and other useful information.

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

"it depends on"

It is necessary to understand that no two applications can have the same optimization, and there is no definite path to optimize a Java application. It's all about using best practices and sticking to the right way to deal with performance optimization methodology. To truly be at the top of performance optimization, as a Java developer, you need to have a proper understanding of the Java Virtual Machine (JVM) and the underlying operating system:

  • JVM and underlying operating system:  Java virtual machine is the host of any Java application. Read the JVM internal guide to learn more about the JVM internals and operating system differences.
  • JVM distribution model: The  Java distribution model handles multiple JVM instances for your application. The distribution model can obtain more available resources, thereby improving application performance. You can move forward in two ways. The first method is to run multiple JVMs on a single server with a heap size of 2GB or 8GB. The second method is to run a JVM on multiple servers. Choosing the right method depends on many factors, including availability and responsiveness.
  • **JVM architecture:** Choosing the right JVM architecture is important for performance. You can use a 64-bit JVM machine or a 32-bit JVM machine. Generally, the performance of a 32-bit JVM is better than that of a 64-bit JVM. The only reason to choose a 64-bit JVM is if you require a heap size greater than 3GB.

After clarifying the basic ideas and elements of performance optimization, we will now focus on techniques that can help you optimize Java applications.

1. Adjust garbage collection (GC)

Due to the complexity of garbage collection, it is difficult to find the exact performance of the application. However, if you really want to optimize your application, you need to deal with garbage collection accordingly. The general rule is to change the GC settings and perform performance analysis at the same time.

Once you are satisfied with the results, you can stop the process and move on to other forms of optimization. Make sure that in addition to the average transaction time, you also pay attention to outliers. When Java applications slow down, outliers are the real culprit, and they are hard to find.

In addition, you need to understand the impact of the performance impact during the running of the application. The speed drop every week is negligible, and the speed drop of each database transaction can be a costly thing. Choose the optimization path accordingly, and then optimize the application based on the workload.

2. Get the GC algorithm that suits you

Let us learn more about GC optimization. After all, this is the key to the entire optimization problem at hand. Currently, there are four Java garbage collector algorithms to choose from. Each algorithm can meet different needs, so you need to choose accordingly. Many developers cannot optimize their applications because they know nothing about GC algorithms.

The four algorithms are serial collector, parallel/throughput collector, CMS collector and G1 collector. To learn more about each garbage collector and how it works, check out the amazing garbage collectors-serial, parallel, CMS, G1 from the Takipi blog  . This article also discusses the impact of Java 8 on the GC algorithm and other minor changes.

Back to understanding the  GC algorithm, based on the understanding of Java garbage collection  , concurrent marking and scanning GC (or "CMS") algorithm is the best algorithm choice for web server applications. The parallel GC algorithm is very suitable for applications with built-in predictability.

G1 and CMS are ideal for concurrent operations, but they can also cause frequent pauses. The choice also depends on the trade-offs. For example, even if the GC pause time is longer compared with other GC algorithms, it is best to choose a parallel algorithm.

3. Java Heap

The Java memory heap plays a vital role in meeting memory requirements. It is always best to start with the smallest heap allocation, and then increase it by continuing to test. In most cases, the optimization problem is solved by increasing the heap size, but if there is a lot of GC overhead, the solution will not work properly.

GC overhead will also make throughput too low, resulting in unusually slow applications. In addition, adjusting the GC earlier can help you avoid problems with heap size allocation. First, you can choose any heap size between 1GB and 8GB. When choosing the correct heap size, the concepts of old and new generation objects can also be used.

Finally, the heap size should depend on the ratio of old objects to new-generation objects, previous GC optimizations and liveset (ie, the memory size of the object).

4. Core application optimization

Core code optimization is the best way to optimize Java applications. If your application does not respond to GC and heap optimization, it is better to make architectural changes and focus on how the application processes the information. Using smart algorithms and taking care of objects can solve many problems, including fragmentation, heap problems, and garbage collection problems.

5. Use the best features

Java has a variety of functions to handle algorithm performance. If you use StringBuilder instead of a simple String, there will be little improvement in performance. However, there are other ways to handle optimization at the code level. Let's take a look at them below.

  • Use StringBuilder instead of + operator.
  • Avoid using iterator().
  • Make full use of the stack.
  • Avoid regular expressions and use Apache Commons Lang instead.
  • Stay away from recursion. Recursion is very resource intensive!

Read more about Java code optimization in Java's  Top Ten Simple Performance Optimizations.

in conclusion

Java performance optimization is a big topic, and this article obviously won't cover everything. If you think you need to add something to the article, please don’t forget to share it with the audience through the comments below.

Let me share with you a performance optimization note on Github starred 85K.

Because the content of this document is too much, the following will show you some of the picture chapters who need to get it, you can directly like + follow and click here to get it for free!

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

Strategies, methods and methodology

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

Operating system performance monitoring

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

JVM overview

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

JVM performance monitoring

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

Java application performance analysis

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

Java application performance analysis skills

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

Getting started with JVM performance tuning

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

Benchmark testing of Java applications

image.png

Benchmarking of multi-tier applications

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-IYBvrwmj-1610333971182)(https://upload-images.jianshu.io/upload_images/22934207-e316ddb3594bedb2?imageMogr2 /auto-orient/strip%7CimageView2/2/w/1240)]

Web application performance tuning

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

Web Service performance

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

Java Persistence and Performance of EnterpriseJava Bean

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

The gap is more than a star and a half!  Github star 85K performance optimization rule bible

How to obtain this high-quality information?

Quick access channel: Click here to get it for free! Full of sincerity! ! !

Selected questions for Java interviews, architecture and actual documentation portal: https://jq.qq.com/?_wv=1027&k=iWJZw1rp

It is not easy to organize, friends who feel helpful can help, like, share and support the editor~

Your support, my motivation; I wish you all a bright future and constant offers! ! !

Guess you like

Origin blog.csdn.net/weixin_47066028/article/details/112463661