Koed00 / django-q

A multiprocessing distributed task queue for Django
https://django-q.readthedocs.org
MIT License
1.83k stars 290 forks source link

test_max_rss fails on armhf architectures #649

Open P-EB opened 2 years ago

P-EB commented 2 years ago

Hi @Koed00 !

I packaged django-q 1.3.9-2 in Debian, and realized that text_max_rss consistently fails in armhf architectures:

_________________________________ test_max_rss _________________________________

broker = <django_q.brokers.redis_broker.Redis object at 0xf44d7b20>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0xf44d7f28>

    @pytest.mark.django_db
    def test_max_rss(broker, monkeypatch):
        # set up the Sentinel
        broker.list_key = "test_max_rss_test:q"
        async_task("django_q.tests.tasks.multiply", 2, 2, broker=broker)
        start_event = Event()
        stop_event = Event()
        cluster_id = uuidlib.uuid4()
        # override settings
        monkeypatch.setattr(Conf, "MAX_RSS", 40000)
        monkeypatch.setattr(Conf, "WORKERS", 1)
        # set a timer to stop the Sentinel
        threading.Timer(3, stop_event.set).start()
        s = Sentinel(stop_event, start_event, cluster_id=cluster_id, broker=broker)
        assert start_event.is_set()
        assert s.status() == Conf.STOPPED
>       assert s.reincarnations == 1
E       assert 0 == 1
E        +  where 0 = <django_q.cluster.Sentinel object at 0xf568e640>.reincarnations

tests/test_cluster.py:424: AssertionError
----------------------------- Captured stderr call -----------------------------
02:12:56 [Q] INFO Enqueued 1
02:12:56 [Q] DEBUG Pushed ('eight-louisiana-pasta-summer', '8aef005e7ce344a6845dacd8b847476e')
02:12:56 [Q] INFO Process-1305 ready for work at 3677
02:12:56 [Q] INFO Process-1306 monitoring at 3678
02:12:56 [Q] INFO MainProcess guarding cluster winter-wisconsin-oscar-one
02:12:56 [Q] INFO Process-1307 pushing tasks at 3679
02:12:56 [Q] INFO Q Cluster winter-wisconsin-oscar-one running.
02:12:56 [Q] DEBUG queueing from test_max_rss_test:q
02:12:56 [Q] INFO Process-1305 processing [eight-louisiana-pasta-summer]
02:12:56 [Q] INFO Processed [eight-louisiana-pasta-summer]
02:12:59 [Q] INFO MainProcess stopping cluster processes
02:13:00 [Q] INFO Process-1307 stopped pushing tasks
02:13:00 [Q] INFO Process-1305 stopped doing work
02:13:00 [Q] INFO Process-1306 stopped monitoring results
02:13:00 [Q] INFO MainProcess waiting for the monitor.

Could it be a problem with redis behaviour? Or something time-based that doesn't work?

What's supposed to increment s.reincarnations in this specific test?

Thanks in advance!

Cheers!

P-EB commented 2 years ago

Ok, I found the issue.

It lies in the fact that armhf is consuming far less resources for a process to run and therefore the MAX_RSS set in your test is too high.

I recommend a value of 20000 that should always lead to a recycling. Or less, if you prefer to be sure to catch any optimized-for-low-mem architecture.