Skip to content

async method call the sync code, and using semaphore together #2285

@colinguozizhong

Description

@colinguozizhong

I saw this code in model_worker.py & multi_model_worker.py

@app.post("/worker_generate")
async def api_generate(request: Request):
    params = await request.json()
    await acquire_worker_semaphore()
    worker = worker_map[params["model"]]
    output = worker.generate_gate(params)
    release_worker_semaphore()
    return JSONResponse(output)

In this asynchronous method, call the synchronous code worker.generate_gate(params), it seems to cause service congestion. In this case, await acquire_worker_semaphore() seems to be invalid because there is always only one model running in the service?

is this right?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions