ably-python icon indicating copy to clipboard operation
ably-python copied to clipboard

Replace httpx with request for sync version

Open sacOO7 opened this issue 2 years ago • 11 comments

  • Related implementation https://github.com/ably/ably-python/pull/200/files
  • This is due to the fact that, httpx causes performance issues when hitting limit of 100k requests/minute.
  • Link to internal discussion ~~> https://ably~~real-time.slack.com/archives/C030C5YLY/p1698238346488369?thread_ts=1697535419.670029&cid=C030C5YLY

┆Issue is synchronized with this Jira Task by Unito

sacOO7 avatar Oct 25 '23 13:10 sacOO7

➤ Automation for Jira commented:

The link to the corresponding Jira issue is https://ably.atlassian.net/browse/SDK-3914

sync-by-unito[bot] avatar Oct 25 '23 14:10 sync-by-unito[bot]

TODO

  • [ ] 1. Reproduce the issue using load testing on a dedicated server.
  • [ ] 2. If reproduced, then make a change to switch to a different library.

@owenpearson has an idea about how to reproduce the issue and do the load testing.

sacOO7 avatar Nov 23 '23 05:11 sacOO7

Some more findings ->

  • Current SDK uses httpx version as 0.24.1 which has dependency on httpcore uses -> 0.17.3
  • Latest version of httpx is 0.25.2, it uses httpcore -> 1.0.2
  • Some critical bugfixes has been addressed in latest version of httpx.
  • While running tests make sure we run it on both older and newer versions of httpx.

sacOO7 avatar Dec 10 '23 12:12 sacOO7

One of the related fix seems to be -> https://github.com/encode/httpcore/pull/823

sacOO7 avatar Dec 10 '23 12:12 sacOO7

The current SDK only supports httpx to be used in http2 mode -> https://github.com/ably/ably-python/blob/10cb4a08c64f915a2878ffd1139b08a50811124d/ably/http/http.py#L132. There is still an active issue for http2 -> https://github.com/encode/httpcore/issues/775 that talks about gracefully closing the connection. Fix is already done for http1.1.

sacOO7 avatar Dec 10 '23 12:12 sacOO7

NEW TODO

  • [ ] 1. Reproduce the issue using load testing on a dedicated server. - [ ] httpx -> 0.24.1 and http2 ( use current SDK as is ! ) - [ ] httpx -> 0.24.1 and http1.1 - [ ] httpx -> 0.25.2 and http2 - [ ] httpx -> 0.25.2 and http1.1
  • [ ] 2. If still facing the issue, then make a change to requests library that uses http 1.1 rather than http2 😒

sacOO7 avatar Dec 10 '23 12:12 sacOO7

I don't know whether it could help your case, but you may consider taking a look at Niquests instead of downgrading to requests. Your feedback would be interesting. Would be happy to get this project where you aim to reach.

Ousret avatar Jan 21 '24 08:01 Ousret

@Ousret Thanks for the suggestion !

sacOO7 avatar Jan 22 '24 07:01 sacOO7

Seems we can use https://locust.io/ as a tool for load testing.

sacOO7 avatar Feb 04 '24 05:02 sacOO7

https://medium.com/@yusufenes3494/how-to-build-your-own-load-test-a-step-by-step-guide-1a8367f7f6a2

Seems locusts by default uses python-requests for executing test against given server https://docs.locust.io/en/stable/increase-performance.html. No wonder, python-requests is stable and doesn't cause issue on high throughput.

Need to check if we can configure other client like httpx instead of default python-requests

sacOO7 avatar Feb 04 '24 06:02 sacOO7

One of the way is to clone python-locust project and modify https://github.com/locustio/locust/blob/master/locust/clients.py file to use httpx client instead of python-requests. This will help us to use all features of locust client like result tracking, without writing explicit code for the same.

sacOO7 avatar Feb 04 '24 06:02 sacOO7