You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@celeborn.apache.org by GitBox <gi...@apache.org> on 2022/11/15 14:32:27 UTC

[GitHub] [incubator-celeborn] FMX commented on a diff in pull request #970: [CELEBORN-3] Add metrics for top disk usage apps for version 0.1.x.

FMX commented on code in PR #970:
URL: https://github.com/apache/incubator-celeborn/pull/970#discussion_r1022861103


##########
server-master/src/main/java/com/aliyun/emr/rss/service/deploy/master/metrics/AppDiskUsageMetric.scala:
##########
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.aliyun.emr.rss.service.deploy.master.metrics
+
+import java.util
+import java.util.concurrent.TimeUnit
+import java.util.concurrent.atomic.AtomicReference
+import com.aliyun.emr.rss.common.RssConf
+import com.aliyun.emr.rss.common.internal.Logging
+import com.aliyun.emr.rss.common.meta.WorkerInfo
+import com.aliyun.emr.rss.common.util.{ThreadUtils, Utils}
+
+import java.time.LocalDateTime
+import scala.collection.JavaConverters.{iterableAsScalaIterableConverter, mapAsScalaMapConverter}
+
+case class AppDiskUsage(var appId: String, var usage: Long) {
+  override def toString: String = s"Application ${appId} used ${Utils.bytesToString(usage)} "
+}
+
+class AppDiskUsageSnapShot(val topItemCount: Int) extends Logging {
+  val topNItems = new Array[AppDiskUsage](topItemCount)
+  val startSnapShotTime = LocalDateTime.now()
+  var endSnapShotTime: LocalDateTime = _
+
+  def commit(): Unit = {
+    endSnapShotTime = LocalDateTime.now()
+  }
+
+  def updateAppDiskUsage(appId: String, usage: Long): Unit = {
+    val dropIndex = topNItems.indexWhere(usage => usage != null && usage.appId == appId)
+    if (dropIndex != -1) {
+      drop(dropIndex)
+    }
+    val insertIndex = findInsertPosition(usage)
+    if (insertIndex != -1) {
+      shift(insertIndex)
+      topNItems(insertIndex) = AppDiskUsage(appId, usage)
+    }
+  }
+
+  def shift(index: Int): Unit = {
+    for (i <- topItemCount - 1 until index by -1) {
+      topNItems(i) = topNItems(i - 1)
+    }
+  }
+
+  def drop(index: Int): Unit = {
+    for (i <- index until topItemCount - 1) {
+      topNItems(i) = topNItems(i + 1)
+    }

Review Comment:
   Done.



-- 
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: dev-unsubscribe@celeborn.apache.org

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