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 2019/05/29 11:37:09 UTC

[GitHub] [incubator-openwhisk] markusthoemmes commented on a change in pull request #4496: Simplify throttle code for API GW Tests

markusthoemmes commented on a change in pull request #4496: Simplify throttle code for API GW Tests
URL: https://github.com/apache/incubator-openwhisk/pull/4496#discussion_r288521012
 
 

 ##########
 File path: tests/src/test/scala/org/apache/openwhisk/core/cli/test/BaseApiGwTests.scala
 ##########
 @@ -56,29 +55,10 @@ abstract class BaseApiGwTests extends TestHelpers with WskTestHelpers with Befor
   // Custom CLI properties file
   val cliWskPropsFile = File.createTempFile("wskprops", ".tmp")
 
-  /**
-   * Expected to be called before each action invocation to
-   * settle the throttle when there isn't enough capacity to handle the test.
-   */
-  def checkThrottle(maxInvocationsBeforeThrottle: Int = maxActionsPerMin, throttlePercent: Int = 50) = {
-    val t = Instant.now
-    val tminus60 = t.minusSeconds(60)
-    val invocationsLast60Seconds = invocationTimes.filter(_.isAfter(tminus60)).sorted
-    val invocationCount = invocationsLast60Seconds.length
-    println(s"Action invokes within last minute: ${invocationCount}")
-
-    if (invocationCount >= maxInvocationsBeforeThrottle && throttlePercent >= 1) {
-      val numInvocationsToClear = max(invocationCount / (100 / throttlePercent), 1)
-      val invocationToClear = invocationsLast60Seconds(numInvocationsToClear - 1)
-      println(
-        s"throttling ${throttlePercent}% of action invocations within last minute = ($numInvocationsToClear) invocations")
-      val throttleTime = 60.seconds.toMillis - (t.toEpochMilli - invocationToClear.toEpochMilli)
-
-      println(s"Waiting ${throttleTime} milliseconds to settle the throttle")
-      Thread.sleep(throttleTime)
-    }
-
-    invocationTimes += Instant.now
+  def throttle(maxInvocationsBeforeThrottle: Int = maxActionsPerMin) = {
+    val throttleTime = (60.seconds.toMillis / maxInvocationsBeforeThrottle * 1.1).toInt
 
 Review comment:
   Doesn't this lack a relation to `invocationsLast60Seconds` from above?

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


With regards,
Apache Git Services