app/vmselect/netstorage: hint the OS that tmpBlocksFile is read almost sequentially

This became the case after b7ee2e7af2 .
This commit is contained in:
Aliaksandr Valialkin 2019-09-30 00:11:01 +03:00
parent c1d3705be0
commit 4e9e1ca0f7
4 changed files with 11 additions and 8 deletions

View file

@ -4,6 +4,6 @@ import (
"os"
)
func mustFadviseRandomRead(f *os.File) {
func mustFadviseSequentialRead(f *os.File) {
// Do nothing :)
}

View file

@ -7,9 +7,9 @@ import (
"golang.org/x/sys/unix"
)
func mustFadviseRandomRead(f *os.File) {
func mustFadviseSequentialRead(f *os.File) {
fd := int(f.Fd())
if err := unix.Fadvise(int(fd), 0, 0, unix.FADV_RANDOM|unix.FADV_WILLNEED); err != nil {
logger.Panicf("FATAL: error returned from unix.Fadvise(RANDOM|WILLNEED): %s", err)
if err := unix.Fadvise(int(fd), 0, 0, unix.FADV_SEQUENTIAL|unix.FADV_WILLNEED); err != nil {
logger.Panicf("FATAL: error returned from unix.Fadvise(SEQUENTIAL|WILLNEED): %s", err)
}
}

View file

@ -7,9 +7,9 @@ import (
"golang.org/x/sys/unix"
)
func mustFadviseRandomRead(f *os.File) {
func mustFadviseSequentialRead(f *os.File) {
fd := int(f.Fd())
if err := unix.Fadvise(int(fd), 0, 0, unix.FADV_RANDOM|unix.FADV_WILLNEED); err != nil {
logger.Panicf("FATAL: error returned from unix.Fadvise(RANDOM|WILLNEED): %s", err)
if err := unix.Fadvise(int(fd), 0, 0, unix.FADV_SEQUENTIAL|unix.FADV_WILLNEED); err != nil {
logger.Panicf("FATAL: error returned from unix.Fadvise(SEQUENTIAL|WILLNEED): %s", err)
}
}

View file

@ -125,7 +125,10 @@ func (tbf *tmpBlocksFile) Finalize() error {
if _, err := tbf.f.Seek(0, 0); err != nil {
logger.Panicf("FATAL: cannot seek to the start of file: %s", err)
}
mustFadviseRandomRead(tbf.f)
// Hint the OS that the file is read almost sequentiallly.
// This should reduce the number of disk seeks, which is important
// for HDDs.
mustFadviseSequentialRead(tbf.f)
return nil
}