5

Let's say I got 2 quadcore processors (8x 2,13Ghz). The server runs multiple programs which can only utilize 1 core + Nginx and Apache worker at the same time.

The question is, does Linux efficiently allocate the single threaded programs to each core so that each program can utilize the full power of 1 core and does not interfere with the load of Apache and Nginx. So basically making sure that all cores are being used and not heap so the programs may end up lagging?

3 Answers3

7

A good answer to your question is much too complicated for SF. A short answer would be "yes", Linux and most modern OSes balance processes that are ready to run across available processors very efficiently.

There are techniques to modify how processes are allocated to resources, including changing schedulers are assigning processes to particular processors, but I wouldn't recommend using any of them without really understanding what they do or using them to solve a specific problem.

Also, both nginx and Apache httpd multithread/multiprocess by default. It would be very odd that they run as a single process. They don't poll network connections/flows, they use a kernel call to stop running when there's nothing to do and automatically wake up when there is something to do.

Chris S
  • 77,945
  • 11
  • 124
  • 216
3

Linux is primarily concerned with maximizing CPU utilization by load balancing the threads over all available cores. This dosen't mean to say that Linux arbitrarily decides to place certain threads on certain cores but it uses a process scheduling algorithm to decide what is the most efficient way to distribute the threads over all the cores. So the answer to your question is yes. If you would like to more I would suggest "Understanding the Linux Kernel" by Bovet & Cesati.

Eamonn Travers
  • 614
  • 4
  • 11
0

If by "multiple programs which can only utilize 1 core" you mean programs you can modify the source for, consider adding a call to sched_setscheduler() during thread init to give the scheduler a hint as to how you would like each thread scheduled. The linux scheduler is pretty darn amazing IMHO but the more information it has the better it can do its job! sched_setscheduler() is a priviledge system call, the thread calling it has to at least have the CAP_SYS_NICE capability and possibly others.

Whilom Chime
  • 131
  • 4