In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
Memory is one of the widely wasted hardware resources in the world today. Due to inefficient programming, an astonishing amount of memory is wasted. This pattern is repeated in multiple enterprise applications. To prove this, we conducted a small study. We analyzed the famous spring boot pet Clinic application to see how much memory was wasted. The application was designed by the spring community to show how the spring application framework is used to build simple but powerful database-oriented applications. Environment preparation Spring Boot 2.1.4 Java SDK 1.8 Tomcat 8.5.20 MySQL 5.7.26 stress testing We used the popular open source load testing tool Apache JMeter for stress testing. We performed a 30-minute load test with the following settings: number of threads (users)-1000 (number of users connected to the target) acceleration period (in seconds)-the time range for all requests to start. According to our configuration, one new thread will be started every 0.01 seconds, that is, 100 threads per second. Loop count-these 1000 threads perform test iterations back to back. Duration (seconds)-after acceleration, 1000 threads run continuously for 1800 seconds. We adopted the following scheme in the load test: add new pet owners to the system. View information about pet owners. Add a new pet to the system. View information about pets. Add information about access to the pet's access history. Update information about pets. Update information about pet owners. View owner information by searching for its name. View the information of all owners. How to measure memory waste? There are hundreds of tools in the industry that can display the amount of memory used. But we rarely encounter tools that can measure the amount of memory wasted due to programming inefficiency. HeapHero is a simple tool that analyzes heap dumps and tells you how much memory is wasted due to inefficient programming. During the test run, we captured the heap dump from the Spring Boot Pet Clinic application. We uploaded the captured heap dump to the HeapHero tool, which generated this beautiful report showing that 65% of memory was wasted due to inefficient programming. Yes, this is a simple raw application in which all best practices should be implemented, wasting 65% of memory on a well-known framework. Analyze memory waste from the report, you can notice the following: string duplication resulted in a waste of 15.6% of memory due to the inefficiency of the original array, 14.6% of memory was wasted due to repeated raw arrays, 14.3% of memory was wasted due to inefficient collection. Waste 12.1% of memory string repetition the main reason for wasting memory in this Spring startup application (and most enterprise applications) is string duplication. The report shows how much memory is wasted by repeating strings, what strings they are, who is creating them, and how to optimize them. You will notice that 15.6% of the memory is wasted due to duplicate strings. Notice that the 'Goldi' string has been created 207481 times. The "Visit" string has been created 132308 times. "access" is the description we mentioned in the test script. The "Banglore" string has been created 75374 times. "Banglore" is the city name we specified in the test script. '123123123 'has been created 37687 times. The "Mahesh" string has been created 37687 times. Obviously, "Goldi" is the name of the pet entered on the screen through the test script. "access" is the description entered on the screen through the test script. Again, it's value. But there is a question of why the same string object should be created thousands of times. We all know that strings are immutable (that is, once created, they cannot be modified). Given why create thousands of duplicate strings? The HeapHero tool also reports the code path that creates these duplicate strings. Another major reason for the waste of memory in spring boot pet clinic applications is the inefficiency of collection. The following is an excerpt from the HeapHero report: you will notice that 99% of the LinkedHashSet in memory does not have any elements. If there are no elements, why create a LinkedHashSet? When you create a new LinkedHashSet object, there is room for 16 elements in memory. Now all the space reserved for these 16 elements is wasted. This problem does not occur if LinedHashset is delayed initialization. Bad practice: best practice: again, another observation is that 68% of the ArrayList contains only 1 element. When you create an ArrayList object, there is room for 10 elements in memory. This means that space for nine elements is wasted in 88% of the ArrayList. If you can initialize ArrayList with capacity, you can avoid this problem. Bad practice: initialize the collection with default values. New ArrayList (); best practice: initialize the collection new ArrayList (1) with capacity; memory is not cheap one can argue that memory is so cheap, so why should I worry about it? It's a question of fairness. But in the era of cloud computing, my friend's memory is not cheap. There are four main computing resources: central processing unit, memory, network, and storage. Your application may run on hundreds of thousands of application servers running on an AWS EC2 instance. Of the above four computing resources, which one is saturated in the EC2 instance? For most applications, it is memory. The CPU is always 30-60%. There is always a lot of storage space. It is difficult to saturate the network (unless your application is streaming a large amount of video content). Therefore, for most applications, the first thing is memory saturation. Even if CPU, storage, and networking are underutilized, you will eventually configure more and more EC2 instances just because memory becomes saturated. This will increase your computational cost several times. On the other hand, due to inefficient programming, modern applications without exception waste 30% and 90% of their memory. Even on the Spring Boot pet clinic, which doesn't have much business logic, 65% of the memory is wasted. Actual enterprise applications will waste a similar amount, or even more. Therefore, if you can write memory-efficient code, it will reduce your computational costs. Because memory is the first resource to reach saturation, if memory consumption can be reduced, applications can be run on a smaller number of server instances. You may be able to reduce the number of servers by 30-40%. This means that your management can reduce data center (or cloud hosting provider) costs by 30% and 40%, plus maintenance and support costs. It can save millions / billions of yuan in costs. Conclusion in addition to reducing computing costs and writing memory-efficient code, your customer experience will also be better. If you can reduce the number of objects created to serve new incoming requests, the response time will be greatly reduced. Because fewer objects are created, fewer CPU cycles will be spent on object creation and garbage collection. Reducing response time will provide a better customer experience.
Add me VX:17324089390 to reply the keyword "test" to get limited software test learning materials.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.