Introduce a thread number reallocation table#10
Conversation
Signed-off-by: Titouan Christophe <tchristophe@scortex.io>
Signed-off-by: Titouan Christophe <tchristophe@scortex.io>
|
This is a great addition! I think I understand the mechanism. By pushing and popping thread numbers to the reallocation table ring buffer, you ensure arbitrary gaps anywhere in the array of threads being tracked can be re-used, and everything is constant-time lookups. Very efficient. I'll do a bit of testing, but am pretty much happy to merge this when you are happy with it. |
|
Ah I see why this is a WIP, we'll need a mechanism to clear the stats that are collected in |
Signed-off-by: Titouan Christophe <tchristophe@scortex.io>
|
Thank you @chrisjbillington for your first comments ! I just pushed an additional commit with a mechanism to reset the counters when a thread has terminated. Could you please have a look at it and tell me if this looks correct to you ?
Yes indeed, and 15 days after opening the PR, I can now see that this wasn't evident at first. Would you like me to add some comments to explain this in the code ? |
|
Hello again @chrisjbillington ! Just wanted to check if you had the opportunity to have a look at this PR over the last weeks ? |
Some applications or libraries can spawn many short-lived threads. Because the size of the thread tracking table is fixed (to 1024 elements), the available slots could quickly get exhausted, and gil_load will simply print
gil_load warning: too many threads, not all will be tracked.To work around this problem, we can detect when a thread dies, and mark its thread number as reusable. In such case, as long as there are not more than 1024 concurrent threads (running at the same time), they can all be tracked.
Example application: