You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/09/07 10:41:26 UTC

[GitHub] [airflow] potiuk opened a new pull request #18054: Advises the kernel to not cache log files generated by Airflow

potiuk opened a new pull request #18054:
URL: https://github.com/apache/airflow/pull/18054


   Extends the standard python logging.FileHandler with advise to the
   Kernel to not cache the file in PageCache when it is written. While
   there is nothing wrong with such cache (it will be cleaned when memory
   is needed), it causes ever-growing memory usage when scheduler is
   running as it keeps on writing new log files and the files are not
   rotated later on. This might lead to confusion for our users, who are
   monitoring memory usage of Scheduler - without realising that it is
   harmless and expected in this case.
   
   Adding the advice to Kernel might help with not generating the cache
   memory growth in the first place.
   
   Closes: #14924
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   ---
   **^ Add meaningful description above**
   
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/main/UPDATING.md).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] potiuk commented on a change in pull request #18054: Advises the kernel to not cache log files generated by Airflow

Posted by GitBox <gi...@apache.org>.
potiuk commented on a change in pull request #18054:
URL: https://github.com/apache/airflow/pull/18054#discussion_r703617323



##########
File path: airflow/utils/log/non_caching_file_handler.py
##########
@@ -0,0 +1,39 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import logging
+import os
+
+
+class NonCachingFileHandler(logging.FileHandler):
+    """
+    This is an extension of the python FileHandler that advises the Kernel to not cache the file
+    in PageCache when it is written. While there is nothing wrong with such cache (it will be cleaned
+    when memory is needed), it causes ever-growing memory usage when scheduler is running as it keeps
+    on writing new log files and the files are not rotated later on. This might lead to confusion
+    for our users, who are monitoring memory usage of Scheduler - without realising that it is
+    harmless and expected in this case.
+
+    See https://github.com/apache/airflow/issues/14924
+
+    Adding the advice to Kernel might help with not generating the cache memory growth in the first place.
+    """
+
+    def _open(self):
+        fd = logging.FileHandler._open(self)
+        os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_DONTNEED)

Review comment:
       I fixed retrieving a wrong file descriptor (looked at wrong open method) and I added try/except to handle any kind of failure when we try to advise the kernel that we do not need to cache the file.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] potiuk commented on pull request #18054: Advises the kernel to not cache log files generated by Airflow

Posted by GitBox <gi...@apache.org>.
potiuk commented on pull request #18054:
URL: https://github.com/apache/airflow/pull/18054#issuecomment-915545660


   The failure is intermittent @ashb - and even if it was not a "real" memory leak, I think it might help a lot with "false-positive" reports of memory leaking :)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] potiuk commented on pull request #18054: Advises the kernel to not cache log files generated by Airflow

Posted by GitBox <gi...@apache.org>.
potiuk commented on pull request #18054:
URL: https://github.com/apache/airflow/pull/18054#issuecomment-915544179


   Seems that the fix works as expected - the hint to kernel does the job!
   
   https://github.com/apache/airflow/issues/14924#issuecomment-915539770


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] ashb commented on a change in pull request #18054: Advises the kernel to not cache log files generated by Airflow

Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #18054:
URL: https://github.com/apache/airflow/pull/18054#discussion_r704443881



##########
File path: airflow/utils/log/non_caching_file_handler.py
##########
@@ -0,0 +1,46 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import logging
+import os
+
+
+class NonCachingFileHandler(logging.FileHandler):
+    """
+    This is an extension of the python FileHandler that advises the Kernel to not cache the file
+    in PageCache when it is written. While there is nothing wrong with such cache (it will be cleaned
+    when memory is needed), it causes ever-growing memory usage when scheduler is running as it keeps
+    on writing new log files and the files are not rotated later on. This might lead to confusion
+    for our users, who are monitoring memory usage of Scheduler - without realising that it is
+    harmless and expected in this case.
+
+    See https://github.com/apache/airflow/issues/14924
+
+    Adding the advice to Kernel might help with not generating the cache memory growth in the first place.
+    """
+
+    def _open(self):
+        wrapper = logging.FileHandler._open(self)

Review comment:
       ```suggestion
           wrapper = super()._open()
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] potiuk merged pull request #18054: Advises the kernel to not cache log files generated by Airflow

Posted by GitBox <gi...@apache.org>.
potiuk merged pull request #18054:
URL: https://github.com/apache/airflow/pull/18054


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] github-actions[bot] commented on pull request #18054: Advises the kernel to not cache log files generated by Airflow

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #18054:
URL: https://github.com/apache/airflow/pull/18054#issuecomment-915968084


   The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest main at your convenience, or amend the last commit of the PR, and push it with --force-with-lease.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] potiuk commented on a change in pull request #18054: Advises the kernel to not cache log files generated by Airflow

Posted by GitBox <gi...@apache.org>.
potiuk commented on a change in pull request #18054:
URL: https://github.com/apache/airflow/pull/18054#discussion_r703398342



##########
File path: airflow/utils/log/non_caching_file_handler.py
##########
@@ -0,0 +1,39 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import logging
+import os
+
+
+class NonCachingFileHandler(logging.FileHandler):
+    """
+    This is an extension of the python FileHandler that advises the Kernel to not cache the file
+    in PageCache when it is written. While there is nothing wrong with such cache (it will be cleaned
+    when memory is needed), it causes ever-growing memory usage when scheduler is running as it keeps
+    on writing new log files and the files are not rotated later on. This might lead to confusion
+    for our users, who are monitoring memory usage of Scheduler - without realising that it is
+    harmless and expected in this case.
+
+    See https://github.com/apache/airflow/issues/14924
+
+    Adding the advice to Kernel might help with not generating the cache memory growth in the first place.
+    """
+
+    def _open(self):
+        fd = logging.FileHandler._open(self)
+        os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_DONTNEED)

Review comment:
       I wonder if we need to add any special behaviour or check if the advice is available. The https://docs.python.org/3/library/os.html#os.posix_fadvise mentions that posix_fadvise is only available on Unix (I guess that excludes both MacOS and Windows, but I guess it's going to be harmless and ignored if not available. Anyone can check it on MacOS ?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org