You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "o-nikolas (via GitHub)" <gi...@apache.org> on 2023/05/01 22:36:39 UTC
[GitHub] [airflow] o-nikolas opened a new pull request, #31001: Celery Executor load time optimizations
o-nikolas opened a new pull request, #31001:
URL: https://github.com/apache/airflow/pull/31001
### Overview
This PR aims to improve the time it takes to load/import the Celery executor module.
### Motivation
Executors are imported in more places now that various compatibility checks are in core Airflow code (re: AIP-51). Also, decreasing import times is very important for the work of executors vending CLI commands (see #29055), since the CLI code in Airflow is particularly sensitive to slow imports (because all code is loaded fresh each time you run an individual Airflow CLI command).
### The changes
Move some expensive typing related imports to be under TYPE_CHECKING.
Also move some imports to runtime imports, closer to their usage.
1. Move some expensive typing related imports to be under TYPE_CHECKING.
1. Refactor expensive classes and methods (other than the CeleryExecutor) out of the `celery_executor.py` module into a utils module so that they are only loaded at runtime.
1. Also move some imports closer to their usage.
### Testing
I benchmarked these changes by writing a script to import the executor module in a fresh python runtime and timing how long that takes (you can test this yourself quickly from a bash shell by doing something like `time python -c 'from airflow.executors.local_executor import CeleryExecutor'`). Then doing that in a loop for several samples (with some randomness in the order for fairness) both on main and on my development branch.
### Results

<!--
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 an 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 changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+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 a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
--
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 #31001: Celery Executor load time optimizations
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1546659399
> If we go this route, I believe this should be done in another PR, so that this one shouldn't have too much novel code changes and just contain the refactoring.
Fair point.
> Interesting, I'll have to look into this. As long as it does not slow down the import time through the regular code path this should be fine.
This will be only for the "old" ways -> it will not slow down things **too much**. It's basically when .app is imported in the module, the lookup has to be done if there is a dynamic attribute defined, deprecation warning printed, and "real" import returned instead - so. this is mostly the extra lookup + print delay (but it makes sense to get is slower a bit rather than stopping working altogether. Especially that those liveness probes/health checks are also pretty arcane knowledge for users and they sometimes do not realise they exist and just see "restarting worker".
Of course it also likely means they won't see the deprecation warning :). but I'd say that is not our worry.
--
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] o-nikolas commented on pull request #31001: Celery Executor load time optimizations
Posted by "o-nikolas (via GitHub)" <gi...@apache.org>.
o-nikolas commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1569162551
Made all the requested changes @uranusjr, ready for another review or approval if you think it looks good!
--
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] o-nikolas commented on a diff in pull request #31001: Celery Executor load time optimizations
Posted by "o-nikolas (via GitHub)" <gi...@apache.org>.
o-nikolas commented on code in PR #31001:
URL: https://github.com/apache/airflow/pull/31001#discussion_r1210787836
##########
airflow/executors/celery_executor_utils.py:
##########
Review Comment:
Sure, I can add a module doc string.
--
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] o-nikolas commented on pull request #31001: Celery Executor load time optimizations
Posted by "o-nikolas (via GitHub)" <gi...@apache.org>.
o-nikolas commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1544534241
> I honestly think that docs and code are tied together and that they should not only be changed but also tested together - this is for example why our example_dags are not only part of our docs but are also runnable system tests that (YES) we now have a great dashboard from Amazon (and waiting for more dashboards from others). Same philosophy.
For the system tests, now that they are a regularly run official test (instead of just example dags), they live in `tests/` but indeed, I take the point that in airflow there are more than just RST files in `docs/` :smile:
--
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 #31001: Celery Executor load time optimizations
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1541619701
Because that's the Halm Chart change (also needed) not the docker-compose change. Those two are different but they both used similar liveness/health check probes.
What is currently modified in this PR is the liveness probe in the Helm Chart - which is also needed (and one of the reasons why celery executor tests are working fine now: https://github.com/apache/airflow/actions/runs/4922794793/jobs/8812037156?pr=31001
It would be a little worrisome if the tests worked before, that would mean that the liveness check of K8S is not aggressive enough for our tests and the tests could have succeeded even if the liveness check was not detectig a problem. Glad that you found and modified it too.
This is part of the helm chart of ours:
https://github.com/apache/airflow/blob/f8f47b0f834faa10e7f3b2adcecc561df34079c9/chart/templates/workers/worker-deployment.yaml#L185
What should also be modified (and this is what is failing currently) is the `docker-compose` configuration that we provide our users as a "quick start". The test that fails is the docker-compose test ("Test docker-compose quick start").
https://github.com/apache/airflow/actions/runs/4922794793/jobs/8812036943?pr=31001
And in this case is not the liveness probe that fails but the worker health check (this is the docker-compose's nomenclature):
https://github.com/apache/airflow/blob/f8f47b0f834faa10e7f3b2adcecc561df34079c9/docs/apache-airflow/howto/docker-compose/docker-compose.yaml#L151
Generally I think searching/grep for whatever the usage of `celery_executor.app` in any file might be a good idea, maybe there are other usages of it in docs for example (We do explain how to use health checks.
This is why my intelliJ shows:

And the .rst files of ours should also be updated, otherwise we will have misleading docs.
--
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] o-nikolas commented on pull request #31001: Celery Executor load time optimizations
Posted by "o-nikolas (via GitHub)" <gi...@apache.org>.
o-nikolas commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1564835077
@potiuk I've updated this PR to leverage PEP562 to make `app` still accessible through `airflow.executors.celery_executor` while also still maintaining the load time optimizations. Plus the PR is a little bit smaller now!
Build is green, if you have some time to take another pass on review.
--
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 #31001: Celery Executor load time optimizations
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1538776040
I am glad we had this test in place :)
--
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 #31001: Celery Executor load time optimizations
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1545185323
Loooks cool!.
I think we should discuss it together with the https://github.com/apache/airflow/pull/30727 and decide - if they are both needed to complete other tasks, I think this one has smaller potential for disruptions - k8s part has far more potential for conflicts and fixes - even yesterday I saw an issue that could have require k8s changes.
If those two willl help with the final steps of AIP-51, I am cool with merging both and biting the cherry-picking bullet.
But the liveness/health checks need a bit more work due to back-compatibilty,
There are two things to be done:
1) I think the liveness check in Helm chart shoudl be airflow version dependent. Very similar to what we have for scheduler/triggerer:
https://github.com/apache/airflow/blob/main/chart/templates/_helpers.yaml#L649
```
{{- if semverCompare ">=2.5.0" .Values.airflowVersion }}
- sh
- -c
- |
CONNECTION_CHECK_MAX_COUNT=0 AIRFLOW__LOGGING__LOGGING_LEVEL=ERROR exec /entrypoint \
airflow jobs check --job-type SchedulerJob --local
{{- else if semverCompare ">=2.1.0" .Values.airflowVersion }}
- sh
- -c
- |
CONNECTION_CHECK_MAX_COUNT=0 AIRFLOW__LOGGING__LOGGING_LEVEL=ERROR exec /entrypoint \
airflow jobs check --job-type SchedulerJob --hostname $(hostname)
{{- else }}
- sh
- -c
- |
CONNECTION_CHECK_MAX_COUNT=0 exec /entrypoint python -Wignore -c "
import os
os.environ['AIRFLOW__CORE__LOGGING_LEVEL'] = 'ERROR'
os.environ['AIRFLOW__LOGGING__LOGGING_LEVEL'] = 'ERROR'
from airflow.jobs.scheduler_job import SchedulerJob
from airflow.utils.db import create_session
from airflow.utils.net import get_hostname
import sys
with create_session() as session:
job = session.query(SchedulerJob).filter_by(hostname=get_hostname()).order_by(
SchedulerJob.latest_heartbeat.desc()).limit(1).first()
sys.exit(0 if job.is_alive() else 1)"
{{- end }}
```
Our Helm Chart should be able to be used with past versions of Airflow and this change will make it to stop working for version < 2.7.0, so we need to have similar conditional template for the liveness checks.
Another option would be to change the liveness check to a new command (similarly to what have been done in those other liveness checks. Rather than calling the
`exec /entrypoint python -m celery --app airflow.executors.celery_executor_utils.app inspect ping -d celery@$(hostname` we could add an airflow command that would do that (`airflow celery check --local`) - with hostname option as well - learning from the experience when we introduced the "jobs check` command.
I think the second option here is really something we should do (and that's why this one is also I thin rather candidate for 2.7.0 than say 2.6.2) - because it will add "new feature".
2) The second piece of compatibility is what should happen if someone uses the old Helm Chart (or old docker-compose) for newer airflow versions with. That one shoudl also work with deprecation likely or at the very least should tell the user what to do. I would be for the former.
And it should be possible with PEP-563 and dynamic attributes (https://github.com/apache/airflow/pull/26290) we should be able to add `app` attribute dynamically in `airflow.executors.celery_executor` module - in the way that it will not be auto-completeable and visible, but if someone will continue using it, it could raise a deprecation warning but it will continue to work, importing the "utils" one instead dynamically.
I tihnk we shoudl solve both problems,
--
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 #31001: Celery Executor load time optimizations
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1538769106
I believe, this failing test shows an actual problem (i.e. if we merge it, `docker-compose` of ours will stop working).
This tests starts a docker-compose of ours and triggers a dag there, I don't **think** the errors you see see there are related.
It looks like that for whatever reason the docker-compose of ours things that the airflow worker is unhealthy:
```
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4255c86396b6 ghcr.io/apache/airflow/main/prod/python3.7:5efaf8bdf0bd84f05049479cf387425000f4771e "/usr/bin/dumb-init …" 5 minutes ago Up 5 minutes (healthy) 8080/tcp quick-start_airflow-scheduler_1
b8a7cb3c9429 ghcr.io/apache/airflow/main/prod/python3.7:5efaf8bdf0bd84f05049479cf387425000f4771e "/usr/bin/dumb-init …" 5 minutes ago Up 5 minutes (unhealthy) 8080/tcp quick-start_airflow-worker_1
011a97dfdeff ghcr.io/apache/airflow/main/prod/python3.7:5efaf8bdf0bd84f05049479cf387425000f4771e "/usr/bin/dumb-init …" 5 minutes ago Up 5 minutes (healthy) 8080/tcp quick-start_airflow-triggerer_1
d3113c6b9d22 ghcr.io/apache/airflow/main/prod/python3.7:5efaf8bdf0bd84f05049479cf387425000f4771e "/usr/bin/dumb-init …" 5 minutes ago Up 5 minutes (healthy) 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp quick-start_airflow-webserver_1
4cd33310af92 redis:latest "docker-entrypoint.s…" 5 minutes ago Up 5 minutes (healthy) 6379/tcp quick-start_redis_1
bc474e8ce123 postgres:13 "docker-entrypoint.s…" 5 minutes ago Up 5 minutes (healthy) 5432/tcp quick-start_postgres_1
$ docker-compose logs
```
From the logs it seems that the worker starter correctly, So I think it's the health check that stopped detecting if the worker is running.
And that I think is somehow related with the change. If it is happening repeatedly in this PR, Likely the health check for the worker in our docker compose gets broken by this change (or mayne irflow :
https://github.com/apache/airflow/blob/ffe3a68f9ada2d9d35333d6a32eac2b6ac9c70d6/docs/apache-airflow/howto/docker-compose/docker-compose.yaml#L148
This seems related, the change is about celery executor and that's the one used in our docker-compose.
The way how to test the docker-compose:
* `breeze prod-image build` -> it will build the image locally (ghcr.io/ .....) - you will see it in the ougput
* `breeze testing docker-compose-tests` - should attempt to run the same tests
You can also manualy start our docker-compose following the https://airflow.apache.org/docs/apache-airflow/stable/howto/docker-compose/index.html steps (because this is what the test is actually doing) - just set the set AIRFLOW_IMAGE_NAME to point to the prod image build and it should reveal similar issue.
--
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] uranusjr commented on a diff in pull request #31001: Celery Executor load time optimizations
Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #31001:
URL: https://github.com/apache/airflow/pull/31001#discussion_r1211049775
##########
airflow/executors/celery_executor_utils.py:
##########
@@ -0,0 +1,300 @@
+# 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.
+"""
+Utilities and classes used by the Celery Executor.
+Much of this code is expensive to import/load, be careful where this module is imported.
+"""
Review Comment:
```suggestion
"""Utilities and classes used by the Celery Executor.
NOTE: Much of this code is expensive to import/load, be careful where this module
is imported.
"""
```
--
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] o-nikolas commented on pull request #31001: Celery Executor load time optimizations
Posted by "o-nikolas (via GitHub)" <gi...@apache.org>.
o-nikolas commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1540993031
Hmm, still failing after patching that yaml, and I don't see any helpful log lines from the worker logs that are printed. Which makes this very difficult to debug
--
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 #31001: Celery Executor load time optimizations
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1543592748
> @potiuk I had another look at my grep results for celery_executor.app and I still don't see anything else that (isn't docs), the hits for mocks that came up in your IDE were already updated in my branch.
The change is still missing in `airflow/docs/apache-airflow/howto/docker-compose/docker-compose.yaml` :)
It has not been changed in your PR :)
```
- 'celery --app airflow.executors.celery_executors.app inspect ping -d "celery@$${HOSTNAME}"'
```
I think you must have some problem with wrong branch number because the PR here only modifies those files:

