-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[New Scheduler] Add memory queue for the new scheduler #5110
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
Changes from all commits
c1f9832
30aa3d5
82a0f20
a124f1c
a1761e1
1cf38d9
7b71b4e
a6d31ac
40117f9
0ce9dbb
2410d42
acc75a9
fcb1248
65cd5dc
153a16d
d2668a2
8129a5d
ff8449b
3394cc7
471df88
99c95cd
6661b33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that makes sense. 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 | ||
} |
Uh oh!
There was an error while loading. Please reload this page.