From 7638423f850340ccce50f5c673c543df305a9d78 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Fri, 13 Nov 2015 19:34:20 -0800 Subject: [PATCH] storage/backend: support MAP_POPULATE for unix This adds build constraints in order to pass memory-map flags to bolt.Option. If backend package passes syscall.MAP_POPULATE flag, the boltdb does read-ahead which speeds up entire-database read, which then leads to faster storage Restore. Benchmark result shows for 4GB, it opens and loads 6x faster in SSD, and 12x faster in HDD. For 2GB, 1.6x faster with MAP_POPULATE in SSD. --- storage/backend/backend.go | 2 +- storage/backend/boltoption_darwin.go | 19 ++++++++++++++++ storage/backend/boltoption_freebsd.go | 19 ++++++++++++++++ storage/backend/boltoption_unix.go | 31 +++++++++++++++++++++++++++ storage/backend/boltoption_windows.go | 21 ++++++++++++++++++ 5 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 storage/backend/boltoption_darwin.go create mode 100644 storage/backend/boltoption_freebsd.go create mode 100644 storage/backend/boltoption_unix.go create mode 100644 storage/backend/boltoption_windows.go diff --git a/storage/backend/backend.go b/storage/backend/backend.go index b8a2f2ad4..608752452 100644 --- a/storage/backend/backend.go +++ b/storage/backend/backend.go @@ -61,7 +61,7 @@ func New(path string, d time.Duration, limit int) Backend { } func newBackend(path string, d time.Duration, limit int) *backend { - db, err := bolt.Open(path, 0600, nil) + db, err := bolt.Open(path, 0600, boltOpenOptions) if err != nil { log.Panicf("backend: cannot open database at %s (%v)", path, err) } diff --git a/storage/backend/boltoption_darwin.go b/storage/backend/boltoption_darwin.go new file mode 100644 index 000000000..856febdf0 --- /dev/null +++ b/storage/backend/boltoption_darwin.go @@ -0,0 +1,19 @@ +// Copyright 2015 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package backend + +import "github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt" + +var boltOpenOptions *bolt.Options = nil diff --git a/storage/backend/boltoption_freebsd.go b/storage/backend/boltoption_freebsd.go new file mode 100644 index 000000000..856febdf0 --- /dev/null +++ b/storage/backend/boltoption_freebsd.go @@ -0,0 +1,19 @@ +// Copyright 2015 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package backend + +import "github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt" + +var boltOpenOptions *bolt.Options = nil diff --git a/storage/backend/boltoption_unix.go b/storage/backend/boltoption_unix.go new file mode 100644 index 000000000..bd676a524 --- /dev/null +++ b/storage/backend/boltoption_unix.go @@ -0,0 +1,31 @@ +// Copyright 2015 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build linux solaris + +package backend + +import ( + "syscall" + + "github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt" +) + +// syscall.MAP_POPULATE on linux 2.6.23+ does sequential read-ahead +// which can speed up entire-database read with boltdb. We want to +// enable MAP_POPULATE for faster key-value store recovery in storage +// package. If your kernel version is lower than 2.6.23 +// (https://github.com/torvalds/linux/releases/tag/v2.6.23), mmap might +// silently ignore this flag. Please update your kernel to prevent this. +var boltOpenOptions = &bolt.Options{MmapFlags: syscall.MAP_POPULATE} diff --git a/storage/backend/boltoption_windows.go b/storage/backend/boltoption_windows.go new file mode 100644 index 000000000..1b9ce9471 --- /dev/null +++ b/storage/backend/boltoption_windows.go @@ -0,0 +1,21 @@ +// Copyright 2015 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package backend + +import "github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt" + +// TODO: support syscall.MAP_POPULATE in windows. +// Need upstream patch from boltdb/bolt. +var boltOpenOptions *bolt.Option = nil