[MDEV-32537] Set thread names for MariaDB Server threads Created: 2023-10-21 Updated: 2024-01-25 |
|
| Status: | Stalled |
| Project: | MariaDB Server |
| Component/s: | None |
| Fix Version/s: | 11.5 |
| Type: | Task | Priority: | Major |
| Reporter: | Valerii Kravchuk | Assignee: | Vladislav Vaintroub |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Description |
|
Multi-threaded Linux programs (like Firefox or MySQL since 8.0.27 or so) usually set a name for each thread. This name will appear in the output of top and other utilities and would help to answer questions like "What thread uses most of CPU" etc. Consider this example of MySQL 8.0.29:
For MariaDB (10.6 here for example) we get:
See also https://bugs.mysql.com/bug.php?id=70858 It makes sense to use the same thread name as used in Performance Schema. |
| Comments |
| Comment by Vladislav Vaintroub [ 2023-10-21 ] | ||||||||||
|
Compared to MySQL, MariaDB has only few single purpose threads. There is timer thread, there is page cleaner thread, there is a main thread, that accepts connections, and nothing interesting otherwise. there can be a bunch of background threads, from a threadpool, that handle innodb background work, and a bunch of foreground threads, that handle user queries ( from thread pool or not). I'm wondering if you can gain much from such info | ||||||||||
| Comment by Valerii Kravchuk [ 2023-10-21 ] | ||||||||||
|
I'd really be happy to know if CPU is used by a specific foreground user thread, some of slave applier threads or some background InnoDB thread. | ||||||||||
| Comment by Nikita Malyavin [ 2024-01-18 ] | ||||||||||
|
left a few notes in https://github.com/MariaDB/server/commit/7e53e7729bf58a0e806424d538ed086f44304c1b | ||||||||||
| Comment by Sergei Golubchik [ 2024-01-18 ] | ||||||||||
|
May be, let's avoid multiplying entities without a necessity?
the thread is started as
so in mysql_thread_create() performance schema can use pthread_setname_np() or whatever for the return value of pthread_create(), setting the name for the new thread. And users will see the same name in ps and in select * from performance_schema.threads. Less confusion. | ||||||||||
| Comment by Vladislav Vaintroub [ 2024-01-18 ] | ||||||||||
|
serg, this does not work.
Thread names are for debugging and profiling, and that's it. | ||||||||||
| Comment by Sergei Golubchik [ 2024-01-18 ] | ||||||||||
|
I thought another option could be to set the name inside the thread, but have a DBUG_ASSERT that it matches the name in perfschema. Then it'll still be "one entity" from the user point of view, even if we'll specify the name in two places (or one can #define STATEMENT_TIMER_THREAD_NAME and use it everywhere). As for many threads with the same name, I thought it'd be useful to print them like, say, "statement_timer:1234" where "1234" is, ideally, the id in the performance_schema.threads. The point is still to show not some arbitrary info but something that correlates with other information sources. For example, one can use ps to find the thread that takes 100% CPU and then use performance_schema to find out more. | ||||||||||
| Comment by Vladislav Vaintroub [ 2024-01-23 ] | ||||||||||
|
serg I sort-of did this verification in the last patch. Not sure it is a good idea, and strictly speaking we can't have the very same entity from the user's point of view. Because, Linux does not accept long names (where long is > 15 characters), one can't have thread names like "thread/innodb/page_cleaner", you can't even have names like 'innodb/page_cleaner'. Only names like 'page_cleaner' are possible, due to Linux limitations. I thought a bit about many threads with the same name, I actually would prefer them to have the same name by default (unless maybe an option is set). | ||||||||||
| Comment by Sergei Golubchik [ 2024-01-24 ] | ||||||||||
|
Thanks. That explains why firefox names threads like
Agree about not appending numeric ids, not even for your profiler sake, but simply because the length is such a scarce resource, we shouldn't waste it on something that can be stored elsewhere, such a thread id. Then what about — the same name as the last component of name in perfschema. Assert if such a last component is longer than 15 characters, it'll limit our imagination a bit, but I'm sure we'll manage. PERFORMANCE_SCHEMA.THREADS has columns NAME and OS_THREAD_ID, they should match the values from
("match" in the above sense. for tid it's "equal", for "comm" it's "last component of") |