Skip to content

Commit 3fc0b33

Browse files
anitakarleahecoletswast
authored
Add dag that clears file system caches on scheduler and workers. (GoogleCloudPlatform#5514)
This dag allows to decrease memory usage of worker and scheduler pods on k8s. Co-authored-by: Leah E. Cole <6719667+leahecole@users.noreply.github.com> Co-authored-by: Tim Swast <swast@google.com>
1 parent cfdac81 commit 3fc0b33

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""A dag that prevents memory leaks on scheduler and workers."""
16+
from datetime import timedelta
17+
import os
18+
19+
import airflow
20+
from airflow import DAG
21+
from airflow.operators.bash_operator import BashOperator
22+
23+
dag = DAG(
24+
'clear_file_system_caches_dag',
25+
description='clear file system caches on scheduler and workers',
26+
schedule_interval='*/30 * * * *',
27+
dagrun_timeout=timedelta(minutes=20),
28+
start_date=airflow.utils.dates.days_ago(1),
29+
catchup=False)
30+
31+
# clean file system cache on scheduler
32+
os.system('echo 3 | sudo tee /proc/sys/vm/drop_caches')
33+
34+
# clean file system cache on one of workers
35+
t1 = BashOperator(
36+
task_id='clear_caches',
37+
bash_command='echo 3 | sudo tee /proc/sys/vm/drop_caches',
38+
dag=dag,
39+
depends_on_past=False)
40+
41+
t1
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import internal_unit_testing
16+
17+
18+
def test_dag_import():
19+
"""Test that the DAG file can be successfully imported.
20+
This tests that the DAG can be parsed, but does not run it in an Airflow
21+
environment. This is a recommended confidence check by the official Airflow
22+
docs: https://airflow.incubator.apache.org/tutorial.html#testing
23+
"""
24+
from . import simple as module
25+
internal_unit_testing.assert_has_valid_dag(module)

0 commit comments

Comments
 (0)