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

Google groups discussion: "Celery only handle one message a time while cocurrency = 4 is set"

Google groups discussion: "Concurrency with Consumers running in a Celery Worker"

Possible Duplicates

None

Environment & Settings

Celery version:

celery report Output:

software -> celery:5.0.5 (singularity) kombu:5.0.2 py:3.7.7
billiard:3.6.3.0 py-amqp:5.0.5
platform -> system:Linux arch:64bit
kernel version:4.19.121-linuxkit imp:CPython
loader -> celery.loaders.app.AppLoader
settings -> transport:amqp results:disabled

api_request_timeout: '********'
broker_connection_max_retries: None
broker_connection_timeout: 30
broker_heartbeat: None
broker_pool_limit: 1
broker_transport_options: {
'confirm_publish': True}
broker_url: 'amqp://admin:********@rabbitmq:5672//'
event_queue_expires: 60
os: <module 'os' from '/usr/local/lib/python3.7/os.py'>
result_backend: None
task_acks_late: True
task_acks_on_failure_or_timeout: False
task_compression: 'gzip'
task_create_missing_queues: True
task_ignore_result: True
task_reject_on_worker_lost: True
task_store_errors_even_if_ignored: False
task_time_limit: 30
task_track_started: True
worker_concurrency: 4
worker_enable_remote_control: False
worker_prefetch_multiplier: 10
deprecated_settings: None

Steps to Reproduce

Required Dependencies

Minimal Python Version: 3.7.x

Minimal Celery Version: 5.x

Minimal Kombu Version: 5.x

Minimal Broker Version: RabbitMQ 3.7.x

Minimal Result Backend Version: N/A

Minimal OS and/or Kernel Version: Debian 9 (ie. the python:3.7-stretch docker image)

Minimal Broker Client Version: Unknown

Minimal Result Backend Client Version: N/A

Python Packages

pip freeze Output:

affine==2.3.0
amqp==5.0.5
attrs==20.3.0
billiard==3.6.3.0
blinker==1.4
boto3==1.14.20
botocore==1.17.63
cached-property==1.5.1
cachetools==4.2.1
celery==5.0.5
certifi==2020.12.5
chardet==3.0.4
click==7.1.2
click-didyoumean==0.0.3
click-plugins==1.1.1
click-repl==0.1.6
cligj==0.7.1
cycler==0.10.0
ddtrace==0.31.0
decorator==4.4.2
docutils==0.15.2
fast-slic==0.4.0
Flask==1.0.2
Flask-Script==2.0.6
flatten-dict==0.3.0
gevent==21.1.2
google-api-core==1.25.1
google-auth==1.24.0
google-cloud-core==1.5.0
google-cloud-storage==1.20.0
google-resumable-media==0.4.1
googleapis-common-protos==1.52.0
greenlet==1.0.0
gunicorn==19.9.0
humanize==3.2.0
idna==2.8
imageio==2.9.0
importlib-metadata==3.4.0
itsdangerous==1.1.0
Jinja2==2.11.2
jmespath==0.10.0
kiwisolver==1.3.1
kombu==5.0.2
MarkupSafe==1.1.1
matplotlib==3.1.3
more-itertools==8.6.0
mysqlclient==1.4.4
networkx==2.5
numpy==1.17.0
opencv-python==4.1.1.26
packaging==20.8
pathlib2==2.3.5
piexif==1.1.3
Pillow==6.1.0
pluggy==0.13.1
prometheus-client==0.7.1
prompt-toolkit==3.0.14
protobuf==3.14.0
psutil==5.8.0
py==1.10.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
PyJWT==2.0.1
pyparsing==2.4.7
pytest==5.4.1
pytest-flask==1.0.0
pytest-mock==1.10.4
pytest-runner==4.4
python-dateutil==2.8.1
python-magic==0.4.15
pytz==2020.5
PyWavelets==1.1.1
PyYAML==5.1.2
rasterio==1.1.6
requests==2.22.0
rsa==4.7
s3transfer==0.3.4
scikit-image==0.16.2
scipy==1.4.1
sentry-sdk==0.16.0
Shapely==1.6.4.post2
six==1.15.0
snuggs==1.4.7
SQLAlchemy==1.3.10
stringcase==1.2.0
structlog==19.1.0
timeout-decorator==0.5.0
tornado==6.1
typing-extensions==3.7.4.3
urllib3==1.25.11
vine==5.0.0
wcwidth==0.2.5
Werkzeug==1.0.1
zipp==3.4.0
zope.event==4.5.0
zope.interface==5.3.0

Other Dependencies

N/A

Minimally Reproducible Test Case

Custom consumer example from the docs, modified to send many messages instead of a single one

from celery import Celery
from celery import bootsteps
from kombu import Consumer, Exchange, Queue

my_queue = Queue('custom', Exchange('custom'), 'routing_key')

app = Celery(broker='amqp://')

class MyConsumerStep(bootsteps.ConsumerStep):

def get_consumers(self, channel):
return [Consumer(channel,
queues=[my_queue],
callbacks=[self.handle_message],
accept=['json'])]

def handle_message(self, body, message):
print('Received message: {0!r}'.format(body))
message.ack()
app.steps['consumer'].add(MyConsumerStep)

def send_me_a_message(who, producer=None):
with app.producer_or_acquire(producer) as producer:
producer.publish(
{'hello': who},
serializer='json',
exchange=my_queue.exchange,
routing_key='routing_key',
declare=[my_queue],
retry=True,
)

if __name__ == '__main__':
for i in range(1000):
send_me_a_message('world!')

Worker process started via:

celery -A app.messaging.celery worker -l INFO -E \
--without-heartbeat --without-gossip --without-mingle \
--concurrency=4
--pool=prefork

Expected Behavior

With concurrency set to the default of 4 and the default prefork execution pool, I would expect that the worker process's children all start executing the custom consumer and do work instead of staying idle.

Actual Behavior

Worker process parent does work, while children processes remain idle. See screenshot of watch ps auxef below, and note that the child processes are idle while the parent process shows CPU usage when 1000 messages are being processed.

Issue 2:
Affects 3.0.23.

The get_scheduler method is called as part of celery.apps.beat.Beat.startup_info (instead of accessing the beat.scheduler property). This instantiates a scheduler object (lazy=True).

Later, in celery.beat.Service.start() the beat.scheduler property is accessed. Since this is the first call, the scheduler instance is created again (lazy=False).

Is this working as designed?