Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add benchmarking script #923

Merged
merged 1 commit into from
Jun 13, 2024

Conversation

MarkusSintonen
Copy link
Contributor

@MarkusSintonen MarkusSintonen commented Jun 10, 2024

Summary

Adds benchmarking script comparing httpcore against another popular http library aiohttp. Related to performance issues httpcore has encode/httpx#3215.

This runs 500 requests with 20 requests concurrently. The test is repeated 10 times. Test server has simulated latency of 10ms with 2KB response. Simulating a good network connection (eg in data center conditions).

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

tests/benchmark/server.py Outdated Show resolved Hide resolved
@tomchristie
Copy link
Member

Great thanks. Is there any sense in us also having the same benchmark for the threaded case?
Eg. Comparison between requests and httpx.

@MarkusSintonen
Copy link
Contributor Author

Great thanks. Is there any sense in us also having the same benchmark for the threaded case? Eg. Comparison between requests and httpx.

It might make sense for checking the pool optimization with the sync case

@MarkusSintonen
Copy link
Contributor Author

MarkusSintonen commented Jun 11, 2024

@tomchristie I added now here the sync benchmark using requests library as a baseline. Rerun the benchmark for the connection pool optimization #924 and updated the description there. The results look pretty promising for the sync-case. With that httpcore reaches perf levels of requests and is even faster than that.

@karpetrosyan
Copy link
Member

I think the most important part of performance improvement is writing effective benchmarks. So, I have two questions here:

  • Should we run these two benchmarks in one process, or would we get more precision if we isolate them?
  • Should we use requests or urllib3? I suppose httpcore is more akin to an alternative to urllib3 rather than requests :d

@MarkusSintonen MarkusSintonen force-pushed the add-benchmark-script branch 2 times, most recently from 2463317 to 1302d5a Compare June 12, 2024 05:39
@MarkusSintonen
Copy link
Contributor Author

  • Should we run these two benchmarks in one process, or would we get more precision if we isolate them?

It doesnt actually work very well when running in a single process as then the benchmark also includes the server side. The sync benchmark especially breaks as the async server wont be able to process the requests as the sync IO is blocking everything. So it would need also to use some threaded sync server which starts to get complex to my taste just for the benchmarking.

  • Should we use requests or urllib3? I suppose httpcore is more akin to an alternative to urllib3 rather than requests :d

Good point, I think it makes sense to use urllib3 as a baseline. I switched now to urllib3 and updated the benchmark results in the connection pool PR.

@tomchristie
Copy link
Member

Okay, yes.

@tomchristie tomchristie merged commit da86ca4 into encode:master Jun 13, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants