You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2020/09/08 11:45:24 UTC

[GitHub] [openwhisk] style95 commented on a change in pull request #4917: Adjust user memory via api

style95 commented on a change in pull request #4917:
URL: https://github.com/apache/openwhisk/pull/4917#discussion_r484843664



##########
File path: common/scala/src/main/scala/org/apache/openwhisk/core/connector/Message.scala
##########
@@ -426,3 +426,22 @@ object EventMessage extends DefaultJsonProtocol {
 
   def parse(msg: String) = Try(format.read(msg.parseJson))
 }
+
+case class ByteSizeMessage(userMemory: ByteSize) extends Message {

Review comment:
       I think the name should denote its purpose more.
   

##########
File path: core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/ContainerPool.scala
##########
@@ -305,6 +308,13 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
     case RescheduleJob =>
       freePool = freePool - sender()
       busyPool = busyPool - sender()
+    case message: ByteSizeMessage =>

Review comment:
       I hope this also has a more detailed protocol.
   This might be extended for general configurations.
   

##########
File path: docs/operation.md
##########
@@ -0,0 +1,33 @@
+<!--
+#
+# 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.
+#
+-->
+
+# User memory configuration of containerPool
+## Change user memory to all invokers via controller. e.g.
+```
+curl -u ${username}:${password} -X POST http://${controllerAddress}:${controllerPort}/config/memory -d '1024 MB'
+```
+Note: you can add `?limit` to specify target invokers, e.g. specify invoker0 and invoker1
+```
+curl -u ${username}:${password} -X POST http://${controllerAddress}:${controllerPort}/config/memory?limit=0:1 -d '1024 MB'

Review comment:
       I feel this API should be based on JSON and have a better protocol.
   For example, the name of the invoker may not be simple like just `invoker0`.
   

##########
File path: core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/ContainerPool.scala
##########
@@ -305,6 +308,13 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
     case RescheduleJob =>
       freePool = freePool - sender()
       busyPool = busyPool - sender()
+    case message: ByteSizeMessage =>
+      logging.info(
+        this,
+        s"user memory is reconfigured from ${latestUserMemory.toString} to ${message.userMemory.toString}")
+      latestUserMemory = message.userMemory

Review comment:
       Even if controllers check the validity of this value, it would be great to cross-check the value again in the invoker layer.
   
   And regarding the check, I feel the application should not concern the condition of the underlying host.
   But on the other hand, I am not sure it would be reasonable to allow a bigger memory than the invoker host has.
   
   I would defer this to other reviewers.
   

##########
File path: core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/ContainerPool.scala
##########
@@ -74,6 +76,7 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
   var busyPool = immutable.Map.empty[ActorRef, ContainerData]
   var prewarmedPool = immutable.Map.empty[ActorRef, PreWarmedData]
   var prewarmStartingPool = immutable.Map.empty[ActorRef, (String, ByteSize)]
+  var latestUserMemory = poolConfig.userMemory

Review comment:
       I hope we can avoid using `var` if possible.

##########
File path: core/controller/src/main/scala/org/apache/openwhisk/core/controller/Controller.scala
##########
@@ -176,6 +184,63 @@ class Controller(val instance: ControllerInstanceId,
     LogLimit.config,
     runtimes,
     List(apiV1.basepath()))
+
+  private val controllerCredentials = loadConfigOrThrow[ControllerCredentials](ConfigKeys.controllerCredentials)
+
+  /**
+   * config user memory of ContainerPool
+   */
+  private val configMemory = {
+    implicit val executionContext = actorSystem.dispatcher
+    (path("config" / "memory") & post) {
+      extractCredentials {
+        case Some(BasicHttpCredentials(username, password)) =>
+          if (username == controllerCredentials.username && password == controllerCredentials.password) {
+            entity(as[String]) { memory =>
+              try {
+                val userMemoryMessage = ByteSizeMessage(ByteSize.fromString(memory))
+                if (userMemoryMessage.userMemory.size == 0) {

Review comment:
       I think this is not the only precondition to configure memory.
   This value can be smaller than `MemoryLimit.min` then invokers would not be able to run any container.
   

##########
File path: core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/ContainerPool.scala
##########
@@ -305,6 +308,13 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
     case RescheduleJob =>
       freePool = freePool - sender()
       busyPool = busyPool - sender()
+    case message: ByteSizeMessage =>
+      logging.info(
+        this,
+        s"user memory is reconfigured from ${latestUserMemory.toString} to ${message.userMemory.toString}")
+      latestUserMemory = message.userMemory
+    case UserMemoryQuery =>
+      sender() ! latestUserMemory.toString

Review comment:
       How about sending the intact obejct directly and handle the type conversion in the InvokerServer layer?
   I think this kind of type conversion is only related to the InvokerServer and the client.
   




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