mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
dynamically get open file limits from OS
This commit is contained in:
parent
3deded28a5
commit
f1590801d4
5 changed files with 30 additions and 4 deletions
16
common/oslimits.go
Normal file
16
common/oslimits.go
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
func MaxOpenFileLimit() int {
|
||||||
|
var nofile syscall.Rlimit
|
||||||
|
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &nofile)
|
||||||
|
if err != nil {
|
||||||
|
return 1024
|
||||||
|
}
|
||||||
|
return int(nofile.Max)
|
||||||
|
}
|
||||||
9
common/oslimits_windows.go
Normal file
9
common/oslimits_windows.go
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
)
|
||||||
|
|
||||||
|
func MaxOpenFileLimit() int {
|
||||||
|
// From https://msdn.microsoft.com/en-us/library/kdfaxaay.aspx
|
||||||
|
return 512
|
||||||
|
}
|
||||||
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/kardianos/osext"
|
"github.com/kardianos/osext"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -236,9 +236,9 @@ func New(config *Config) (*Ethereum, error) {
|
||||||
logger.NewJSONsystem(config.DataDir, config.LogJSON)
|
logger.NewJSONsystem(config.DataDir, config.LogJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let the database take 3/4 of the max open files (TODO figure out a way to get the actual limit of the open files)
|
|
||||||
const dbCount = 3
|
const dbCount = 3
|
||||||
ethdb.OpenFileLimit = 128 / (dbCount + 1)
|
|
||||||
|
ethdb.OpenFileLimit = common.MaxOpenFileLimit() / (dbCount + 1)
|
||||||
|
|
||||||
newdb := config.NewDB
|
newdb := config.NewDB
|
||||||
if newdb == nil {
|
if newdb == nil {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package ethdb
|
package ethdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/compression/rle"
|
"github.com/ethereum/go-ethereum/compression/rle"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/logger/glog"
|
"github.com/ethereum/go-ethereum/logger/glog"
|
||||||
|
|
@ -10,7 +11,8 @@ import (
|
||||||
"github.com/syndtr/goleveldb/leveldb/opt"
|
"github.com/syndtr/goleveldb/leveldb/opt"
|
||||||
)
|
)
|
||||||
|
|
||||||
var OpenFileLimit = 64
|
|
||||||
|
var OpenFileLimit = common.MaxOpenFileLimit()
|
||||||
|
|
||||||
type LDBDatabase struct {
|
type LDBDatabase struct {
|
||||||
// filename for reporting
|
// filename for reporting
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue