Cómo hacer que php y mysql usen diferentes núcleos

Kinda struggeling with mysql again...

Setup: vServer with 4 Cores, 1 gig RAM. Ubuntu 12.04 LTS, Serverpilot installed Apache (behind NGinx), PHP and MySQL.

When I run a script (runs kinda long, a few hours), it uses exactly 1 core - about 70% php, the rest mysql. Not stable of course, sometimes mysql isn't active at all, etc.

Is there a way to make mysql run on a different core? Connect to mysql via external IP does not solve it... ;-)

¡Muchas gracias!

preguntado el 12 de junio de 14 a las 10:06

The question is irrelevant. When your PHP accesses the MySQL database the PHP is put on hold (blocking), so it's not actually using any core at all at that point. Which core MySQL then uses is neither here nor there as they're all available for use. To more effectively use multiple cores you need to rethink your script to work in a parallel fashion. -

If you really want to force the CPU affinity of a process, which won't speed up your script, this is how: cyberciti.biz/tips/… -

Thanks for your responses, sorry left it there for a few days. It still seems strange to me, that it looks like MySQL and PHP together use exactly one cores power but I will try to setup pthreads. -

2 Respuestas

I fear that your problem is that PHP is not a Threaded language. There are no good ways to do parallel processing in PHP (hilos de rosca looks promising, but I was not able to build it successfully last I tried), which is probably what you really would need to speed up this script.

Respondido el 12 de junio de 14 a las 15:06

Check out numactl (http://linux.die.net/man/8/numactl) which you can include in your launcher for mysql. You could also use cset and taskset depending on what your distribution recommends, but that's how you can bind any process to a single core or package.

Respondido el 12 de junio de 14 a las 11:06

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.