Skip to content

Commit

Permalink
Add uci.Engine.Renice()
Browse files Browse the repository at this point in the history
This change adds a Renice() method receiver to uci.Engine. This
enables callers to specify that the engine should be run at a lower
priority. In practice this is helpful in improving system
responsiveness when running the engine with
high thread counts and/or larger hash sizes.

(cherry picked from commit 92c1903)
  • Loading branch information
mikeb26 committed May 25, 2023
1 parent 5a91e1f commit f1dd178
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion uci/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"os"
"os/exec"
"strconv"
"sync"
)

Expand Down Expand Up @@ -55,10 +56,20 @@ func New(path string, opts ...func(e *Engine)) (*Engine, error) {
for _, opt := range opts {
opt(e)
}
go e.cmd.Run()
err = e.cmd.Start()
if err != nil {
return nil, fmt.Errorf("uci: failed to start executable %s: %w", path, err)
}
go e.cmd.Wait()
return e, nil
}

func (e *Engine) Renice() error {
cmd := exec.Command("renice", "-n", "19", "-p", strconv.FormatInt(int64(e.cmd.Process.Pid), 10))

return cmd.Run()
}

// ID returns the id values returned from the most recent CmdUCI invocation. It includes
// key value data such as the following:
// id name Stockfish 12
Expand Down

0 comments on commit f1dd178

Please sign in to comment.