in3rsha / bitcoin-utxo-dump

Get a list of UTXOs (unspent transaction outputs) from your Bitcoin Core client.
MIT License
241 stars 103 forks source link

Update utxodump.go with ulimit macOS fix #9

Closed beiex closed 4 years ago

beiex commented 4 years ago

Turns out that with or without write buffer there is a limit on file operations per second. In macOS it is set to 1024 by default and on linux to the max 4096 by default.

So to run this correctly on macOS

ulimit -n 4096; go run bitcoin-utxo-dump.go; ulimit -n 1024

I tried to implement this in code

import "runtime" // Check OS type for file-handler limitations

// Check if OS type is Mac OS, then increase ulimit -n to 4096 filehandler during runtime and reset to 1024 at the end
// Mac OS standard is 1024
// Linux standard is already 4096 wich is also "max" for more edit etc/security/limits.conf
    if runtime.GOOS == "darwin" {
             cmd2 := exec.Command("ulimit", "-n", "4096")
             fmt.Println("setting ulimit 4096\n", err)
             _, err2 := cmd2.Output()
             if err2 != nil {
                 fmt.Println("setting new ulimit failed with %s\n", err)
             }
             defer exec.Command("ulimit", "-n", "1024")
    }

don't know if that's completely correct but seems to be working for me, still there might be a more elegant solution..

in3rsha commented 4 years ago

Thank you :)