Automating Chia Plotting on Ubuntu

Chia plotting is both CPU and IO intensive. You can run several plots in parallel until you hit a bottleneck. Plotting in parallel will increase the processing time, but also the throughput. The goal is to maximize the number of plots per day. There’s a sweet spot after which adding more processes will decrease the throughput. Therefore, it’s important not to exceed this limit.

The following bash script is a primitive mechanism to maintain the optimal number of plotting processes running. It starts a new processes after a previous completes:

#!/usr/bin/bash

MAX=$1

if [ -z "$MAX" ]
then
  echo MAX not set
  exit 1
fi

MEMORY=28000
BASE=/home/x/chia-blockchain
BIN=$BASE/venv/bin
TEMP1=/big1
TEMP2=/big1/s1
DESTINATION='/media/x/My Book Duo/chia-farms'
KEY=1111111111
THREADS=2

current=`ps -ef | grep chia | grep plots | grep create | wc -l`

if [ "$current" -ge "$MAX" ]; then
  exit
fi

memory_per_plot=$((MEMORY/MAX))

cd $BASE
. ./activate

$BIN/python $BIN/chia plots create -k32 -n1 -t$TEMP1 -2$TEMP2 -d"$DESTINATION" -b$memory_per_plot -u128 -r$THREADS -a$KEY

The command line argument is the maximum number of plot processes.

The script is meant to be scheduled in crontab:

25,55 * * * * /home/x/chia-blockchain/create_plot 4 >> /home/x/chia-blockchain/create_plot.log 2>&1

You’d need to customize the following variables:

MEMORY: total mebibytes allocated for plotting. The script calculates the memory per process to avoid swapping.
BASE: Chia software installation directory
TEMP1, TEMP2: temporary directories for plotting, optimally on NVMe SSDs. It requires ~300GB per plotting process.
DESTINATION: farming directory, usually on cheap storage
KEY: wallet key
THREADS: the number of threads per plotting process

You can also use this script to find out the optimal degree of parallelism for your system.

After scheduling the script and attaching enough cheap storage for farming you can go away on vacation and hopefully find some coins when you get back ๐Ÿ™‚

Thanks for sharing

Nenad Noveljic

3 Comments

  1. Hi Nenad! This is very helpful script. Thanks a lot for posting it! I do have a question if you don’t mind: In crobtab, what does “25, 55” in the beginning stand for? Not familiar with it, so I google it, seems the 2nd one is hour and the value suppose to be 0-23. So why 55 here?
    Another thought, it’d be better if you can add a loop with logics that detects CPU usage, available ram, available space on temp folder and destination folder, if NONE of them is lower than specified number, add a new plot; otherwise wait for a few mins. By this way, there are two benefits: no need to specify the max number of plot process and no need to use crontab.

    Thanks again and cheers!
    -oldcotton

    • Never mind, I figured out it’s for checking twice every hour at 25 and 55. ๐Ÿ™‚

      • Yes, the check is done twice per hour.

        Check out Plotman. It seems to be a sophisticated framework which parses the log files and allocates resources more dynamically. My goal was to come up with something quickly and start farming while the total network size is still rather small.

        If you take care of the following, you should be fine:
        – leave some RAM for other processes on the server, like OS and farming, if done on the same node.
        – plotting SSD needs to be large enough (~300GB per process).
        – keep processes apart so that don’t saturate the farming storage.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.