In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
MMAP document accelerated reading and writing tips are what, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
In addition to read and write, the process can also use mmap for file mapping when reading and writing data, as shown in the following figure:
As you can see, after the disk file is loaded into memory, you need to perform another copy operation.
If you use mmap, the disk file is loaded directly into user space, that is, the dark yellow part of the image above, and the process can manipulate the file directly through the pointer.
It looks like mmap is missing a copy, which is theoretically faster than read. However, calling mmap does not actually load files into memory, so a large number of interrupts are triggered during reading and writing (especially large files), resulting in slow performance, even using madvise call acceleration parameters. Here is a small way to read the first byte on each page of the file:
In the above code, we use two 8m files with exactly the same data to see what happens after preloading and not preloading:
You can see that preloading calls are significantly faster than not executing them. Is it effective to use madvise acceleration? Take a look:
There is no effect, but the speed of preloading calls is significantly faster than that of none. There is a slight deviation in the time for the program to read the file twice because of the electrical characteristics of cpu and memory itself.
Robustness
When using mmap for shared mapping, multiple processes can manipulate the same file. A typical scenario is to use vim to edit the file, and then use cat to view the file, as shown below:
At this point, there will be a competitive scenario. Processes 1 and 2 can only see their own private virtual addresses, respectively. You need to implement the locking mechanism by the caller. For more information, please see the copy-on-write mechanism.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.