@@ -143,7 +143,7 @@ var (
143143 CacheFlag = cli.IntFlag {
144144 Name : "cache" ,
145145 Usage : "Megabytes of memory allocated to internal caching (min 16MB / database forced)" ,
146- Value : 0 ,
146+ Value : 128 ,
147147 }
148148 BlockchainVersionFlag = cli.IntFlag {
149149 Name : "blockchainversion" ,
@@ -527,6 +527,22 @@ func MakeGenesisBlock(ctx *cli.Context) string {
527527 return string (data )
528528}
529529
530+ // MakeDatabaseHandles raises out the number of allowed file handles per process
531+ // for Geth and returns half of the allowance to assign to the database.
532+ func MakeDatabaseHandles () int {
533+ if err := raiseFdLimit (2048 ); err != nil {
534+ Fatalf ("Failed to raise file descriptor allowance: %v" , err )
535+ }
536+ limit , err := getFdLimit ()
537+ if err != nil {
538+ Fatalf ("Failed to retrieve file descriptor allowance: %v" , err )
539+ }
540+ if limit > 2048 { // cap database file descriptors even if more is available
541+ limit = 2048
542+ }
543+ return limit / 2 // Leave half for networking and other stuff
544+ }
545+
530546// MakeAccountManager creates an account manager from set command line flags.
531547func MakeAccountManager (ctx * cli.Context ) * accounts.Manager {
532548 // Create the keystore crypto primitive, light if requested
@@ -649,6 +665,7 @@ func MakeSystemNode(name, version string, extra []byte, ctx *cli.Context) *node.
649665 FastSync : ctx .GlobalBool (FastSyncFlag .Name ),
650666 BlockChainVersion : ctx .GlobalInt (BlockchainVersionFlag .Name ),
651667 DatabaseCache : ctx .GlobalInt (CacheFlag .Name ),
668+ DatabaseHandles : MakeDatabaseHandles (),
652669 NetworkId : ctx .GlobalInt (NetworkIdFlag .Name ),
653670 AccountManager : accman ,
654671 Etherbase : MakeEtherbase (accman , ctx ),
@@ -763,9 +780,10 @@ func SetupVM(ctx *cli.Context) {
763780func MakeChain (ctx * cli.Context ) (chain * core.BlockChain , chainDb ethdb.Database ) {
764781 datadir := MustMakeDataDir (ctx )
765782 cache := ctx .GlobalInt (CacheFlag .Name )
783+ handles := MakeDatabaseHandles ()
766784
767785 var err error
768- if chainDb , err = ethdb .NewLDBDatabase (filepath .Join (datadir , "chaindata" ), cache ); err != nil {
786+ if chainDb , err = ethdb .NewLDBDatabase (filepath .Join (datadir , "chaindata" ), cache , handles ); err != nil {
769787 Fatalf ("Could not open database: %v" , err )
770788 }
771789 if ctx .GlobalBool (OlympicFlag .Name ) {
0 commit comments