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:46:58 UTC

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

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

 ##########
 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:
   @markusthoemmes The original test code worked as expected in isolation. Buit is way to complicated with seeing the limitation that it only controls the test execution of the API GW tests in  and does not prevent all the error situation we have encountered due to prior invocation in the same namespace.
   
    In decided to dumb it down to throttle each invocation with a shorter fixed period to increase maintainability. 

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