Repository: apache/airflow

Issue:
Can't pass --without-mingle and --without-gossip to celery worker
<!--

Welcome to Apache Airflow!  For a smooth issue process, try to answer the following questions.
Don't worry if they're not all applicable; just try to include what you can :-)

If you need to include code snippets or logs, please put them in fenced code
blocks.  If they're super-long, please use the details tag like
<details><summary>super-long log</summary> lots of stuff </details>

Please delete these comment blocks before submitting the issue.

-->

<!--

IMPORTANT!!!

PLEASE CHECK "SIMILAR TO X EXISTING ISSUES" OPTION IF VISIBLE
NEXT TO "SUBMIT NEW ISSUE" BUTTON!!!

PLEASE CHECK IF THIS ISSUE HAS BEEN REPORTED PREVIOUSLY USING SEARCH!!!

Please complete the next sections or the issue will be closed.
These questions are the first thing we need to know to understand the context.

-->

**Apache Airflow version**: ANY


**Kubernetes version (if you are using kubernetes)** (use `kubectl version`):

**Environment**:

- **Cloud provider or hardware configuration**:
- **OS** (e.g. from /etc/os-release):
- **Kernel** (e.g. `uname -a`):
- **Install tools**:
- **Others**:

**What happened**:

I've an issue with airflow celery worker performance, and I think there are a place for optimization if airflow enables providing --without-gossip while creating celery worker https://github.com/apache/airflow/blob/87038ae42aff3ff81cba1111e418a1f411a0c7b1/airflow/bin/cli.py#L1271 
https://docs.celeryproject.org/en/4.4.3/reference/celery.bin.worker.html?highlight=--without-gossip#cmdoption-celery-worker-without-gossip. In my case, I've a 200 vm and every vm running 2 queues, so 400 **workers exchanging useless message every second** which result in airflow worker is taking about 10% of cpu time (in 4 cores) and to compare, I've a standalone celery app that consume 0.1% of cpu time **after enabling --without-gossip --without-mingle --without-heartbeat**.

**What you expected to happen**:

celery worker should not take more than 2% of cpu time.

**How to reproduce it**:
Using 200 vm and every vm 2 celery workers running at same time, you will see that the celery worker process is taking ~10-15% of cpu time.

PLEASE NOTE:
Due to https://github.com/celery/celery/issues/2566, we can't provide --without-mingle and --without-gossip through configuration (config file).
<!---

As minimally and precisely as possible. Keep in mind we do not have access to your cluster or dags.

If you are using kubernetes, please attempt to recreate the issue using minikube or kind.

## Install minikube/kind

- Minikube https://minikube.sigs.k8s.io/docs/start/
- Kind https://kind.sigs.k8s.io/docs/user/quick-start/

If this is a UI bug, please provide a screenshot of the bug or a link to a youtube video of the bug in action

You can include images using the .md style of
![alt text](http://url/to/img.png)

To record a screencast, mac users can use QuickTime and then create an unlisted youtube video with the resulting .mov file.

--->


**Anything else we need to know**:

<!--

How often does this problem occur? Once? Every time etc?

Any relevant logs to include? Put them here in side a detail tag:
<details><summary>x.log</summary> lots of stuff </details>

-->



Discussion:
According to this test:
https://github.com/celery/celery/blob/05da357502a109c05b35392391299d75d181ccab/celery/contrib/testing/worker.py#L110-L122

We should be able to pass those argument to celery worker without a problem because here:
https://github.com/apache/airflow/blob/f7e01ab29339080c77431a1fc5e4403ba2d80326/airflow/cli/commands/celery_command.py#L152

The `Worker` class is inheriting from `WorkController`
CC: @auvipy 

Resolving patch:
diff --git a/airflow/cli/cli_parser.py b/airflow/cli/cli_parser.py
--- a/airflow/cli/cli_parser.py
+++ b/airflow/cli/cli_parser.py
@@ -513,6 +513,18 @@ def positive_int(value):
     help="Set the umask of celery worker in daemon mode",
     default=conf.get('celery', 'worker_umask'),
 )
+ARG_WITHOUT_MINGLE = Arg(
+    ("--without-mingle",),
+    default=False,
+    help="Don’t synchronize with other workers at start-up",
+    action="store_true",
+)
+ARG_WITHOUT_GOSSIP = Arg(
+    ("--without-gossip",),
+    default=False,
+    help="Don’t subscribe to other workers events",
+    action="store_true",
+)
 
 # flower
 ARG_BROKER_API = Arg(("-a", "--broker-api"), help="Broker API")
@@ -1292,6 +1304,8 @@ class GroupCommand(NamedTuple):
             ARG_LOG_FILE,
             ARG_AUTOSCALE,
             ARG_SKIP_SERVE_LOGS,
+            ARG_WITHOUT_MINGLE,
+            ARG_WITHOUT_GOSSIP,
         ),
     ),
     ActionCommand(
diff --git a/airflow/cli/commands/celery_command.py b/airflow/cli/commands/celery_command.py
--- a/airflow/cli/commands/celery_command.py
+++ b/airflow/cli/commands/celery_command.py
@@ -139,6 +139,8 @@ def worker(args):
         'hostname': args.celery_hostname,
         'loglevel': conf.get('logging', 'LOGGING_LEVEL'),
         'pidfile': pid_file_path,
+        'without_mingle': args.without_mingle,
+        'without_gossip': args.without_gossip,
     }
 
     if conf.has_option("celery", "pool"):


Test patch:
diff --git a/tests/cli/commands/test_celery_command.py b/tests/cli/commands/test_celery_command.py
--- a/tests/cli/commands/test_celery_command.py
+++ b/tests/cli/commands/test_celery_command.py
@@ -172,6 +172,8 @@ def test_worker_started_with_required_arguments(self, mock_worker, mock_popen, m
                 celery_hostname,
                 '--queues',
                 queues,
+                '--without-mingle',
+                '--without-gossip',
             ]
         )
 
@@ -189,4 +191,6 @@ def test_worker_started_with_required_arguments(self, mock_worker, mock_popen, m
             autoscale=autoscale,
             hostname=celery_hostname,
             loglevel=conf.get('logging', 'LOGGING_LEVEL'),
+            without_mingle=True,
+            without_gossip=True,
         )