Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically clean up AWS Batch temporary folder #1450

Closed
sminot opened this issue Jan 9, 2020 · 7 comments
Closed

Automatically clean up AWS Batch temporary folder #1450

sminot opened this issue Jan 9, 2020 · 7 comments

Comments

@sminot
Copy link

sminot commented Jan 9, 2020

New feature

When using the awsbatch executor, there is no reason to keep files in the temporary directory after a process has finished execution. I suggest that Nextflow automatically delete all of the files in the ephemeral temporary directory after execution.

The accumulation of large files in the temporary directory of AWS Batch workers can cause big problems when they fill up the partition, effectively blocking an entire workflow. While it is possible to write a workflow which fixes this with afterScript "rm -r *", such a solution is entirely incompatible with any executor which uses a shared filesystem (local, SLURM, etc.).

Usage scenario

The main usage case is a user who is using the awsbatch executor. The desired scenario is that when they run a workflow, the usage partition used for scratch space will be kept to a minimum, storing only those files which are being used by actively running tasks. The current scenario is that long-running workflows will accumulate files in the scratch partition, eventually filling up and completely locking up those workers.

For the developer, this improvement would also mean that I can take out the afterScript "rm -r *" command in my processes, which will make them easily compatible with local execution modes, and which will also protect me against running out of space in the scratch partition on AWS Batch.

Suggest implementation

I regret to say that I do not understand the Nextflow codebase enough to suggest the most efficient implementation of this idea.

@pditommaso
Copy link
Member

This looks a duplicate of #452, for which there's no a quick solution tho the plan is to tackle in a more general manner at some point.

Have you taken into consideration using a S3 lifecycle policy to cleanup the bucket? it works beautifully

https://docs.aws.amazon.com/AmazonS3/latest/user-guide/create-lifecycle.html

@sminot
Copy link
Author

sminot commented Jan 13, 2020

My apologies, I was hoping to explain how this is a really different issue and concern.

There is a group of files staged to the working instance in an ephemeral scratch directory which is distinct from the S3 bucket used for the working directory. That's the set of files I want to target in this issue.

Does that help explain?

@sminot
Copy link
Author

sminot commented Jan 13, 2020

If it were possible to write this code in the process, it would constitute a reasonable solution:

if executor == 'awsbatch':
    afterScript "rm -r *" 

Note that this would not impact any files in the work directory

@pditommaso
Copy link
Member

I see. But that's already done, if you look at the command launcher you will see

on_exit() {
    exit_status=${nxf_main_ret:=$?}
    printf $exit_status | /home/ec2-user/miniconda/bin/aws --region eu-west-1 s3 cp --only-show-errors - s3://nf-course/work/ad/84c59e22b4b0d4dd038b35e9885a05/.exitcode || true
    set +u
    [[ "$tee1" ]] && kill $tee1 2>/dev/null
    [[ "$tee2" ]] && kill $tee2 2>/dev/null
    [[ "$ctmp" ]] && rm -rf $ctmp || true
    rm -rf $NXF_SCRATCH || true
    exit $exit_status
}

@sminot
Copy link
Author

sminot commented Jan 13, 2020 via email

@pditommaso
Copy link
Member

it should be invoked in all cases.

@sminot
Copy link
Author

sminot commented Jan 13, 2020

Ok, in that case I'm all set!

Thank you for your quick and helpful response!

@sminot sminot closed this as completed Jan 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants