Skip to content

Litestar consumes high amount of CPU #2503

@0asys

Description

@0asys

Description

Running litestar litestar app run with uvicorn consumes in an idling state on my machines 40-45% CPU.

Is this normal or is there a way to reduce the idling CPU consumption?

Attached a picture of cProfile. python -m cProfile -o litestar.pstats ./.venv/bin/litestar run

litestar_profile

URL to code causing the issue

No response

MCVE

UVICORN_LOOP=uvloop litestar run                            
Using Litestar app from env: 'app.asgi:create_app'
Starting server process ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┌──────────────────────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Litestar version2.2.1                                                                                                        │
│ Debug modeDisabled                                                                                                     │
│ Python Debugger on exceptionDisabled                                                                                                     │
│ CORSEnabled                                                                                                      │
│ CSRFDisabled                                                                                                     │
│ OpenAPIEnabled path=/schema                                                                                         │
│ CompressionDisabled                                                                                                     │
│ Template engineViteTemplateEngine                                                                                           │
│ Static filespath=/static dirs=.../src/app/domain/web/public html_mode=Enabled │
│ MiddlewaresJWTCookieAuthenticationMiddleware, SentryLitestarASGIMiddleware, middleware_factory                          │
└──────────────────────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
2023-10-23T19:12:38.780745Z [info     ] Started server process [4257]  [uvicorn.error] 
2023-10-23T19:12:38.781923Z [info     ] Waiting for application startup. [uvicorn.error] 
2023-10-23T19:12:38.789916Z [info     ] Application startup complete.  [uvicorn.error] 
2023-10-23T19:12:38.792650Z [info     ] Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) [uvicorn.error] 
^C2023-10-23T19:15:04.770399Z [info     ] Shutting down                  [uvicorn.error] 
^C2023-10-23T19:15:04.910332Z [info     ] Finished server process [4257] [uvicorn.error] 
^C2023-10-23T19:15:04.974529Z [info     ] ASGI 'lifespan' protocol appears unsupported. [uvicorn.error] 


### Steps to reproduce

```bash
- Run `litestar run`
- Look process ressources

Screenshots

litestar_profile

Logs

No response

Litestar Version

2.2.1
python3.11

Platform

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs MCVEThis needs an MCVEQuestionThis is a question and further information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions