Issue 1:
Checklist

I have verified that the issue exists against the master branch of Celery.

This has already been asked to the discussion group first.

I have read the relevant section in the

contribution guide

on reporting bugs.

I have checked the issues list

for similar or identical bug reports.

I have checked the pull requests list

for existing proposed fixes.

I have checked the commit log

to find out if the bug was already fixed in the master branch.

I have included all related issues and possible duplicate issues

in this issue (If there are none, check this box anyway).

Mandatory Debugging Information

I have included the output of celery -A proj report in the issue.

(if you are not able to do this, then at least specify the Celery

version affected).

I have verified that the issue exists against the master branch of Celery.

I have included the contents of pip freeze in the issue.

I have included all the versions of all the external dependencies required

to reproduce this bug.

Optional Debugging Information

I have tried reproducing the issue on more than one Python version

and/or implementation.

I have tried reproducing the issue on more than one message broker and/or

result backend.

I have tried reproducing the issue on more than one version of the message

broker and/or result backend.

I have tried reproducing the issue on more than one operating system.

I have tried reproducing the issue on more than one workers pool.

I have tried reproducing the issue with autoscaling, retries,

ETA/Countdown & rate limits disabled.

I have tried reproducing the issue after downgrading

and/or upgrading Celery and its dependencies.

Related Issues and Possible Duplicates

Related Issues

#6381

Possible Duplicates

None

Environment & Settings

Celery version: 5.0.0 (singularity)

celery report Output:

celery report

software -> celery:5.0.0 (singularity) kombu:5.0.2 py:3.8.2
billiard:3.6.3.0 py-amqp:5.0.1
platform -> system:Linux arch:64bit, ELF
kernel version:5.4.0-48-generic imp:CPython
loader -> celery.loaders.default.Loader
settings -> transport:amqp results:disabled

deprecated_settings: None

Steps to Reproduce

Required Dependencies

Minimal Python Version: N/A or Unknown

Minimal Celery Version: 5.0.0

Minimal Kombu Version: N/A or Unknown

Minimal Broker Version: N/A or Unknown

Minimal Result Backend Version: N/A or Unknown

Minimal OS and/or Kernel Version: N/A or Unknown

Minimal Broker Client Version: N/A or Unknown

Minimal Result Backend Client Version: N/A or Unknown

Python Packages

pip freeze Output:

alabaster==0.7.12
amqp==5.0.1
appdirs==1.4.4
attrs==19.3.0
autoflake==1.3.1
autopep8==1.5.4
aws-xray-sdk==0.95
azure-common==1.1.5
azure-nspkg==3.0.2
azure-storage==0.36.0
azure-storage-common==1.1.0
azure-storage-nspkg==3.1.0
Babel==2.8.0
backcall==0.2.0
bandit==1.6.2
basho-erlastic==2.1.1
billiard==3.6.3.0
bleach==3.1.5
boto==2.49.0
boto3==1.13.26
botocore==1.16.26
bump2version==1.0.0
bumpversion==0.6.0
case==1.5.3
cassandra-driver==3.20.2
-e git+git@github.com:celery/celery.git@eab4bc3d28b5dc547bb6dfac981b01595c565c3a#egg=celery
certifi==2020.4.5.1
cffi==1.14.0
cfgv==3.1.0
chardet==3.0.4
click==7.1.2
click-didyoumean==0.0.3
click-repl==0.1.6
cmake-setuptools==0.1.3
codecov==2.1.8
colorama==0.4.3
couchbase==2.5.12
coverage==5.2
cryptography==3.0
DateTime==4.3
decorator==4.4.2
distlib==0.3.1
dnspython==1.16.0
docker==4.2.1
docutils==0.15.2
ecdsa==0.15
elasticsearch==7.8.1
ephem==3.7.7.1
eventlet==0.26.1
filelock==3.0.12
future==0.18.2
gevent==20.6.2
gitdb==4.0.5
GitPython==3.1.7
greenlet==0.4.16
identify==1.4.19
idna==2.9
imagesize==1.2.0
importlib-metadata==1.6.1
iniconfig==1.0.1
ipython==7.17.0
ipython-genutils==0.2.0
isort==5.0.9
jedi==0.17.2
jeepney==0.4.3
Jinja2==2.11.2
jmespath==0.10.0
jsondiff==1.1.1
jsonpickle==1.4.1
keyring==21.2.1
kombu==5.0.2
linecache2==1.0.0
MarkupSafe==1.1.1
mock==4.0.2
monotonic==1.5
more-itertools==8.3.0
moto==1.3.7
msgpack==1.0.0
nodeenv==1.4.0
nose==1.3.7
packaging==20.4
parso==0.7.1
pbr==5.4.5
pexpect==4.8.0
pickleshare==0.7.5
pkginfo==1.5.0.1
pluggy==0.13.1
pre-commit==2.5.1
prompt-toolkit==3.0.7
ptyprocess==0.6.0
py==1.9.0
pyaml==20.4.0
pyArango==1.3.4
pycodestyle==2.6.0
pycouchdb==1.14.1
pycparser==2.20
pycryptodome==3.9.7
pycurl==7.43.0.5
pydocumentdb==2.3.2
pyflakes==2.2.0
Pygments==2.6.1
pylibmc==1.6.1
pymongo==3.11.0
pyparsing==2.4.7
pytest==6.0.1
pytest-celery==0.0.0a1
pytest-cov==2.10.0
pytest-rerunfailures==9.0
pytest-sugar==0.9.4
pytest-timeout==1.4.2
pytest-travis-fold==1.3.0
python-consul==1.1.0
python-dateutil==2.8.1
python-jose==2.0.2
python-memcached==1.59
python3-protobuf==2.5.0
pytz==2020.1
pyupgrade==2.6.2
PyYAML==5.3.1
readme-renderer==26.0
redis==3.5.3
requests==2.23.0
requests-toolbelt==0.9.1
responses==0.10.14
rfc3986==1.4.0
riak==2.7.0
s3transfer==0.3.3
SecretStorage==3.1.2
simplejson==3.17.2
six==1.15.0
smmap==3.0.4
snowballstemmer==2.0.0
softlayer-messaging==1.0.3
Sphinx==3.0.4
sphinx-celery==2.0.0
sphinx-click==2.5.0
sphinx-testing==0.7.2
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==1.0.3
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.4
SQLAlchemy==1.3.18
stevedore==3.2.0
tblib==1.7.0
termcolor==1.1.0
tokenize-rt==4.0.0
toml==0.10.1
tox==3.20.0
tqdm==4.48.0
traceback2==1.4.0
traitlets==4.3.3
twine==3.2.0
typer==0.3.0
unittest2==1.1.0
urllib3==1.25.9
vine==5.0.0
virtualenv==20.0.31
wcwidth==0.2.5
webencodings==0.5.1
websocket-client==0.57.0
Werkzeug==1.0.1
wrapt==1.12.1
xar==19.4.22
xmltodict==0.12.0
zipp==3.1.0
zope.event==4.4
zope.interface==5.1.0

Other Dependencies

A recent version of SystemD.

Minimally Reproducible Test Case

Expected Behavior

The service should start without error.

Actual Behavior

The service crashes with the following error:

okt 06 18:13:53 nezzybuild systemd[1]: Started Celery Service.
okt 06 18:13:53 nezzybuild systemd[1]: celery.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
okt 06 18:13:53 nezzybuild systemd[1]: celery.service: Failed with result 'exit-code'.

Issue 2:
Checklist

I have verified that the issue exists against the master branch of Celery.

This has already been asked to the discussions forum first.

I have read the relevant section in the

contribution guide

on reporting bugs.

I have checked the issues list

for similar or identical bug reports.

I have checked the pull requests list

for existing proposed fixes.

I have checked the commit log

to find out if the bug was already fixed in the master branch.

I have included all related issues and possible duplicate issues

in this issue (If there are none, check this box anyway).

Mandatory Debugging Information

I have included the output of celery -A proj report in the issue.

(if you are not able to do this, then at least specify the Celery

version affected).

I have verified that the issue exists against the master branch of Celery.

I have included the contents of pip freeze in the issue.

I have included all the versions of all the external dependencies required

