Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fsync is slow on mac os #28754

Open
rjl493456442 opened this issue Jan 2, 2024 · 0 comments
Open

Fsync is slow on mac os #28754

rjl493456442 opened this issue Jan 2, 2024 · 0 comments
Labels

Comments

@rjl493456442
Copy link
Member

rjl493456442 commented Jan 2, 2024

According to issue golang/go#43342, file.Sync operation is extremely slow.

After investigating it a bit further, I realized that for file.Sync on mac os X, it's actually a fcntl(F_FULLFSYNC) because OS X and some versions of ext3 have an fsync that doesn't really flush to disk. OS X requires fcntl(F_FULLFSYNC) to flush to disk

Apparently, F_FULLFSYNC is a lot slower than a normal file.Sync on the other platforms.

func TestFooBar(t *testing.T) {
	filename := "go.txt"
	os.Remove(filename)
	fp, err := os.OpenFile(filename, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
	if err != nil {
		panic(err)
	}
	count := 1000
	for i := 0; i < count; i++ {
		var err error
		s := fmt.Sprintf("%010d\n", i)
		_, err = fp.WriteString(s)
		if err != nil {
			panic(err)
		}
		err = fp.Sync()
		if err != nil {
			panic(err)
		}
	}
	fp.Close()
}

1000 file sync takes 18s on my laptop (Apple M1 Pro)


Inside of Geth, we use freezer as the chain data backend and state diff backend if path scheme is used, which always do a file.Sync after applying writes. Namely it can cause performance degradation on Mac OS X.

If the node has finished the initial state sync, then capturing up the progress made in the network should be sufficient even with slow FSYNC, but might be a disaster if people want to do a full-sync on Mac OS X.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant