What’s the best way to profile a Django backend with Celery workers?

0
20
Asked By ChillVegeta45 On

I'm currently working with a sizeable codebase built on Django that utilizes Celery workers for handling our workflows. As our app has grown, it's clear that we need to start profiling and optimizing our code, but I'm a bit lost on what tools are available for this specific stack. I come from a background in compiled languages, where profiling seems a lot simpler. We don't have proper tracing spans set up at this point either. Does anyone have recommendations for profiling this kind of application? I was thinking of creating a script that runs Django and Celery in separate subprocesses and then using pyspy to generate flame graphs or speedscope data after executing some computational commands in a third process. Any guidance would be greatly appreciated!

4 Answers

Answered By DataDiveGuru On

For profiling a site with heavy traffic, I've had success using a few tools. I check for the number of database queries in my Django views during standard tests. This can help you identify potential optimizations—sometimes, a larger query with proper indexes can be more efficient than running thousands of smaller ones. For load testing, I recommend using Locust, and for APM or AWS infrastructure monitoring, New Relic works, although you might also explore alternatives like SigNoz or open source options with OpenTelemetry. If you want to dive deeper into code profiling, Brendan Gregg has some great books on using BPF, DTrace, and other performance tuning techniques.

QueryHunter99 -

Does New Relic provide in-depth stack traces for Python? I've noticed it sometimes shows 'uninstrumented code' when I try to examine transactions, which is super frustrating.

DevGizmo -

How does New Relic stack up against Datadog or Sentry when it comes to profiling? We've tried Datadog, but it seemed to slow our app down significantly.

Answered By ErrorLogger On

Sentry can handle profiling along with various other features quite easily. You might want to check that out if you haven't already.

ProfilerNoob -

I didn't realize Sentry could do that! Do you have any specific tools or features in Sentry that you find particularly helpful?

Answered By PySparkler On

I've had good results using pyinstrument for profiling. It's straightforward and can provide useful insights.

Answered By NerdyNinja On

Starting with logs that include timings can be beneficial for diagnosing performance issues. Even without tracing spans, those logs can pinpoint problems. If your bottlenecks are more on the IO side than CPU, that should help you identify things locally on your machine.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.