You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "heesung-sn (via GitHub)" <gi...@apache.org> on 2023/04/27 01:27:37 UTC

[GitHub] [pulsar] heesung-sn commented on a diff in pull request #16832: [feature][broker] Support cgroup v2 by using `jdk.internal.platform.Metrics` in Pulsar Loadbalancer

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


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/LinuxInfoUtils.java:
##########
@@ -98,11 +138,14 @@ public static double getTotalCpuLimit(boolean isCGroupsEnabled) {
      * Get CGroup cpu usage.
      * @return Cpu usage
      */
-    public static double getCpuUsageForCGroup() {
+    public static long getCpuUsageForCGroup() {
         try {
+            if (metrics != null && getCpuUsageMethod != null) {
+                return (long) getCpuUsageMethod.invoke(metrics);

Review Comment:
   For backward compatibility, don't we need to multiply the limit in calculateBrokerHostUsage?
   ```
   public void calculateBrokerHostUsage() {
   ... 
          double totalCpuLimit = getTotalCpuLimit(isCGroupsEnabled);
           if (isCGroupsEnabled && metrics != null && getCpuUsageMethod != null) {
               // cgroup cpuUsage is already scaled, [0.0, 1.0]
               usage.setCpu(new ResourceUsage(cpuUsage * totalCpuLimit, totalCpuLimit));
           } else {
               usage.setCpu(new ResourceUsage(cpuUsage, totalCpuLimit));
           }
           
   ```



-- 
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