Skip to content

Commit

Permalink
[Custom Patch] Check dstdir available space before starting new plot
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Steil committed May 20, 2021
1 parent 6db95ea commit 469043f
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/plotman/_tests/manager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def sched_cfg():
polling_time_s=2,
tmpdir_stagger_phase_major=3,
tmpdir_stagger_phase_minor=0,
tmpdir_max_jobs=3
tmpdir_max_jobs=3,
stop_when_dst_full=False
)

@pytest.fixture
Expand Down
3 changes: 1 addition & 2 deletions src/plotman/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ def archive(dir_cfg, all_jobs):
return(False, 'No free archive dirs found.')

archdir = ''
available = [(d, space) for (d, space) in archdir_freebytes.items() if
space > 1.2 * plot_util.get_k32_plotsize()]
available = [(d, space) for (d, space) in archdir_freebytes.items() if plot_util.enough_space_for_k32(space)]
if len(available) > 0:
index = min(dir_cfg.archive.index, len(available) - 1)
(archdir, freespace) = sorted(available)[index]
Expand Down
1 change: 1 addition & 0 deletions src/plotman/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class Scheduling:
tmpdir_stagger_phase_major: int
tmpdir_stagger_phase_minor: int
tmpdir_stagger_phase_limit: int = 1 # If not explicit, "tmpdir_stagger_phase_limit" will default to 1
stop_when_dst_full: bool = False

@attr.frozen
class Plotting:
Expand Down
19 changes: 11 additions & 8 deletions src/plotman/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,24 @@ def maybe_start_new_plot(dir_cfg, sched_cfg, plotting_cfg):
rankable = [ (d, phases[0]) if phases else (d, job.Phase(known=False))
for (d, phases) in eligible ]

if not eligible:
# Select the dst dir least recently selected
dst_dir = dir_cfg.get_dst_directories()

dir2ph = { d:ph for (d, ph) in dstdirs_to_youngest_phase(jobs).items()
if d in dst_dir and ph is not None and plot_util.is_valid_plot_dst(d, sched_cfg, jobs)}
unused_dirs = [d for d in dst_dir if d not in dir2ph.keys() and plot_util.is_valid_plot_dst(d, sched_cfg, jobs)]

if not unused_dirs and not dir2ph:
wait_reason = 'no eligible dstdirs'
elif not eligible:
wait_reason = 'no eligible tempdirs (%ds/%ds)' % (youngest_job_age, global_stagger)
else:
# Plot to oldest tmpdir.
tmpdir = max(rankable, key=operator.itemgetter(1))[0]

# Select the dst dir least recently selected
dst_dir = dir_cfg.get_dst_directories()

if dir_cfg.dst_is_tmp():
dstdir = tmpdir
else:
dir2ph = { d:ph for (d, ph) in dstdirs_to_youngest_phase(jobs).items()
if d in dst_dir and ph is not None}
unused_dirs = [d for d in dst_dir if d not in dir2ph.keys()]
dstdir = ''
if unused_dirs:
dstdir = random.choice(unused_dirs)
else:
Expand Down
18 changes: 18 additions & 0 deletions src/plotman/plot_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import re
import shutil

from plotman import job

GB = 1_000_000_000

def df_b(d):
Expand All @@ -13,6 +15,22 @@ def df_b(d):
def get_k32_plotsize():
return 108 * GB

def is_valid_plot_dst(d, sched_cfg, all_jobs):
if sched_cfg.stop_when_dst_full:
space = df_b(d)
# Subtract space for current jobs which will be moved to the dir
# Note: This is underestimates the free space available when a
# job is in phase 4 since the plot is partially moved to dst,
# once phase 4 is complete a new plot will eventually kick off
jobs_to_dstdir = job.job_phases_for_dstdir(d, all_jobs)
space -= len(jobs_to_dstdir) * get_k32_plotsize()
return enough_space_for_k32(space)
return True

def enough_space_for_k32(b):
'Determine if there is enough space for a k32 given a number of free bytes'
return b > 1.2 * get_k32_plotsize()

def human_format(num, precision):
magnitude = 0
while abs(num) >= 1000:
Expand Down
2 changes: 1 addition & 1 deletion src/plotman/plotman.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def main():
csv_exporter.export(logfilenames, args.save_to)

else:
jobs = Job.get_running_jobs(cfg.directories.log())
jobs = Job.get_running_jobs(cfg.directories.log)

# Status report
if args.cmd == 'status':
Expand Down
4 changes: 4 additions & 0 deletions src/plotman/resources/plotman.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ scheduling:
# How often the daemon wakes to consider starting a new plot job, in seconds.
polling_time_s: 20

# Stop initiating new plots when a dst is full, default to False since
# archiving job should move other plots before plotting is completed
stop_when_dst_full: False


# Plotting parameters. These are pass-through parameters to chia plots create.
# See documentation at
Expand Down

0 comments on commit 469043f

Please sign in to comment.