Skip to content

Commit

Permalink
Avoid the occurrence of 0 physical cpu cores (#6505) (#7946)
Browse files Browse the repository at this point in the history
close #6504
  • Loading branch information
ti-chi-bot authored Aug 16, 2023
1 parent 203a6c4 commit 23ab4d7
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions dbms/src/Common/getNumberOfCPUCores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <Common/Logger.h>
#include <Common/getNumberOfCPUCores.h>
#include <common/logger_useful.h>
#include <common/types.h>

namespace CPUCores
Expand Down Expand Up @@ -58,6 +60,15 @@ void computeAndSetNumberOfPhysicalCPUCores(UInt16 number_of_logical_cpu_cores_,
// - `(hardware_logical_cpu_cores / number_of_hardware_physical_cores)` means how many logical cpu core a physical cpu core has.
// - `number_of_logical_cpu_cores_ / (hardware_logical_cpu_cores / number_of_hardware_physical_cores)` means how many physical cpu cores the tiflash process could use. (Actually, it's needless to get physical cpu cores in virtual environment, but we must ensure the behavior `1` is not broken)
auto hardware_logical_cpu_cores = std::thread::hardware_concurrency();
UInt16 physical_cores = number_of_logical_cpu_cores_ / (hardware_logical_cpu_cores / number_of_hardware_physical_cores);
CPUCores::number_of_physical_cpu_cores = physical_cores > 0 ? physical_cores : 1;
UInt16 physical_cpu_cores = number_of_logical_cpu_cores_ / (hardware_logical_cpu_cores / number_of_hardware_physical_cores);
CPUCores::number_of_physical_cpu_cores = physical_cpu_cores > 0 ? physical_cpu_cores : 1;
auto log = DB::Logger::get("CPUCores");
LOG_INFO(
log,
"logical cpu cores: {}, hardware logical cpu cores: {}, hardware physical cpu cores: {}, physical cpu cores: {}, number_of_physical_cpu_cores: {}",
number_of_logical_cpu_cores_,
hardware_logical_cpu_cores,
number_of_hardware_physical_cores,
physical_cpu_cores,
CPUCores::number_of_physical_cpu_cores);
}

0 comments on commit 23ab4d7

Please sign in to comment.