In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
The content of this article mainly focuses on the read / write optimization scheme of hot data under big data scene. The content of the article is clear and well-organized. It is very suitable for beginners to learn and is worth reading. Interested friends can follow the editor to read together. I hope you can get something through this article!
Daring to take the first step is often the beginning of success.
I. brief introduction of caching technology
1. Caching refers to storing frequently accessed hot spot data in the place closest to the calculation, so as to facilitate the system to respond quickly. Eg: static resources can be cached on CDN (Content Delivery NetWork, the content distribution network, the nearest computer room to the telecom operator). It can also be cached to the reverse proxy server. Unlike CDN, the reverse proxy server belongs to the internal computer room of the enterprise, which blocks the front end of the application server. 2. Caching is divided into local caching and distributed caching, such as Ehcache, MemCache and Redis3, caching mainly solves the following problems: alleviating the load pressure on application systems or relational databases and improving system throughput 4. Local caching: sharing heap space in the same JVM process, providing off-heap (out-of-heap memory) from Ehcache3.x, and out-of-heap memory can reduce GC times or pause time. More memory space can be expanded and used. 5. Distributed cache: due to the limited capacity of local cache, it is impossible to scale out, so it is necessary to evolve from local cache architecture to distributed cache architecture. Common distributed caches include Redis and MemCache.
II. Practical application scenarios
1. Based on the multi-write and multi-read scheme of Redis cluster, the multi-level Cache scheme of Zookeeper2 and LocalCache combined with Redis cluster can be used to ensure the data consistency of multi-write.
Third, expand, in-depth understanding of JVM in-heap memory and out-of-heap memory (reprint)
1. What is in-heap memory? during the execution of the Java program, the Java virtual machine divides the memory part it manages in the main memory into multiple areas, each of which stores different types of data. The following figure shows the main memory partitions when the java virtual machine is running:
The largest portion of these partitions that take up the most memory space is called "heap", which is what we call on-heap memory. The "heap" in the java virtual machine is primarily an instance of all objects. This area is created when the java virtual machine starts, is shared by all threads, and is also the main working area of the garbage collector, so this area is also called the "GC heap" (Garbage Collected Heap) in addition to the "in-heap memory".
1.1.The memory in the heap is the main working area of the java garbage collector. In order to improve the efficiency of garbage collection, the memory in the heap is divided into the new generation, the old age and the permanent generation. In the new generation of memory, according to the 8:1:1 ratio (the default allocation ratio of the java virtual machine is 8:1:1, which can also be customized), it is divided into three areas: Eden, Survivor1 and Survivor2. When performing garbage collection algorithms, different collection algorithms will have different effects on memory areas. However, most of the recycling algorithms will cause physical discontinuity of memory space in the heap. Here is an example of the most basic garbage collection algorithm, the tag-cleanup algorithm:
As you can see, the memory area produces a lot of discontiguous memory space after garbage collection. Therefore, the area of in-heap memory in the java virtual machine is only logically continuous and does not guarantee physical continuity. Therefore, the operating system can not directly get the correct address of the data stored in the memory area of the heap in the main memory. At a certain point in time, the Java virtual machine performs a thorough garbage collection (full gc). When fully reclaimed, the garbage collector scans all allocated in-heap memory completely, and during the scan, most running java threads are temporarily stopped. This means that the impact of such a garbage collection on Java applications is proportional to the amount of data stored in the heap memory, and excessive in-heap memory will affect the performance of Java applications.
two。 Out of heap memory (off-heap memory)
Generation of out-of-heap memory in order to solve the problem of long GC pause caused by excessive in-heap memory and the unknowability of operating system to in-heap memory, java virtual machine developed out-of-heap memory (off-heap memory). Out-of-heap memory means that instances of some objects are allocated to areas of memory other than the memory in the Java virtual machine heap, which is directly managed by the operating system (not the virtual machine). The result is to maintain a small heap to reduce the impact of garbage collection on the application. At the same time, because this part of the area is directly managed by the operating system, other processes and devices (such as GPU) can access it directly through the operating system, reducing the process of copying memory data from the virtual machine. 2.2 allocation of out-of-heap memory java provides the ByteBuffer class in the NIO package to access out-of-heap memory. The following figure shows the hierarchical inheritance relationship of ByteBuffer in the NIO package
You can directly open up a specified size of external memory in the following way: import sun.nio.ch.DirectBuffer;import java.nio.ByteBuffer;public class TestDirectByteBuffer {public static void main (String [] args) throws Exception {while (true) {ByteBuffer buffer = ByteBuffer.allocateDirect (10 * 1024 * 1024);}} so we open up a piece of out-of-heap memory with a size of 10m.
3. Advantages and disadvantages of out-of-heap memory and its relationship with in-heap memory
3.1 advantages and disadvantages of out-of-heap memory: advantages: it can easily open up a lot of memory space independently, has good scalability to large memory, reduces the system pause time caused by garbage collection and is directly controlled by the operating system, can be directly accessed by other processes and devices, reducing the original process of copying from virtual machines is especially suitable for those with less allocation times. The disadvantage of frequent read and write operations: memory leaks are easy to occur, and it is difficult to troubleshoot the data structure of out-of-heap memory is not intuitive, when storing complex objects, it will waste a lot of time to serialize them. Connection between in-heap memory and out-of-heap memory: although out-of-heap memory itself is not subject to garbage collection algorithm, because it was created by ByteBuffer, the buffer itself as an instantiated object, its own information (such as the starting address of main memory outside the heap, etc.) must be stored in in-heap memory, as shown in the following figure.
When the buffer object instance stored in the heap memory is reclaimed by the garbage collection algorithm, the out-of-heap memory area corresponding to the buffer is also released. Thank you for your reading. I believe you have a certain understanding of the "read / write optimization scheme of hot data under the big data scene". Go and practice it. If you want to know more about it, you can follow the website! The editor will continue to bring you better articles!
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.