You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/10/01 10:14:35 UTC

[GitHub] [pulsar] thetumbled commented on a diff in pull request #17820: [Bugfix] [LinuxInfoUtils] incorrect CPU usage collected by pulsar #17815

thetumbled commented on code in PR #17820:
URL: https://github.com/apache/pulsar/pull/17820#discussion_r985081349


##########
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:
   you are right.



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org