to reproduce this bug.

Optional Debugging Information

I have tried reproducing the issue on more than one Python version

and/or implementation.

I have tried reproducing the issue on more than one message broker and/or

result backend.

I have tried reproducing the issue on more than one version of the message

broker and/or result backend.

I have tried reproducing the issue on more than one operating system.

I have tried reproducing the issue on more than one workers pool.

I have tried reproducing the issue with autoscaling, retries,

ETA/Countdown & rate limits disabled.

I have tried reproducing the issue after downgrading

and/or upgrading Celery and its dependencies.

Related Issues and Possible Duplicates

Related Issues

None

Possible Duplicates

None

Environment & Settings

Celery version: 5.3.0b1 (dawn-chorus)

celery report Output:

software -> celery:5.3.0b1 (dawn-chorus) kombu:5.3.0b1 py:3.9.6
billiard:3.6.4.0 redis:4.3.4
platform -> system:Darwin arch:64bit
kernel version:20.6.0 imp:CPython
loader -> celery.loaders.app.AppLoader
settings -> transport:redis results:redis://localhost/

broker_url: 'redis://localhost:6379//'
result_backend: 'redis://localhost/'
deprecated_settings: None
worker_concurrency: 1
worker_prefetch_multiplier: 1
task_acks_late: True

Steps to Reproduce

Required Dependencies

Python Version: 3.9.6

Celery Version: 5.3.0b1

Kombu Version: 5.3.0b1

Broker Version: redis 7.0.2

Result Backend Version: redis 7.0.2

OS and/or Kernel Version: MacOS: Darwin 20.6.0 Darwin Kernel Version 20.6.0: RELEASE_ARM64_T8101 arm64 arm Darwin

Minimal Broker Client Version: N/A or Unknown

Minimal Result Backend Client Version: N/A or Unknown

Python Packages

pip freeze Output:

amqp==5.1.1
anyio==3.6.1
async-timeout==4.0.2
billiard==3.6.4.0
celery @ file:///Users/shahar/work/sources/celery
click==8.1.3
click-didyoumean==0.3.0
click-plugins==1.1.1
click-repl==0.2.0
Cython==0.29.32
Deprecated==1.2.13
fastapi==0.78.0
flower==1.0.0
greenlet==1.1.2
h11==0.13.0
humanize==4.2.0
idna==3.3
kombu==5.3.0b1
packaging==21.3
prometheus-client==0.14.1
prompt-toolkit==3.0.30
pydantic==1.9.1
pyparsing==3.0.9
pytz==2022.2.1
redis==4.3.4
six==1.16.0
sniffio==1.2.0
starlette==0.19.1
tornado==6.1
typing-extensions==4.2.0
uvicorn==0.18.1
vine==5.0.0
wcwidth==0.2.5
wrapt==1.14.1

Other Dependencies

using redis 7.0.2 as broker and backend.

Minimally Reproducible Test Case

from celery import Celery
import time

app = Celery('bug', broker='redis://localhost', backend='redis://localhost')
app.conf.worker_concurrency = 1
app.conf.worker_prefetch_multiplier = 1
app.conf.task_acks_late = True

@app.task
def func():
time.sleep(1)

def func_duration():
ts = time.perf_counter()
func.delay().get()
return time.perf_counter() - ts

def main(count=5):
func_duration()
latency = (sum(func_duration() for _ in range(count)) / count) - 1
print(f'{latency}')

if __name__ == '__main__':
main()

Expected Behavior

I expect that enabling task_acks_late will not increase the latency by a factor of 10.

Actual Behavior

Running the script with acks late disabled results in a ~20ms latency.

Running the script iwht acks late enabled results in a ~500ms latency.

Analysis

Running profiler reveals that our single worker, between sending the result of the previous task and popping the next task, spends most of its time in the event loop's poll: https://github.com/celery/kombu/blob/master/kombu/asynchronous/hub.py#L315

The event loop will usually wait the default timeout of one whole second (when there's no pending event), even in the case where popping the next task should happen as soon as possible.

Changing the order in the event loop so that the tick callbacks will be executed after the todo callbacks seems to resolve the issue.