You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "coderzc (via GitHub)" <gi...@apache.org> on 2023/04/28 13:14:07 UTC

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

coderzc commented on code in PR #16832:
URL: https://github.com/apache/pulsar/pull/16832#discussion_r1180389710


##########
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:
   The `Metrics.getCpuUsage` will return the aggregate time, so I think we don't need to multiply the limit.
   
   ```
       /**
        * Returns the aggregate time, in nanoseconds, consumed by all
        * tasks in the Isolation Group.
        *
        * @return Time in nanoseconds, -1 if unknown or
        *         -2 if the metric is not supported.
        *
        */
       public long getCpuUsage();
   ```



##########
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:
   The `Metrics.getCpuUsage` will return the aggregate time, so I think we don't need to multiply the limit.
   
   ```java
       /**
        * Returns the aggregate time, in nanoseconds, consumed by all
        * tasks in the Isolation Group.
        *
        * @return Time in nanoseconds, -1 if unknown or
        *         -2 if the metric is not supported.
        *
        */
       public long getCpuUsage();
   ```



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