markusthoemmes commented on a change in pull request #3886: Proposing Lean OpenWhisk URL: https://github.com/apache/incubator-openwhisk/pull/3886#discussion_r206266760
########## File path: core/lean/src/main/scala/whisk/core/loadBalancer/LeanBalancer.scala ########## @@ -0,0 +1,256 @@ +/* + * 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 whisk.core.loadBalancer + +import java.nio.charset.StandardCharsets +import java.util.concurrent.atomic.LongAdder + +import akka.actor.{ActorSystem, Props} +import akka.event.Logging.InfoLevel +import akka.stream.ActorMaterializer +import org.apache.kafka.clients.producer.RecordMetadata +import pureconfig._ +import whisk.spi.SpiLoader +import whisk.core.entity._ +import whisk.core.entity.size._ +import whisk.common.LoggingMarkers._ +import whisk.common._ +import whisk.core.WhiskConfig._ +import whisk.core.connector._ +import whisk.core.WhiskConfig +import whisk.core.ConfigKeys +import scala.collection.concurrent.TrieMap +import scala.concurrent.duration._ +import scala.concurrent.{ExecutionContext, Future, Promise} +import scala.util.{Failure, Success} +import whisk.core.invoker.InvokerReactive +import whisk.utils.ExecutionContextFactory + +/** + * A loadbalancer that uses "horizontal" sharding to not collide with fellow loadbalancers. + * + * Horizontal sharding means, that each invoker's capacity is evenly divided between the loadbalancers. If an invoker + * has at most 16 slots available, those will be divided to 8 slots for each loadbalancer (if there are 2). + */ +class LeanBalancer(config: WhiskConfig, controllerInstance: ControllerInstanceId)(implicit val actorSystem: ActorSystem, + logging: Logging, + materializer: ActorMaterializer) + extends LoadBalancer { + + private implicit val executionContext: ExecutionContext = actorSystem.dispatcher + + private val lbConfig = loadConfigOrThrow[ShardingContainerPoolBalancerConfig](ConfigKeys.loadbalancer) + + /** State related to invocations and throttling */ + private val activations = TrieMap[ActivationId, ActivationEntry]() + private val activationsPerNamespace = TrieMap[UUID, LongAdder]() + private val totalActivations = new LongAdder() + private val totalActivationMemory = new LongAdder() + + /** State needed for scheduling. */ + private val schedulingState = ShardingContainerPoolBalancerState()() Review comment: Uneeded. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
