Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New Scheduler] Add memory queue for the new scheduler #5110

Merged
merged 22 commits into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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.openwhisk.common
style95 marked this conversation as resolved.
Show resolved Hide resolved

object AverageRingBuffer {
def apply(maxSize: Int) = new AverageRingBuffer(maxSize)
}

/**
* This buffer provides the average of the given elements.
* The number of elements are limited and the first element is removed if the maximum size is reached.
* Since it is based on the Vector, its operation takes effectively constant time.
* For more details, please visit https://docs.scala-lang.org/overviews/collections/performance-characteristics.html
*
* @param maxSize the maximum size of the buffer
*/
class AverageRingBuffer(private val maxSize: Int) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This circular buffer is used to calculate the average execution time of recent N activations for a given action.

Copy link
Contributor

@bdoyle0182 bdoyle0182 Jun 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reasoning for picking average as the heuristic. Would median be a better heuristic here? i.e. if all activations take 100 milliseconds and then one activation has a slow call to a db that takes 10 seconds it will heavily skew the average.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes sense.
The ring size in our case was relatively small such as 10, so we calculated the average of recent 10 activations. Even if there was a skew at some point, it quickly gets back to the "normal" average if the slow activation is a transient issue.
Also, it only affects the timing to add more containers, and activations are still being processed by existing containers. So there was no critical impact.

Basically, the median would be better, but the average is a much simpler and cheaper solution so I chose it.

private var elements = Vector.empty[Double]
private var sum = 0.0
private var max = 0.0
private var min = 0.0

def nonEmpty: Boolean = elements.nonEmpty

def average: Double = {
val size = elements.size
if (size > 2) {
(sum - max - min) / (size - 2)
} else {
sum / size
}
}

def add(el: Double): Unit = synchronized {
if (elements.size == maxSize) {
sum = sum + el - elements.head
elements = elements.tail :+ el
} else {
sum += el
elements = elements :+ el
}
if (el > max) {
max = el
}
if (el < min) {
min = el
}
}

def size(): Int = elements.size
}
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,26 @@ object LoggingMarkers {
*
* MetricEmitter.emitCounterMetric(LoggingMarkers.MY_COUNTER(GreenCounter))
*/
def SCHEDULER_NAMESPACE_CONTAINER(namespace: String) =
LogMarkerToken(scheduler, "namespaceContainer", counter, Some(namespace), Map("namespace" -> namespace))(
MeasurementUnit.none)
def SCHEDULER_NAMESPACE_INPROGRESS_CONTAINER(namespace: String) =
LogMarkerToken(scheduler, "namespaceInProgressContainer", counter, Some(namespace), Map("namespace" -> namespace))(
MeasurementUnit.none)
def SCHEDULER_ACTION_CONTAINER(namespace: String, action: String) =
LogMarkerToken(
scheduler,
"actionContainer",
counter,
Some(namespace),
Map("namespace" -> namespace, "action" -> action))(MeasurementUnit.none)
def SCHEDULER_ACTION_INPROGRESS_CONTAINER(namespace: String, action: String) =
LogMarkerToken(
scheduler,
"actionInProgressContainer",
counter,
Some(namespace),
Map("namespace" -> namespace, "action" -> action))(MeasurementUnit.none)

/*
* Controller related markers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ object ConfigKeys {
val azBlob = "whisk.azure-blob"

val schedulerMaxPeek = "whisk.scheduler.max-peek"
val schedulerQueue = "whisk.scheduler.queue"
val schedulerQueueManager = "whisk.scheduler.queue-manager"
val schedulerInProgressJobRetentionSecond = "whisk.scheduler.in-progress-job-retention"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,7 @@ protected[core] object CreationId {
}
}
}

val systemPrefix = "cid_"
val void = CreationId(systemPrefix + "void")
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ object Messages {
s"Too many requests in the last minute (count: $count, allowed: $allowed)."

/** Standard message for too many concurrent activation requests within a time window. */
val tooManyConcurrentRequests = s"Too many concurrent requests in flight."
def tooManyConcurrentRequests(count: Int, allowed: Int) =
s"Too many concurrent requests in flight (count: $count, allowed: $allowed)."

Expand Down Expand Up @@ -225,6 +226,7 @@ object Messages {
}

val namespacesBlacklisted = "The action was not invoked due to a blacklisted namespace."
val namespaceLimitUnderZero = "The namespace limit is less than or equal to 0."

val actionRemovedWhileInvoking = "Action could not be found or may have been deleted."
val actionMismatchWhileInvoking = "Action version is not compatible and cannot be invoked."
Expand Down
1 change: 1 addition & 0 deletions core/scheduler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ dependencies {
}

compile "org.scala-lang:scala-library:${gradle.scala.version}"
compile "io.altoo:akka-kryo-serialization_${gradle.scala.depVersion}:1.0.0"
compile project(':common:scala')
}

Expand Down
49 changes: 47 additions & 2 deletions core/scheduler/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,63 @@
# limitations under the License.
#


akka {
actor {
allow-java-serialization = off
serializers {
kryo = "io.altoo.akka.serialization.kryo.KryoSerializer"
}
serialization-bindings {
"org.apache.openwhisk.core.scheduler.queue.CreateQueue" = kryo
"org.apache.openwhisk.core.scheduler.queue.CreateQueueResponse" = kryo
"org.apache.openwhisk.core.connector.ActivationMessage" = kryo
}
kryo {
idstrategy = "automatic"
classes = [
"org.apache.openwhisk.core.scheduler.queue.CreateQueue",
"org.apache.openwhisk.core.scheduler.queue.CreateQueueResponse",
"org.apache.openwhisk.core.connector.ActivationMessage"
]
}
}

remote.netty.tcp {
send-buffer-size = 3151796b
receive-buffer-size = 3151796b
maximum-frame-size = 3151796b
}
}

whisk {
# tracing configuration
tracing {
component = "Scheduler"
}

fraction {
managed-fraction: 90%
blackbox-fraction: 10%
managed-fraction: 90%
blackbox-fraction: 10%
}

scheduler {
protocol = "http"
username: "scheduler.user"
password: "scheduler.pass"
grpc {
tls = "false"
}
queue {
idle-grace = "20 seconds"
stop-grace = "20 seconds"
flush-grace = "60 seconds"
graceful-shutdown-timeout = "5 seconds"
max-retention-size = "10000"
max-retention-ms = "60000"
throttling-fraction = "0.9"
duration-buffer-size = "10"
}
queue-manager {
max-scheduling-time = "20 seconds"
max-retries-to-get-queue = "13"
Expand Down
Loading