Pyactuator showing 9 threads when running single thread in threads.count
ericsouza opened this issue · 4 comments
Hi, first, this plugin is amazing, congratulations!!
Well, I'm using with Flask app serving with waitress.
When I run with one thread it shows 9 on pyctuator, when run with two thread it shows 10 on pyctuator and so on. Is this right?
Hi @ericsouza , thank you for your feedback!
Under the hood, Pyctuator uses sys._current_frames()
to obtain a list of current threads and then introspect each one.
The documentation on sys._current_frames()
states (somewhat enigmatically) that:
This function should be used for internal and specialized purposes only.
without specifying what the valid use cases are.
I'm not familiar with waitress, but I can imagine it having some background threads working to collect metrics, garbage collect, serve debug APIs, etc. Looking at their documentation, it seems that threads
configures "The number of threads used to process application logic (integer).", so maybe they have some other threads which are not for application logic...
Can you share a screenshot of the threads you see, as well as the configuration you use?
If there's a bug in the threading module's code we'd be happy to find it and fix it, so the more details you can give us - the better!
Hey @MatanRubin. Well, it's probably something that I don't know about the way threads works on python (I actually am a new developer). I tried just using flask run
with debug disabled just and it shows 10 threads at thread.count
Below is my pyctuator/metrics/thread.count json output :
{
"availableTags": [
],
"baseUnit": "Integer",
"description": null,
"measurements": [
{
"statistic": "COUNT",
"value": 10
}
],
"name": "thread.count""
}
I'm not sure of what you mean by show my the threads, you mean threads on my machine with ps -ef ?
Threading in Python is an interesting topic. In CPython threads are not OS threads, but virtual threads - they all run on the same OS thread. This is a good resource to start reading about the subject.
Note that Pyctuator shows you the thread count under the metrics
endpoint, and you can also see actual stack traces for each thread using the threaddump
endpoint.
If you're using Spring Boot Admin you can see this visually under the "Thread Dump" tab:
And if you click a thread you can see its stack trace:
To get all of this working quickly you can take a look at the Flask Pyctuator Example
Ow! Such amazing things!! Thank you @MatanRubin. I will read the resource and close the topic. 😁