heesung-sn commented on code in PR #17820:
URL: https://github.com/apache/pulsar/pull/17820#discussion_r985158091


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/LinuxInfoUtils.java:
##########
@@ -72,6 +73,31 @@ public static boolean isCGroupEnabled() {
         }
     }
 
+    /**
+     *  Get total cpu count.
+     * @return Total cpu count
+     */
+    public static int getTotalCpuCount() {
+        int totalCpuCount=0;
+        try {
+            String[] ranges = 
readTrimStringFromFile(Paths.get(CGROUPS_CPU_CPUSET_CPUS)).split(",");
+            for (String range : ranges) {
+                if (!range.contains("-")) {
+                    totalCpuCount++;
+                } else {
+                    int dashIndex = range.indexOf('-');
+                    int left = Integer.valueOf(range.substring(0, dashIndex));
+                    int right = Integer.valueOf(range.substring(dashIndex + 
1));
+                    totalCpuCount += right - left + 1;
+                }
+            }
+        } catch (IOException e) {
+            log.warn("[LinuxInfo] Failed to read CPU counts from cgroups", e);
+            // Fallback to availableProcessors

Review Comment:
   Also please confirm if this can fallback to the next cpu limit getter 
logic,if it outputs 0 cpu count.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to