jazzband / django-silk

Silky smooth profiling for Django
MIT License
4.41k stars 332 forks source link

Does Django-Silk support profiling multithreaded code? #378

Open pirate opened 4 years ago

pirate commented 4 years ago

We have some IO-bound view handlers that we sped up by using multithreading (plain old threading.Thread, we know multiprocessing is better, but in this case the code was IO-bound, not CPU-bound, so we did't need separate processes to avoid the GIL).

When profiling with django-silk, we can't tell if it's including calls from all of the threads in the output, or just the main thread.

I was also unable to find mentions of multithreading in the documentation or README. Can we add a note about it to the README explaining whether or not it's supported and with what caveats? e.g.

It's supported:

Django-Silk will seamlessly profile threads spawned from a request handler or @silk_profile decorated function.

  • Should work seamlessly with normal ./manage.py runserver and with django-channels (without needing --nothread or --noreload)
  • All calls in subthreads spawned by a given request will appear intermingled with the main thread profiling output (e.g. functions called in a threading.Thread)
  • Does not automatically profile code run in spawned subprocesses (e.g. via multiprocessing, subprocess, etc).

OR

It's not supported:

Django-Silk cannot profile multi-threaded code, so runserver must be run with --nothread --noreload when using silk request profiling.

Thanks! Aside from this and not having a pyflame-style flamegraph view out-of-the-box, the project is awesome and we've found it extremely useful. Is there any way to donate to it?

nasirhjafri commented 4 years ago

I'll have to dig deeper to check if django-silk supports multithreading or not, will update the documentation after that. I'm not sure if jazzband or django-silk is currently accepting any donations.