Skip to content

Commit

Permalink
Merge pull request meshplus#120 from meshplus/perf/raise-ulimit
Browse files Browse the repository at this point in the history
perf(app):raise ulimit
  • Loading branch information
0xforever9 authored Jul 21, 2020
2 parents 790c633 + 1c337c0 commit e20c0e3
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions internal/app/bitxhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package app
import (
"context"
"fmt"
"syscall"
"time"

"github.com/common-nighthawk/go-figure"
"github.com/ethereum/go-ethereum/common/fdlimit"
"github.com/meshplus/bitxhub-kit/types"
"github.com/meshplus/bitxhub/internal/executor"
"github.com/meshplus/bitxhub/internal/ledger"
Expand Down Expand Up @@ -205,6 +207,11 @@ func NewTesterBitXHub(rep *repo.Repo) (*BitXHub, error) {
}

func (bxh *BitXHub) Start() error {

if err := bxh.raiseUlimit(2048); err != nil {
return fmt.Errorf("raise ulimit: %w", err)
}

if !bxh.repo.Config.Solo {
if err := bxh.PeerMgr.Start(); err != nil {
return fmt.Errorf("peer manager start: %w", err)
Expand Down Expand Up @@ -280,3 +287,21 @@ func (bxh *BitXHub) printLogo() {
}
}
}

func (bxh *BitXHub) raiseUlimit(limitNew uint64) error {
_, err := fdlimit.Raise(limitNew)
if err != nil {
return err
}

var limit syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
return err
}

if limit.Cur != limitNew && limit.Cur != limit.Max {
return fmt.Errorf("failed to raise ulimit")
}

return nil
}

0 comments on commit e20c0e3

Please sign in to comment.