ericaltendorf / plotman

Chia plotting manager
Apache License 2.0
909 stars 280 forks source link

Feature Request: Phase1 Renice #393

Open rdirocco opened 3 years ago

rdirocco commented 3 years ago

Feature Request

Support configurable Phase1 and Phase2/3/4 NICE levels in the config Ex:

plotting:
        k: 32
        e: False             # Use -e plotting option
        n_threads: 6         # Threads per job
        n_buckets: 128       # Number of buckets to split data into
        job_buffer: 4096     # Per job memory
        phase_1_nice: -19 #Launch Nice of Plotting Process
        phase_234_nice: 15 #Renice on completion of Phase1

On launch of plotting processes set NICE of -19, as per example At Phase 1 completion, renice PID of respective job to 15, as per example

Background:

much of my plotting load testing has lead me to the conclusion that over-subscription of machine cores (threads) at a near 2:1 ratio nets optimal parallel plotting, while sacrificing a bit of phase1 speed. The objective is to minimize the peak/valley behavior and fully utilize the compute resources available, within the limits of the storage. Phase1 is multi-threaded and compared to the other phases, extremely CPU bound. In the example configuration 32 threads would be allocated to Phase1 with an additional 11 threads for the jobs in phase2/3/4. , 43 threads allocated on 32 threads, roughly a 34% over subscription.

Example Hardware Config:

Ryzen 5950x (16c / 32t) 64GB DDR4-3600 4 x 1TB NVME TMP (mdadm raid-0, xfs, zram logdev, noatime mounts, etc) 1 x 500GB SSD Destination

Example Plotman config:

4 max before stage 2:0, 10 second scan, 10 minute stagger, 15 max plots, memory 4096, threads 8

Data:

Testing has shown that for all PIDs of jobs in Phase1, setting a nice of -19 and all other jobs at a default 15 ensures that adequate (all the things...) CPU resources are allocated to quickly progress the P1 jobs to a state where everyone gets their own single physical core in 2+. In ~24 hours of testing this has resulted in about an 8% gain in reduction of total plot time.

rdirocco commented 3 years ago

for anyone that cares to do the same, here is some bash that you can use, loop it, cron it, whatever


#!/bin/bash
main () {
        echo "Checking PIDs and Making Nice!"
        nice_p1
        nice_p234
}

function nice_p1 {
        jobs=($(plotman status | awk {'print $1" "$6'} | grep "1:" | awk {'print  $1'}))
        if [[ ${#jobs[@]} -gt 0 ]]
        then
                echo "- Jobs in Phase 1:"
                for i in $(echo ${jobs[@]}); do
                        pid=$(plotman details $i | grep "pid:" | cut -d ":" -f 2)
                        echo " -- PID: "$pid
                        echo " --- Checking NICE "
                        nice=$(ps --no-headers -o ni $pid)
                        if [[ $nice -ne -19 ]]
                        then
                                echo " ----"`renice --priority -19 --pid $pid`
                        else
                                echo " --- Good, continuing"
                        fi
                done
        fi
}

function nice_p234 {
        jobs=($(plotman status | awk {'print $1" "$6'} | grep -v "1:" | awk {'print  $1'} | tail -n +2))
        if [[ ${#jobs[@]} -gt 0 ]]
        then
                echo "- Jobs in Phase 2/3/4:"
                for i in $(echo ${jobs[@]}); do
                        pid=$(plotman details $i | grep "pid:" | cut -d ":" -f 2)
                        echo " -- PID: "$pid
                        echo " --- Checking Nice"
                        nice=$(ps --no-headers -o ni $pid)
                        if [[ $nice -ne 15 ]]
                        then
                                echo " ----"`renice --priority 15 --pid $pid`
                        else
                                echo " --- Good, continuing"
                        fi
                done
        fi
}

main"$@"
fer662 commented 3 years ago

@rdirocco so you run/cron this as root or what?

rdirocco commented 3 years ago

@fer662 you could run it as a cron or just an infinite loop, even if it's at a 1 minute cron, you'll still get things quickly as they spawn and as they exit phase1

fer662 commented 3 years ago

When i run as root the part that calls plotman looks for the config file in the root's user folders and it fails. did you just copy the config or you have a different result?

On Sat, May 15, 2021 at 11:47 AM Ryan DiRocco @.***> wrote:

@fer662 https://github.com/fer662 you could run it as a cron or just an infinite loop, even if it's at a 1 minute cron, you'll still get things quickly as they spawn and as they exit phase1

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ericaltendorf/plotman/issues/393#issuecomment-841669877, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACR7Y3PSLV3BNCE5HU35QTTN2CQNANCNFSM44Z743TQ .

MartinEderer commented 3 years ago

run it within the venv of chia (and plotman) run it with the user which also runs plotman (not root) change echo " ----"renice --priority -19 --pid $pid to echo " ----"sudo renice --priority -19 --pid $pid

run

fer662 commented 3 years ago

Won't it ask the password every few times it runs that way?

On Sat, May 15, 2021 at 12:21 PM Martin Ederer @.***> wrote:

run it within the venv of chia (and plotman) run it with the user which also runs plotman (not root) change echo " ----"renice --priority -19 --pid $pid to echo " ----"sudo renice --priority -19 --pid $pid

run

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ericaltendorf/plotman/issues/393#issuecomment-841679100, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACR7Y4HALR6UHKZ7UWLEIDTN2GQZANCNFSM44Z743TQ .

MartinEderer commented 3 years ago

true - you could allow the user to use renice. https://askubuntu.com/questions/564375/allow-users-to-set-higher-lower-nice-levels

altendky commented 3 years ago

Random tidbit, I'm not aware of any good reason to be running any Chia or plotman stuff as root.

rdirocco commented 3 years ago

@altendky very good point, in the reference system that this is used in, they are pxe-boot diskless systems with a minimal environment with no users, services, etc so it's all running as root. For any general use case running all the services, etc as root is not a recommended practice.