@@ -223,20 +223,25 @@ class LifecycleManager(val appUniqueId: String, val conf: CelebornConf) extends
223223 }
224224
225225 private val masterClient = new MasterClient (masterRpcEnvInUse, conf, false )
226- val clientSource = new CelebornClientSource (conf)
227- private [client] val clientMetricsEnabled = conf.metricsSystemEnable && conf.clientMetricsEnabled
226+ private val clientMetricsEnabled = conf.metricsSystemEnable && conf.clientMetricsEnabled
227+ val clientSource : Option [CelebornClientSource ] =
228+ if (clientMetricsEnabled) Some (new CelebornClientSource (conf)) else None
229+
230+ @ inline private [client] def incClientMetric (name : String , delta : Long = 1L ): Unit =
231+ clientSource.foreach(_.incCounter(name, delta))
228232 val commitManager = new CommitManager (appUniqueId, conf, this )
229233 val workerStatusTracker = new WorkerStatusTracker (conf, this )
230- if (clientMetricsEnabled) {
231- clientSource .addGauge(CelebornClientSource .ACTIVE_SHUFFLE_COUNT ) { () =>
234+ clientSource.foreach { source =>
235+ source .addGauge(CelebornClientSource .ACTIVE_SHUFFLE_COUNT ) { () =>
232236 registeredShuffle.size
233237 }
234- clientSource .addGauge(CelebornClientSource .EXCLUDED_WORKER_COUNT ) { () =>
238+ source .addGauge(CelebornClientSource .EXCLUDED_WORKER_COUNT ) { () =>
235239 workerStatusTracker.excludedWorkers.size
236240 }
237- clientSource .addGauge(CelebornClientSource .SHUTTING_WORKER_COUNT ) { () =>
241+ source .addGauge(CelebornClientSource .SHUTTING_WORKER_COUNT ) { () =>
238242 workerStatusTracker.shuttingWorkers.size
239243 }
244+ source.start()
240245 }
241246 private val heartbeater =
242247 new ApplicationHeartbeater (
@@ -252,11 +257,8 @@ class LifecycleManager(val appUniqueId: String, val conf: CelebornConf) extends
252257 registeredShuffle,
253258 reason => cancelAllActiveStages(reason),
254259 () =>
255- if (clientMetricsEnabled) {
256- clientSource.getMetricsSnapshot().asJava
257- } else {
258- new util.HashMap [String , ClientMetric ]()
259- })
260+ clientSource.map(_.getMetricsSnapshot().asJava)
261+ .getOrElse(new util.HashMap [String , ClientMetric ]()))
260262 private def resetFallbackCounts (counts : ConcurrentHashMap [String , java.lang.Long ])
261263 : Map [String , java.lang.Long ] = {
262264 val fallbackCounts = new util.HashMap [String , java.lang.Long ]()
@@ -747,13 +749,9 @@ class LifecycleManager(val appUniqueId: String, val conf: CelebornConf) extends
747749
748750 // Reply to all RegisterShuffle request for current shuffle id.
749751 def replyRegisterShuffle (response : RegisterShuffleResponse ): Unit = {
750- if (clientMetricsEnabled) {
751- if (response.status == StatusCode .SUCCESS ) {
752- clientSource.incCounter(CelebornClientSource .REGISTER_SHUFFLE_COUNT )
753- } else {
754- clientSource.incCounter(CelebornClientSource .REGISTER_SHUFFLE_FAIL_COUNT )
755- }
756- }
752+ incClientMetric(
753+ if (response.status == StatusCode .SUCCESS ) CelebornClientSource .REGISTER_SHUFFLE_COUNT
754+ else CelebornClientSource .REGISTER_SHUFFLE_FAIL_COUNT )
757755 registeringShuffleRequest.synchronized {
758756 val serializedMsg : Option [ByteBuffer ] = partitionType match {
759757 case PartitionType .REDUCE =>
@@ -915,15 +913,11 @@ class LifecycleManager(val appUniqueId: String, val conf: CelebornConf) extends
915913 serdeVersion : SerdeVersion ): Unit = {
916914 val contextWrapper =
917915 ChangeLocationsCallContext (context, partitionIds.size(), serdeVersion)
918- if (clientMetricsEnabled) {
919- clientSource.incCounter(CelebornClientSource .REVIVE_REQUEST_COUNT , partitionIds.size())
920- }
916+ incClientMetric(CelebornClientSource .REVIVE_REQUEST_COUNT , partitionIds.size())
921917 // If shuffle not registered, reply ShuffleNotRegistered and return
922918 if (! registeredShuffle.contains(shuffleId)) {
923919 logError(s " [handleRevive] shuffle $shuffleId not registered! " )
924- if (clientMetricsEnabled) {
925- clientSource.incCounter(CelebornClientSource .REVIVE_FAIL_COUNT )
926- }
920+ incClientMetric(CelebornClientSource .REVIVE_FAIL_COUNT , partitionIds.size())
927921 contextWrapper.reply(
928922 - 1 ,
929923 StatusCode .SHUFFLE_UNREGISTERED ,
@@ -935,9 +929,7 @@ class LifecycleManager(val appUniqueId: String, val conf: CelebornConf) extends
935929 s " [handleRevive] shuffle $shuffleId, $mapIds, $partitionIds, $oldEpochs, $oldPartitions, $causes" )
936930 if (commitManager.isStageEnd(shuffleId)) {
937931 logError(s " [handleRevive] shuffle $shuffleId stage ended! " )
938- if (clientMetricsEnabled) {
939- clientSource.incCounter(CelebornClientSource .REVIVE_FAIL_COUNT )
940- }
932+ incClientMetric(CelebornClientSource .REVIVE_FAIL_COUNT , partitionIds.size())
941933 contextWrapper.reply(
942934 - 1 ,
943935 StatusCode .STAGE_ENDED ,
@@ -1151,9 +1143,7 @@ class LifecycleManager(val appUniqueId: String, val conf: CelebornConf) extends
11511143 if (invokeReportTaskShuffleFetchFailurePreCheck(taskId)) {
11521144 logInfo(s " handle fetch failure for appShuffleId $appShuffleId shuffleId $shuffleId" )
11531145 ret = invokeAppShuffleTrackerCallback(appShuffleId)
1154- if (ret && clientMetricsEnabled) {
1155- clientSource.incCounter(CelebornClientSource .SHUFFLE_FETCH_FAILURE_COUNT )
1156- }
1146+ if (ret) incClientMetric(CelebornClientSource .SHUFFLE_FETCH_FAILURE_COUNT )
11571147 shuffleIds.put(appShuffleIdentifier, (shuffleId, false ))
11581148 } else {
11591149 logInfo(
@@ -1285,9 +1275,7 @@ class LifecycleManager(val appUniqueId: String, val conf: CelebornConf) extends
12851275 context.reply(MapperEndResponse (StatusCode .SUCCESS , serdeVersion))
12861276 case false =>
12871277 logError(s " Failed $message, reply ${StatusCode .SHUFFLE_DATA_LOST }. " )
1288- if (clientMetricsEnabled) {
1289- clientSource.incCounter(CelebornClientSource .SHUFFLE_DATA_LOST_COUNT )
1290- }
1278+ incClientMetric(CelebornClientSource .SHUFFLE_DATA_LOST_COUNT )
12911279 context.reply(MapperEndResponse (StatusCode .SHUFFLE_DATA_LOST , serdeVersion))
12921280 }
12931281 }
@@ -1653,9 +1641,7 @@ class LifecycleManager(val appUniqueId: String, val conf: CelebornConf) extends
16531641 // [[releasePartitionLocation]]. Now in the slots are all the successful partition
16541642 // locations.
16551643 logWarning(s " Reserve buffers for $shuffleId still fail after retrying, clear buffers. " )
1656- if (clientMetricsEnabled) {
1657- clientSource.incCounter(CelebornClientSource .SLOT_RESERVATION_FAIL_COUNT )
1658- }
1644+ incClientMetric(CelebornClientSource .SLOT_RESERVATION_FAIL_COUNT )
16591645 destroySlotsWithRetry(shuffleId, slots)
16601646 } else {
16611647 logInfo(s " Reserve buffer success for shuffleId $shuffleId" )
@@ -1875,9 +1861,7 @@ class LifecycleManager(val appUniqueId: String, val conf: CelebornConf) extends
18751861 // if unregister shuffle not success, wait next turn
18761862 if (StatusCode .SUCCESS == StatusCode .fromValue(unregisterShuffleResponse.getStatus)) {
18771863 unregisterShuffleTime.remove(shuffleId)
1878- if (clientMetricsEnabled) {
1879- clientSource.incCounter(CelebornClientSource .UNREGISTER_SHUFFLE_COUNT )
1880- }
1864+ incClientMetric(CelebornClientSource .UNREGISTER_SHUFFLE_COUNT )
18811865 }
18821866 }
18831867 } else {
@@ -1889,9 +1873,7 @@ class LifecycleManager(val appUniqueId: String, val conf: CelebornConf) extends
18891873 if (StatusCode .SUCCESS == StatusCode .fromValue(unregisterShuffleResponse.getStatus)) {
18901874 shuffleIdsToRemove.foreach { shuffleId : Integer =>
18911875 unregisterShuffleTime.remove(shuffleId)
1892- if (clientMetricsEnabled) {
1893- clientSource.incCounter(CelebornClientSource .UNREGISTER_SHUFFLE_COUNT )
1894- }
1876+ incClientMetric(CelebornClientSource .UNREGISTER_SHUFFLE_COUNT )
18951877 }
18961878 }
18971879 }
@@ -2101,6 +2083,7 @@ class LifecycleManager(val appUniqueId: String, val conf: CelebornConf) extends
21012083 */
21022084 override def stop (): Unit = {
21032085 heartbeater.stop()
2086+ clientSource.foreach(_.stop())
21042087 super .stop()
21052088 }
21062089
0 commit comments