4

I'm attempting to set the affinity of mysql (latest Percona Server) on a 4vCpu VPS virtualized with OpenVZ and running CentOS 6.x.

The command I'm running is taskset -pc 0-1 1026. I've also tried 0,1 instead. The output is:

pid 1026's current affinity list: 0-3
pid 1026's new affinity list: 0-3

So, it does not seem to be 'sticking'. It can be confirmed by running taskset again to find the cpu's available to the process. Is this an issue with my virtualization type, perhaps?

I'm doing this because every now and then I need mysql to run quite hard, and going over 2.0-4.0 for more than 2 hours gets me a restart with my current provider.

Is there a clear reason why this isn't working, or is more troubleshooting required?

Tim
  • 143
  • 2
  • 7

2 Answers2

10

CPU affinity masks are ignored inside OpenVZ containers. You will not be able to get this to "work".

In RHEL5-based kernels we had the notion of virtual cpus: tasks were scheduled on vcpus while the vcpus were somehow distributed among physical cpus. The sched_setaffinity syscall could be used to bind tasks to vcpus then.

This concept was cumbersome and often sub-optimal so in RHEL6 we decided to drop it: currently setting nr_cpus limit for a container is actually equivalent to setting cpulimit. The decision is justified by the fact that the latest Linux scheduler is smart enough to gather actively interacting tasks together so that there is no need to limit parallelism artificially.

As a result, cpu affinity support was dropped. Tasks can still use the sched_setaffinity syscall, but it will be ignored.

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
  • Exactly the definitive answer I was looking for. I didn't come across this in my searches, but it is what I suspected. Unfortunately, I'm not aware of any other ways to limit mysql's processor usage (other than thread-concurrency, but it doesn't seem to do much on the 4 core), so it looks like I'm out of luck. – Tim Jan 05 '15 at 22:03
  • @Tim Use another container, send fewer queries, or optimize the queries you are already sending. – Michael Hampton Jan 05 '15 at 22:10
  • In my truly limited understanding, I'm a bit unsure of why a VPS provider would use OpenVZ over something like KVM in the first place (unless they're simply more familiar with the former.). I think I really just need to migrate to another provider where I don't have to worry about whether or not I can use all the resources for more than an hour or two. For the time being optimizing/reducing the queries much isn't possible, (at least not by more than a negligible amount.). – Tim Jan 06 '15 at 16:22
  • @Tim Because it's cheaper and easier to oversubscribe. That's about it. – Michael Hampton Jan 06 '15 at 16:38
1

A tool like taskset probably won't work properly in a container. You may be able to do this from the host system, but it doesn't make sense from within a container.

See: Taskset not working properly in OpenVZ container

ewwhite
  • 194,921
  • 91
  • 434
  • 799