[Maria-discuss] mariadb runs at lowest priority (nice -n 19)
Hi, I just noticed that all our MariaDB 5.2 servers show the same: $ ps -eo ni,comm |grep mysql 9 mysqld_safe 19 mysql_isam_spac <defunct> 19 mysqld While servers with Oracle MySQL are at nice -n 0 I tried setting niceness=-10 in /usr/bin/mysqld_safe but with no effect. Is there a reason to run MariaDB at the lowest possible priority and is there a way to change that?
Hi!
"Panayot" == Panayot Belchev <panayot@panayot.com> writes:
Panayot> Hi, Panayot> I just noticed that all our MariaDB 5.2 servers show the same: Panayot> $ ps -eo ni,comm |grep mysql Panayot> 9 mysqld_safe Panayot> 19 mysql_isam_spac <defunct> Panayot> 19 mysqld Panayot> While servers with Oracle MySQL are at nice -n 0 Panayot> I tried setting Panayot> niceness=-10 Panayot> in /usr/bin/mysqld_safe but with no effect. Is there a reason to run Panayot> MariaDB at the lowest possible priority and is there a way to change Panayot> that? The code for MariaDB when it comes to priority should be identical to MySQL. I did a quick test of just starting 'mysqld' in MySQL and MariaDB and noticed the above too. After some debugging I found the following in the pbxt code: ----------- if (pth_min_priority == pth_max_priority) { /* Under Linux the priority of normal (non-runtime) * threads are set using the standard methods * for setting process priority. */ /* We could set who == 0 because it should have the same affect * as using the PID. */ /* -20 = highest, 20 = lowest */ if (setpriority(PRIO_PROCESS, getpid(), 20) == -1) return errno; return 0; } ------------ This causes the mysqld process to be set to -19, which is clearly wrong as pbxt should not affect the priority of it's caller. For Paul: pth_min_priority and pth_max_priority are both 0 here. I will for now ifdef away the above call to setpriority() in 5.1 and above until we have a better solution. A workaround until that is to disable pbxt with --skip-pbxt. Please add the above to your my.cnf file and the above problems disappears! Regards, Monty
Hi Monty, Paul This msg is to be sure the right (PBXT) Paul sees it... Monty sent to paul@kitebird which if I remember correctly is one of Paul Dubois' addresses ;-) Cheers, Arjen. ----- Original Message ----- Hi!
"Panayot" == Panayot Belchev <panayot@panayot.com> writes:
Panayot> Hi, Panayot> I just noticed that all our MariaDB 5.2 servers show the same: Panayot> $ ps -eo ni,comm |grep mysql Panayot> 9 mysqld_safe Panayot> 19 mysql_isam_spac <defunct> Panayot> 19 mysqld Panayot> While servers with Oracle MySQL are at nice -n 0 Panayot> I tried setting Panayot> niceness=-10 Panayot> in /usr/bin/mysqld_safe but with no effect. Is there a reason to run Panayot> MariaDB at the lowest possible priority and is there a way to change Panayot> that? The code for MariaDB when it comes to priority should be identical to MySQL. I did a quick test of just starting 'mysqld' in MySQL and MariaDB and noticed the above too. After some debugging I found the following in the pbxt code: ----------- if (pth_min_priority == pth_max_priority) { /* Under Linux the priority of normal (non-runtime) * threads are set using the standard methods * for setting process priority. */ /* We could set who == 0 because it should have the same affect * as using the PID. */ /* -20 = highest, 20 = lowest */ if (setpriority(PRIO_PROCESS, getpid(), 20) == -1) return errno; return 0; } ------------ This causes the mysqld process to be set to -19, which is clearly wrong as pbxt should not affect the priority of it's caller. For Paul: pth_min_priority and pth_max_priority are both 0 here. I will for now ifdef away the above call to setpriority() in 5.1 and above until we have a better solution. A workaround until that is to disable pbxt with --skip-pbxt. Please add the above to your my.cnf file and the above problems disappears! Regards, Monty _______________________________________________ Mailing list: https://launchpad.net/~maria-discuss Post to : maria-discuss@lists.launchpad.net Unsubscribe : https://launchpad.net/~maria-discuss More help : https://help.launchpad.net/ListHelp
The intension of this code was to set the priority of the current running thread only, not the entire program. If the code is not working in this manner, then there is no better solution that to disable it. However it would be nice in the cases where pthread_setschedparam() does work, that it is called. In the current code, pthread_setschedparam() is called when pth_min_priority != pth_max_priority. On May 27, 2011, at 12:58 AM, Arjen Lentz wrote:
Hi Monty, Paul
This msg is to be sure the right (PBXT) Paul sees it... Monty sent to paul@kitebird which if I remember correctly is one of Paul Dubois' addresses ;-)
Cheers, Arjen.
----- Original Message -----
Hi!
"Panayot" == Panayot Belchev <panayot@panayot.com> writes:
Panayot> Hi, Panayot> I just noticed that all our MariaDB 5.2 servers show the same:
Panayot> $ ps -eo ni,comm |grep mysql
Panayot> 9 mysqld_safe Panayot> 19 mysql_isam_spac <defunct> Panayot> 19 mysqld
Panayot> While servers with Oracle MySQL are at nice -n 0
Panayot> I tried setting
Panayot> niceness=-10
Panayot> in /usr/bin/mysqld_safe but with no effect. Is there a reason to run Panayot> MariaDB at the lowest possible priority and is there a way to change Panayot> that?
The code for MariaDB when it comes to priority should be identical to MySQL.
I did a quick test of just starting 'mysqld' in MySQL and MariaDB and noticed the above too.
After some debugging I found the following in the pbxt code:
-----------
if (pth_min_priority == pth_max_priority) { /* Under Linux the priority of normal (non-runtime) * threads are set using the standard methods * for setting process priority. */
/* We could set who == 0 because it should have the same affect * as using the PID. */
/* -20 = highest, 20 = lowest */ if (setpriority(PRIO_PROCESS, getpid(), 20) == -1) return errno; return 0; } ------------
This causes the mysqld process to be set to -19, which is clearly wrong as pbxt should not affect the priority of it's caller.
For Paul: pth_min_priority and pth_max_priority are both 0 here.
I will for now ifdef away the above call to setpriority() in 5.1 and above until we have a better solution.
A workaround until that is to disable pbxt with --skip-pbxt. Please add the above to your my.cnf file and the above problems disappears!
Regards, Monty
_______________________________________________ Mailing list: https://launchpad.net/~maria-discuss Post to : maria-discuss@lists.launchpad.net Unsubscribe : https://launchpad.net/~maria-discuss More help : https://help.launchpad.net/ListHelp
_______________________________________________ Mailing list: https://launchpad.net/~maria-discuss Post to : maria-discuss@lists.launchpad.net Unsubscribe : https://launchpad.net/~maria-discuss More help : https://help.launchpad.net/ListHelp
-- Paul McCullagh PrimeBase Technologies www.primebase.org www.blobstreaming.org pbxt.blogspot.com
Hi!
"Paul" == Paul McCullagh <paul.mccullagh@primebase.org> writes:
Paul> The intension of this code was to set the priority of the current Paul> running thread only, not the entire program. Paul> If the code is not working in this manner, then there is no better Paul> solution that to disable it. Paul> However it would be nice in the cases where pthread_setschedparam() Paul> does work, that it is called. Agree, but I don't know how to test for this case :( At least on linux, using setpriority() will not work with any modern Linux. Paul> In the current code, pthread_setschedparam() is called when Paul> pth_min_priority != pth_max_priority. Current code ? Do you mean that this has been changed recently ? (It was not a long time ago when we merged with the latest pbxt, so I assumed we have the latest code already). The pbxt code in the MariaDB tree is bascily: (from xt_p_set_low_priority()): if (pth_min_priority == pth_max_priority) setpriority() else pth_set_priority() It's the call to setpriority() that should be avoided in all cases. Don't see how to fix this for linux except by adding an ifdef around the call to setpriority(). Do you know of any system, except old obsolete linux systems, where one should use setpriority() to set the priority for a thread? Regards, Monty PS: Sorry for the delayed answer but I have been on vacation...
On Jun 6, 2011, at 11:23 AM, Michael Widenius wrote:
Hi!
"Paul" == Paul McCullagh <paul.mccullagh@primebase.org> writes:
Paul> The intension of this code was to set the priority of the current Paul> running thread only, not the entire program.
Paul> If the code is not working in this manner, then there is no better Paul> solution that to disable it.
Paul> However it would be nice in the cases where pthread_setschedparam() Paul> does work, that it is called.
Agree, but I don't know how to test for this case :( At least on linux, using setpriority() will not work with any modern Linux.
Paul> In the current code, pthread_setschedparam() is called when Paul> pth_min_priority != pth_max_priority.
Current code ?
Do you mean that this has been changed recently ?
No, this has not been changed in years.
(It was not a long time ago when we merged with the latest pbxt, so I assumed we have the latest code already).
The pbxt code in the MariaDB tree is bascily: (from xt_p_set_low_priority()):
if (pth_min_priority == pth_max_priority) setpriority() else pth_set_priority()
It's the call to setpriority() that should be avoided in all cases.
Don't see how to fix this for linux except by adding an ifdef around the call to setpriority().
Do you know of any system, except old obsolete linux systems, where one should use setpriority() to set the priority for a thread?
I have done no research on this, so I think we should simply change the code to: if (pth_min_priority != pth_max_priority) pth_set_priority() This would mean the thread priority is not changed, but that better than mistakingly changing the program priority. -- Paul McCullagh PrimeBase Technologies www.primebase.org www.blobstreaming.org pbxt.blogspot.com
Hi!
"Paul" == Paul McCullagh <paul.mccullagh@primebase.org> writes:
<cut>
Do you know of any system, except old obsolete linux systems, where one should use setpriority() to set the priority for a thread?
Paul> I have done no research on this, so I think we should simply change Paul> the code to: Paul> if (pth_min_priority != pth_max_priority) Paul> pth_set_priority() Paul> This would mean the thread priority is not changed, but that better Paul> than mistakingly changing the program priority. Sounds good. I have now done this change in MariaDB 5.2 (I assume this is what you meant) === modified file 'storage/pbxt/src/pthread_xt.cc' --- storage/pbxt/src/pthread_xt.cc 2011-05-26 11:38:17 +0000 +++ storage/pbxt/src/pthread_xt.cc 2011-06-13 13:39:43 +0000 @@ -547,44 +547,23 @@ xtPublic void xt_p_init_threading(void) xtPublic int xt_p_set_low_priority(pthread_t thr) { - if (pth_min_priority == pth_max_priority) { - /* Under Linux the priority of normal (non-runtime) - * threads are set using the standard methods - * for setting process priority. - */ - - /* We could set who == 0 because it should have the same affect - * as using the PID. - */ - - /* -20 = highest, 20 = lowest */ - if (setpriority(PRIO_PROCESS, getpid(), 20) == -1) - return errno; - return 0; - } - return pth_set_priority(thr, pth_min_priority); + if (pth_min_priority != pth_max_priority) + return pth_set_priority(thr, pth_min_priority); + return 0; } xtPublic int xt_p_set_normal_priority(pthread_t thr) { - if (pth_min_priority == pth_max_priority) { - if (setpriority(PRIO_PROCESS, getpid(), 0) == -1) - return errno; - return 0; - } - return pth_set_priority(thr, pth_normal_priority); + if (pth_min_priority != pth_max_priority) + return pth_set_priority(thr, pth_normal_priority); + return 0; } xtPublic int xt_p_set_high_priority(pthread_t thr) { - if (pth_min_priority == pth_max_priority) { - if (setpriority(PRIO_PROCESS, getpid(), -20) == -1) - return errno; - return 0; - } - return pth_set_priority(thr, pth_max_priority); + if (pth_min_priority != pth_max_priority) + return pth_set_priority(thr, pth_max_priority); + return 0; } Regards, Monty
Hi!
"Panayot" == Panayot Belchev <panayot@panayot.com> writes:
Panayot> Hi, Panayot> I just noticed that all our MariaDB 5.2 servers show the same: Panayot> $ ps -eo ni,comm |grep mysql Panayot> 9 mysqld_safe Panayot> 19 mysql_isam_spac <defunct> Panayot> 19 mysqld I digged a bit deeper into this Panayot> While servers with Oracle MySQL are at nice -n 0 pthread_setschedparam() uses sched_getscheduler() to set the priority. It's called with pthread_setschedparam(thread, POLICY, &sp), where POLICY == SCHED_OTHER
From 'man sched_setscheduler'
Scheduling Policies The scheduler is the kernel component that decides which runnable process will be executed by the CPU next. Each process has an associ ated scheduling policy and a static scheduling priority, sched_prior ity; these are the settings that are modified by sched_setscheduler(). The scheduler makes it decisions based on knowledge of the scheduling policy and static priority of all processes on the system. For processes scheduled under one of the normal scheduling policies (SCHED_OTHER, SCHED_IDLE, SCHED_BATCH), sched_priority is not used in scheduling decisions (it must be specified as 0). As you are calling this with sched_priority <> 0, pthread_setschedparam() will return EINVAL which has the effect that pth_min_priority and pth_max_priority are always 0, which casues xt_p_set_low_priority() to misbehave. This is at least the case on SuSE 11.4 and Linux 2.6.37.6-0.5. Regards, Monty
participants (4)
-
Arjen Lentz
-
Michael Widenius
-
Panayot Belchev
-
Paul McCullagh