#506·faust

Multiple Agents Running Concurrently

Author: ShikkicCreated Jan 7, 2020Updated Apr 23, 2023

Checklist

  • I have included information about relevant versions
  • I have verified that the issue persists when using the master branch of Faust.

Steps to reproduce

This is my first time using faust and I wanted to create a small example application with multiple agents. My expectation is that each agent would run concurrently and that I would see the print lines from each agent interspersed in some random ordering.

bash
@app.agent(job_location_topic)
async def job_locations(job_location):
    async for job_loc_batch in job_location.take(1, within=30):
        for job_loc in job_loc_batch:
            print("JOB LOC")
            await asyncio.sleep(10.0)
            print("not sleeping")

@app.agent(job_topic)
async def test_jobs(jobs):
    async for job_batch in jobs.take(1, within=30):
        for job in job_batch:
            print("job")

However, when I observe the output it appears that only one agent can run at any given time. This is even true if I use an await asyncio.sleep(10.0), which I thought might let other agents process events from the event loop.

I have a feeling I'm just misunderstanding how agents are executed and managed via the agent_supervisor.

Would really appreciate it if I could get some insight into what I might be doing/misunderstanding. Thank you!

Expected behavior

bash
not sleeping
JOB LOC
job
not sleeping
JOB LOC
job
job
job
job
not sleeping
JOB LOC

Something of this variation.

Actual behavior

bash
not sleeping
JOB LOC
not sleeping
JOB LOC
not sleeping
JOB LOC
not sleeping
JOB LOC
not sleeping
JOB LOC
not sleeping
JOB LOC

Versions

  • Python version 3.7.5 (docker slim-buster)
  • Faust version 1.9.0
  • Kafka version 1.1.1