pydantic / pydantic/httpx2

High CPU usage if request content is bytes

Open
#737 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.5k
Forks
78
Avg merge
8h 59m
Merged PRs (30d)
24

Description

Originally opened by @kice on 2023-01-26 08:56:35 in encode/httpx

I noticed a increase of CPU usage after I changed request content from content=io.BytesIO(b'<actual data>') to content=b'<actual data>'. The content I want to send is 10MB in size, which is not that much, but still considerable amount of data.

My code is running on a VPS with low end CPU, which makes it much more dramatic (from peek at 40% to pinned at 100%).

I would like to help debug this issue, but I need some instructions to do so.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report by comparing a 10MB bytes request body with the equivalent io.BytesIO content on the affected HTTP client. Trace request-content handling to identify why the bytes form causes sustained CPU usage, then verify that both forms send the same data without the reported CPU spike.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.