question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Performance issue on outgoing requests

See original GitHub issue

We have an API developed using DRF but recently we switched to FastAPI. We are loving it a lot. This is one of the greatest software that we have ever come across.

Now getting back to the point, our upcoming version of API is built using FastAPI. When we deploy it to a Docker Swarm cluster, regular endpoints (that just return JSON responses without making any computation) perform really great. In our small cluster, we achieved 40K+ requests per second in wrk benchmarks.

But when we call the endpoints where we are making an outgoing request, the performance dramatically decreases. We barely achieve 100 requests per second in our benchmarking tests.

The endpoints where the performance issue is present make outgoing requests and we return data in real-time. We are using a proxy service too so latency issues are there. But the performance difference between the normal endpoints and the ones that get external data and return to the user is really really huge.

We have tried using Gunicorn + Uvicorn worker and Uvicorn alone too. We also tried applying an API gateway like Kong but the performance issue remains there. On the nodes where the API is running CPU usage rises while the API gateway doesn’t go under any load.

Is this a CPU-intensive case or threads are locked when external requests response is awaited? We are using httpx and each API call results in a single external request. Any help will be appreciated greatly.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
STeveSharycommented, Jun 2, 2021

HTTP connection pooling doesn’t work when a rotating proxy is used and the TCP connection needs to be reestablished every time the IP changes.

“Layer of abstraction”: The cause of and solution to all your problems!

1reaction
rehmatworkscommented, Jun 1, 2021

@STeveShary Thank you so much for replying. Looks like you have pointed me in the right direction. I am modifying my code and I’ll run some benchmarking tests again.

  • I’ll give locust.io a try
  • Yes, the endpoints are HTTPS. I am now using HTTP endpoints as well as I am trying pooling
  • I am using HTTPX
  • I am using Sentry but haven’t looked in the logs for this particular issue yet

Thank you for all your help. I’ll be running benchmarking tests again and I’ll share the results.

Update: Connection pooling does work and I achieved 8K+ requests per second and the results were around ~100 requests per second previously. This is a huge difference. But when a rotating proxy is used, the performance degrades again. HTTP connection pooling doesn’t work when a rotating proxy is used and the TCP connection needs to be reestablished every time the IP changes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Analysis of HTTP Performance Problems
Latency problems are caused by opening a single connection per request, through connection setup and slow-start costs. Further avoidable latency is incurred due ......
Read more >
Node.js performance question for outgoing requests
For the very basic simplified case, i'm writing a service1 in node, which sends requests to service2, wait till it finishes the computation...
Read more >
Working with the Outgoing HTTP Requests view
The Outgoing HTTP requests view shows performance data for all the outgoing HTTP requests your application made during the selected time period:.
Read more >
Performance issues when you call web services - ASP.NET
This article provides help to solve the performance issues that occur when you make calls to web services from an ASP.NET application.
Read more >
How to monitor the outgoing http requests
How to monitor the outgoing http requests - Application Performance Monitoring - New Relic Explorers Hub.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found