Merge pull request #434 from liori/tmpfs_workspace

tmpfs_workspace: Plugin for having workspace on tmpfs for speed
This commit is contained in:
Anders Ingemann 2018-01-20 14:12:29 +01:00 committed by GitHub
commit 10f061ad13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 85 additions and 0 deletions

View file

@ -0,0 +1,18 @@
tmpfs workspace
---------------
The ``tmpfs workspace`` plugin mounts a tmpfs filesystem for the
workspace temporary files. This is useful when the workspace directory
is placed on a slow medium (e.g. a hard disk drive), the build process
performs lots of local I/O (e.g. building a vagrant box), and there is
enough RAM to store data necessary for the build process. For example,
the ``stretch-vagrant.yml`` manifest file from the examples directory
takes 33 minutes to build on the plugin author's home server. Using
this plugin reduces this time to 3 minutes at the cost of 1.2GB of
additional RAM usage.
Settings
~~~~~~~~
This plugin has no settings. To enable it add ``"tmpfs_workspace":{}``
to the plugin section of the manifest.

View file

@ -0,0 +1,17 @@
from bootstrapvz.common.tasks.workspace import CreateWorkspace, DeleteWorkspace
from tasks import CreateTmpFsWorkspace, MountTmpFsWorkspace, UnmountTmpFsWorkspace, DeleteTmpFsWorkspace
def resolve_tasks(taskset, manifest):
taskset.discard(CreateWorkspace)
taskset.discard(DeleteWorkspace)
taskset.add(CreateTmpFsWorkspace)
taskset.add(MountTmpFsWorkspace)
taskset.add(UnmountTmpFsWorkspace)
taskset.add(DeleteTmpFsWorkspace)
def resolve_rollback_tasks(taskset, manifest, completed, counter_task):
counter_task(taskset, MountTmpFsWorkspace, UnmountTmpFsWorkspace)
counter_task(taskset, CreateTmpFsWorkspace, DeleteTmpFsWorkspace)

View file

@ -0,0 +1,50 @@
from os import makedirs, rmdir
from bootstrapvz.base import Task
from bootstrapvz.common.tasks.workspace import CreateWorkspace, DeleteWorkspace
from bootstrapvz.common import phases
from bootstrapvz.common.tools import log_check_call
class CreateTmpFsWorkspace(Task):
description = 'Creating directory for tmpfs-based workspace'
phase = phases.preparation
@classmethod
def run(cls, info):
makedirs(info.workspace)
class MountTmpFsWorkspace(Task):
description = 'Mounting tmpfs-based workspace'
phase = phases.preparation
# CreateWorkspace is explicitly skipped (see the plugin's resolve_task function). Several other tasks
# depend on CreateWorkspace to put their own files inside the workspace. We position MountTmpFs before
# CreateWorkspace to leverage these dependencies. See also UnmountTmpFs/DeleteWorkspace below.
successors = [CreateWorkspace]
predecessors = [CreateTmpFsWorkspace]
@classmethod
def run(cls, info):
log_check_call(['mount', '--types', 'tmpfs', 'none', info.workspace])
class UnmountTmpFsWorkspace(Task):
description = 'Unmounting tmpfs-based workspace'
phase = phases.cleaning
predecessors = [DeleteWorkspace]
@classmethod
def run(cls, info):
log_check_call(['umount', info.workspace])
class DeleteTmpFsWorkspace(Task):
description = 'Deleting directory for tmpfs-based workspace'
phase = phases.cleaning
predecessors = [UnmountTmpFsWorkspace]
@classmethod
def run(cls, info):
rmdir(info.workspace)