* no .rst files
* no `docker-compose.yaml` file
Unless I totally miss something
--
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] o-nikolas commented on pull request #31001: Celery Executor load time optimizations
Posted by "o-nikolas (via GitHub)" <gi...@apache.org>.
o-nikolas commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1533915306
I'm seeing some failed INSERT and SELECT statements when the postgres container is trying to start. I think that's what's making the Docker Compose start unhealthy and timing out. But I don't see the connection to my changes in this PR. I've tried rebasing off main already in case I was missing some fix but it's still failing.
```
postgres_1 | 2023-05-04 00:11:25.558 UTC [1] LOG: starting PostgreSQL 13.10 (Debian 13.10-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
postgres_1 | 2023-05-04 00:11:25.558 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres_1 | 2023-05-04 00:11:25.558 UTC [1] LOG: listening on IPv6 address "::", port 5432
postgres_1 | 2023-05-04 00:11:25.558 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1 | 2023-05-04 00:11:25.560 UTC [63] LOG: database system was shut down at 2023-05-04 00:11:25 UTC
postgres_1 | 2023-05-04 00:11:25.563 UTC [1] LOG: database system is ready to accept connections
postgres_1 | 2023-05-04 00:11:38.079 UTC [77] ERROR: relation "log" does not exist at character 13
postgres_1 | 2023-05-04 00:11:38.079 UTC [77] STATEMENT: INSERT INTO log (dttm, event, owner, extra) VALUES ('2023-05-04T00:11:38.051018+00:00'::timestamptz, 'cli_check', 'root', '{"host_name": "4b5384b87e09", "full_command": "[''/home/airflow/.local/bin/airflow'', ''db'', ''check'']"}') RETURNING log.id
postgres_1 | 2023-05-04 00:11:38.719 UTC [78] ERROR: relation "log" does not exist at character 13
postgres_1 | 2023-05-04 00:11:38.719 UTC [78] STATEMENT: INSERT INTO log (dttm, event, owner, extra) VALUES ('2023-05-04T00:11:38.710877+00:00'::timestamptz, 'cli_upgradedb', 'root', '{"host_name": "4b5384b87e09", "full_command": "[''/home/airflow/.local/bin/airflow'', ''db'', ''upgrade'']"}') RETURNING log.id
postgres_1 | 2023-05-04 00:11:40.897 UTC [78] ERROR: relation "connection" does not exist at character 55
postgres_1 | 2023-05-04 00:11:40.897 UTC [78] STATEMENT: SELECT connection.conn_id AS connection_conn_id
postgres_1 | FROM connection GROUP BY connection.conn_id
postgres_1 | HAVING count(*) > 1
postgres_1 | 2023-05-04 00:11:40.899 UTC [78] ERROR: relation "connection" does not exist at character 55
postgres_1 | 2023-05-04 00:11:40.899 UTC [78] STATEMENT: SELECT connection.conn_id AS connection_conn_id
postgres_1 | FROM connection
postgres_1 | WHERE connection.conn_type IS NULL
postgres_1 | 2023-05-04 00:11:40.934 UTC [78] ERROR: relation "ab_user" does not exist at character 51
postgres_1 | 2023-05-04 00:11:40.934 UTC [78] STATEMENT: SELECT ab_user.username AS ab_user_username
postgres_1 | FROM ab_user GROUP BY ab_user.username
postgres_1 | HAVING count(*) > 1
postgres_1 | 2023-05-04 00:11:40.936 UTC [78] ERROR: relation "ab_register_user" does not exist at character 69
postgres_1 | 2023-05-04 00:11:40.936 UTC [78] STATEMENT: SELECT ab_register_user.username AS ab_register_user_username
postgres_1 | FROM ab_register_user GROUP BY ab_register_user.username
postgres_1 | HAVING count(*) > 1
```
--
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 #31001: Celery Executor load time optimizations
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1544519194
> Oh my, I finally see the confusion! I have been "ignoring" docs for now (since I will do a second pass to update them later), but there is actually real code/config in there! I am not used to seeing real code that is tested living in a docs/ dir.
We TEST everything. Including our docs. I am dead serious.
--
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] uranusjr commented on a diff in pull request #31001: Celery Executor load time optimizations
Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #31001:
URL: https://github.com/apache/airflow/pull/31001#discussion_r1209696998
##########
airflow/executors/celery_executor_utils.py:
##########
Review Comment:
Maybe we should add a comment or docstring somewhere in this module to warn future contributors against importing this anywhere global?
##########
airflow/executors/celery_executor.py:
##########
@@ -250,7 +119,7 @@ def _num_tasks_per_send_process(self, to_send_count: int) -> int:
return max(1, int(math.ceil(1.0 * to_send_count / self._sync_parallelism)))
def _process_tasks(self, task_tuples: list[TaskTuple]) -> None:
- task_tuples_to_send = [task_tuple[:3] + (execute_command,) for task_tuple in task_tuples]
+ task_tuples_to_send = [task_tuple[:3] + (self.execute_command,) for task_tuple in task_tuples]
Review Comment:
Why not just import `execute_command` in this function?
##########
airflow/executors/celery_executor.py:
##########
@@ -64,151 +58,23 @@
TaskInstanceInCelery = Tuple[TaskInstanceKey, CommandType, Optional[str], Task]
-log = logging.getLogger(__name__)
+# PEP562
+def __getattr__(name):
+ # This allows us to make the Celery app accessible through the
+ # celery_executor module without the time cost of it's import and
Review Comment:
```suggestion
# celery_executor module without the time cost of its import and
```
--
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] o-nikolas commented on pull request #31001: Celery Executor load time optimizations
Posted by "o-nikolas (via GitHub)" <gi...@apache.org>.
o-nikolas commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1544852959
> Yes. Docker-compose and instructions there are part of the docs too :).
>
> And to be brutally honest - I prefer you having hard time now and struggle finding all those things out while having the PR red and prevening you from merging (and me spending time on helping), rather than having users 3 months from now (when released) starting to complain that the things do not work, with some poor souls looking on our github issues and triaging them and trying to guess why the things are failing from poor description of the users who would **just** know they docker-compose fails and their nodes are unhealthy...
>
> The philosophy is:
>
> * findding/fixing problems as early as we can in the product lifecycle (at PR stage is as early as possible)
>
> * the best way to solve a problem is prevent the problem from happening at all
>
>
> If we would not follow it, we would not be able to handle the number of issues our users would raise :).
Yes, I agree with all of the above, I'm definitely not trying to argue that we shouldn't test as much as possible or as early as possible :smile:
I put up some new changes which should resolve the issue and make the tests green! :crossed_fingers:
--
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] o-nikolas commented on pull request #31001: Celery Executor load time optimizations
Posted by "o-nikolas (via GitHub)" <gi...@apache.org>.
o-nikolas commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1543373865
@potiuk I had another look at my grep results for `celery_executor.app` and I still don't see anything else that (isn't docs), the hits for mocks that came up in your IDE were already updated in my branch.
Once your pr #31181 is merged I'll use the improved debugging ability to have a deeper look to see if I can find the root cause :+1:
--
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 #31001: Celery Executor load time optimizations
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1541904823
Here is a PR that improves all the aspects of the docker-compose tests debuggability and re-runnability locally https://github.com/apache/airflow/pull/31181
--
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 #31001: Celery Executor load time optimizations
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1544547444
Yes. Docker-compose and instructions there are part of the docs too :).
And to be brutally honest - I prefer you having hard time now and struggle finding all those things out while having the PR red and prevening you from merging, rather than having users 3 months from now when released starting to complain that the things do not work, so that some poor souls looking on our github issues and triaging them and trying to guess why the things are failing from poor description of the users who would **just** know they docker-compose fails and their nodes are unhealthy...
The philosophy is:
* fixing problems before as early as we can in the product lifecycle (at PR stage is as early as possible)
* the best way to solve a problem is prevent the problem from happening at all
If we would not follow it, we would not be able to handle the number of issues our users would raise :).
--
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] o-nikolas commented on pull request #31001: Celery Executor load time optimizations
Posted by "o-nikolas (via GitHub)" <gi...@apache.org>.
o-nikolas commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1539090533
> Yes - the health check currently checks if the celery app is running:
>
> `celery --app airflow.executors.celery_executor.app inspect ping -d "celery@$${HOSTNAME}"'`
>
> And this PR removes the `app` variable from that module, so indeed, the change breaks health-check,
Thanks for helping to unblock this one @potiuk!
> I am glad we had this test in place :)
Indeed, good testing pays so many future dividends :smile:
--
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] o-nikolas commented on pull request #31001: Celery Executor load time optimizations
Posted by "o-nikolas (via GitHub)" <gi...@apache.org>.
o-nikolas commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1544498362
Oh my, I finally see the confusion! I have been "ignoring" docs for now (since I will do a second pass to update them later), but there is actually real code/config in there! I am not used to seeing real code that is tested living in a docs/ dir.
--
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] o-nikolas commented on pull request #31001: Celery Executor load time optimizations
Posted by "o-nikolas (via GitHub)" <gi...@apache.org>.
o-nikolas commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1546080768
> Loooks cool!.
>
> I think we should discuss it together with the #30727 and decide - if they are both needed to complete other tasks, I think this one has smaller potential for disruptions - k8s part has far more potential for conflicts and fixes - even yesterday I saw an issue that could have require k8s changes.
>
> If those two willl help with the final steps of AIP-51, I am cool with merging both and biting the cherry-picking bullet.
Yeah, I still think we cannot finish/merge #29055 without these changes (see [here](https://github.com/apache/airflow/pull/29055#issuecomment-1479968269)). The Airflow CLI code will see too much of a performance regression.
>
> But the liveness/health checks need a bit more work due to back-compatibilty,
>
> There are two things to be done:
>
> 1. I think the liveness check in Helm chart shoudl be airflow version dependent. Very similar to what we have for scheduler/triggerer:
>
> Our Helm Chart should be able to be used with past versions of Airflow and this change will make it to stop working for version < 2.7.0, so we need to have similar conditional template for the liveness checks.
Yupp, that's fair, I can look into this.
> Another option would be to change the liveness check to a new command (similarly to what have been done in those other liveness checks. Rather than calling the `exec /entrypoint python -m celery --app airflow.executors.celery_executor_utils.app inspect ping -d celery@$(hostname` we could add an airflow command that would do that (`airflow celery check --local`) - with hostname option as well - learning from the experience when we introduced the "jobs check` command.
>
> I think the second option here is really something we should do (and that's why this one is also I thin rather candidate for 2.7.0 than say 2.6.2) - because it will add "new feature".
If we go this route, I believe this should be done in another PR, so that this one shouldn't have too much novel code changes and just contain the refactoring.
>
> 2. The second piece of compatibility is what should happen if someone uses the old Helm Chart (or old docker-compose) for newer airflow versions with. That one shoudl also work with deprecation likely or at the very least should tell the user what to do. I would be for the former.
>
>
> And it should be possible with PEP-563 and dynamic attributes (#26290) we should be able to add `app` attribute dynamically in `airflow.executors.celery_executor` module - in the way that it will not be auto-completeable and visible, but if someone will continue using it, it could raise a deprecation warning but it will continue to work, importing the "utils" one instead dynamically.
Interesting, I'll have to look into this. As long as it does not slow down the import time through the regular code path this should be fine.
>
> I think we shoudl solve both problems,
:+1:
--
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] o-nikolas commented on pull request #31001: Celery Executor load time optimizations
Posted by "o-nikolas (via GitHub)" <gi...@apache.org>.
o-nikolas commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1542517563
Thanks @potiuk !
> Generally I think searching/grep for whatever the usage of `executors.celery_executor.app` in any file might be a good idea, maybe there are other usages of it in docs for example (We do explain how to use health checks.
Agreed, and I did just this and only found one non-docs result (the one I updated) but I must have just missed the other usage. I'll have another look later today. I'm at the Open Source Summit so time is limited this week.
> And the .rst files of ours should also be updated, otherwise we will have misleading docs.
Yupp, 100%, I'm just trying to understand this failure and get the build passing, I'll definitely update the docs 👍
--
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] uranusjr merged pull request #31001: Celery Executor load time optimizations
Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr merged PR #31001:
URL: https://github.com/apache/airflow/pull/31001
--
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 #31001: Celery Executor load time optimizations
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1544522073
I honestly thing that docs and code are tight together and that they should not only be changed and tested together - this is for example why our example_dags are not only part of our docs but are also runnable system tests that (YES) we now have a great dashboard from Amazon (and waiting for more dashboards from others). Same philosophy.
--
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] o-nikolas commented on pull request #31001: Celery Executor load time optimizations
Posted by "o-nikolas (via GitHub)" <gi...@apache.org>.
o-nikolas commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1548222243
> This will be only for the "old" ways -> it will not slow down things **too much**. It's basically when .app is imported in the module, the lookup has to be done if there is a dynamic attribute defined, deprecation warning printed, and "real" import returned instead - so. this is mostly the extra lookup + print delay (but it makes sense to get is slower a bit rather than stopping working altogether. Especially that those liveness probes/health checks are also pretty arcane knowledge for users and they sometimes do not realise they exist and just see "restarting worker".
Actually, this has me thinking, the very slow part is importing the celery bits and constructing the app (mostly the former), so if I just defer the import in a dynamic attribute on celery_executor.py, then that actually suits all my needs for this PR perfectly fine. There would be no need to deprecate anything as far as the user is concerned and the number of changes in this PR will shrink quite a bit. I'll play around with this today and see if all the tests still pass as expected.
--
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 #31001: Celery Executor load time optimizations
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1541632593
> Which makes this very difficult to debug
That's a good point. I searched in stack overflow and I will make a PR in a moment to add the output of the helth checks in case of docker-compose failure.
--
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] o-nikolas commented on a diff in pull request #31001: Celery Executor load time optimizations
Posted by "o-nikolas (via GitHub)" <gi...@apache.org>.
o-nikolas commented on code in PR #31001:
URL: https://github.com/apache/airflow/pull/31001#discussion_r1210787086
##########
airflow/executors/celery_executor.py:
##########
@@ -250,7 +119,7 @@ def _num_tasks_per_send_process(self, to_send_count: int) -> int:
return max(1, int(math.ceil(1.0 * to_send_count / self._sync_parallelism)))
def _process_tasks(self, task_tuples: list[TaskTuple]) -> None:
- task_tuples_to_send = [task_tuple[:3] + (execute_command,) for task_tuple in task_tuples]
+ task_tuples_to_send = [task_tuple[:3] + (self.execute_command,) for task_tuple in task_tuples]
Review Comment:
I already needed the import in init for the BulkStateFetcher so I just imported both on the same line and then set it as an attribute. But happy to change it if you'd prefer :+1:
--
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 #31001: Celery Executor load time optimizations
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #31001:
URL: https://github.com/apache/airflow/pull/31001#issuecomment-1538773741
Yes - the health check currently checks if the celery app is running:
`celery --app airflow.executors.celery_executor.app inspect ping -d "celery@$${HOSTNAME}"'`
And this PR removes the `app` variable from that module, so indeed, the change breaks health-check,
--
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