From reviews-return-1120553-archive-asf-public=cust-asf.ponee.io@spark.apache.org Fri Jun 26 14:34:13 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id A32C2180656 for ; Fri, 26 Jun 2020 16:34:13 +0200 (CEST) Received: (qmail 87474 invoked by uid 500); 26 Jun 2020 14:34:13 -0000 Mailing-List: contact reviews-help@spark.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list reviews@spark.apache.org Received: (qmail 87458 invoked by uid 99); 26 Jun 2020 14:34:13 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Jun 2020 14:34:13 +0000 From: =?utf-8?q?GitBox?= To: reviews@spark.apache.org Subject: =?utf-8?q?=5BGitHub=5D_=5Bspark=5D_baohe-zhang_commented_on_a_change_in_pull?= =?utf-8?q?_request_=2328412=3A_=5BSPARK-31608=5D=5BCORE=5D=5BWEBUI=5D_Add_a?= =?utf-8?q?_new_type_of_KVStore_to_make_loading_UI_faster?= Message-ID: <159318205298.8807.16525770714074151800.asfpy@gitbox.apache.org> Date: Fri, 26 Jun 2020 14:34:12 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit In-Reply-To: References: baohe-zhang commented on a change in pull request #28412: URL: https://github.com/apache/spark/pull/28412#discussion_r446221919 ########## File path: core/src/main/scala/org/apache/spark/deploy/history/HistoryServerMemoryManager.scala ########## @@ -0,0 +1,82 @@ +/* + * 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 org.apache.spark.deploy.history + +import java.util.concurrent.atomic.AtomicLong + +import scala.collection.mutable.HashMap + +import org.apache.spark.SparkConf +import org.apache.spark.internal.Logging +import org.apache.spark.internal.config.History._ +import org.apache.spark.util.Utils + +/** + * A class used to keep track of in-memory store usage by the SHS. + */ +private class HistoryServerMemoryManager( + conf: SparkConf) extends Logging { + + private val maxUsage = conf.get(MAX_IN_MEMORY_STORE_USAGE) + private val currentUsage = new AtomicLong(0L) + private val active = new HashMap[(String, Option[String]), Long]() + + def initialize(): Unit = { + logInfo("Initialized memory manager: " + + s"current usage = ${Utils.bytesToString(currentUsage.get())}, " + + s"max usage = ${Utils.bytesToString(maxUsage)}") + } + + def lease( + appId: String, + attemptId: Option[String], + eventLogSize: Long, + isCompressed: Boolean): Unit = { + val memoryUsage = approximateMemoryUsage(eventLogSize, isCompressed) + if (memoryUsage + currentUsage.get > maxUsage) { + throw new RuntimeException("Not enough memory to create hybrid store " + + s"for app $appId / $attemptId.") + } + active.synchronized { + active(appId -> attemptId) = memoryUsage + } + currentUsage.addAndGet(memoryUsage) + logInfo(s"Leasing ${Utils.bytesToString(memoryUsage)} memory usage for " + + s"app $appId / $attemptId") + } + + def release(appId: String, attemptId: Option[String]): Unit = { + val memoryUsage = active.synchronized { active.remove(appId -> attemptId) } + + memoryUsage match { + case Some(m) => + currentUsage.addAndGet(-m) + logInfo(s"Released ${Utils.bytesToString(m)} memory usage for " + + s"app $appId / $attemptId") + case None => + } + } + + private def approximateMemoryUsage(eventLogSize: Long, isCompressed: Boolean): Long = { + if (isCompressed) { + eventLogSize * 2 Review comment: Sure I will do the experiment with different compressions and put the number here. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: users@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org For additional commands, e-mail: reviews-help@spark.apache.org