diff --git a/http-bench-jmh/src/main/scala/org/apache/pekko/http/impl/engine/http2/H2ClientServerBenchmark.scala b/http-bench-jmh/src/main/scala/org/apache/pekko/http/impl/engine/http2/H2ClientServerBenchmark.scala index d09f72eb3..d3525efaf 100644 --- a/http-bench-jmh/src/main/scala/org/apache/pekko/http/impl/engine/http2/H2ClientServerBenchmark.scala +++ b/http-bench-jmh/src/main/scala/org/apache/pekko/http/impl/engine/http2/H2ClientServerBenchmark.scala @@ -24,6 +24,7 @@ import pekko.http.scaladsl.settings.{ ClientConnectionSettings, ServerSettings } import pekko.stream.TLSProtocol.{ SslTlsInbound, SslTlsOutbound } import pekko.stream.scaladsl.{ BidiFlow, Flow, Keep, Sink, Source } import pekko.util.ByteString +import com.typesafe.config.ConfigFactory import org.openjdk.jmh.annotations._ import java.util.concurrent.{ CountDownLatch, TimeUnit } @@ -40,6 +41,9 @@ class H2ClientServerBenchmark extends CommonBenchmark with H2RequestResponseBenc val numRequests = 1000 + @Param(Array("1s", "0s")) + var resetFrameThrottleInterval: String = _ + @Benchmark @OperationsPerInvocation(1000) // should be same as numRequest def benchRequestProcessing(): Unit = { @@ -69,7 +73,9 @@ class H2ClientServerBenchmark extends CommonBenchmark with H2RequestResponseBenc def setup(): Unit = { initRequestResponse() - system = ActorSystem("PekkoHttpBenchmarkSystem", config) + val resetFrameConfig = ConfigFactory.parseString( + s"pekko.http.server.http2.reset-frame.throttle-interval=$resetFrameThrottleInterval") + system = ActorSystem("PekkoHttpBenchmarkSystem", resetFrameConfig.withFallback(config)) val settings = implicitly[ServerSettings] val log = system.log implicit val ec = system.dispatcher diff --git a/http-core/src/main/resources/reference.conf b/http-core/src/main/resources/reference.conf index c5220a2a3..2f13ff47a 100644 --- a/http-core/src/main/resources/reference.conf +++ b/http-core/src/main/resources/reference.conf @@ -308,11 +308,13 @@ pekko.http { # When zero the ping-interval is used, if set the value must be evenly divisible by less than or equal to the ping-interval. ping-timeout = 0s - # Configure the throttle for Reset Frames (https://github.com/apache/incubator-pekko-http/issues/332) - reset-frame-throttle-cost = 100 - reset-frame-throttle-burst = 100 - # setting reset-frame-throttle-interval to 0s will disable the throttle - reset-frame-throttle-interval = 1s + reset-frame { + # Configure the throttle for Reset Frames (https://github.com/apache/incubator-pekko-http/issues/332) + throttle-cost = 100 + throttle-burst = 100 + # setting pekko.http.server.http2.reset-frame.throttle-interval to 0s will disable the throttle + throttle-interval = 1s + } } websocket { diff --git a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/Http2Blueprint.scala b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/Http2Blueprint.scala index f5b5507b7..23feb695a 100644 --- a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/Http2Blueprint.scala +++ b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/Http2Blueprint.scala @@ -206,9 +206,8 @@ private[http] object Http2Blueprint { private def rapidResetMitigation( settings: Http2ServerSettings): BidiFlow[FrameEvent, FrameEvent, FrameEvent, FrameEvent, NotUsed] = { def frameCost(event: FrameEvent): Int = event match { - case _: FrameEvent.DataFrame => 0 - case _: FrameEvent.WindowUpdateFrame => 0 // TODO: should we throttle these? - case _ => 1 + case _: FrameEvent.RstStreamFrame => 1 + case _ => 0 } BidiFlow.fromFlows( diff --git a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/settings/Http2ServerSettings.scala b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/settings/Http2ServerSettings.scala index 96124e9dc..7074d8fd9 100644 --- a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/settings/Http2ServerSettings.scala +++ b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/settings/Http2ServerSettings.scala @@ -163,9 +163,9 @@ object Http2ServerSettings extends SettingsCompanion[Http2ServerSettings] { logFrames = c.getBoolean("log-frames"), pingInterval = c.getFiniteDuration("ping-interval"), pingTimeout = c.getFiniteDuration("ping-timeout"), - resetFrameThrottleCost = c.getInt("reset-frame-throttle-cost"), - resetFrameThrottleBurst = c.getInt("reset-frame-throttle-burst"), - resetFrameThrottleInterval = c.getFiniteDuration("reset-frame-throttle-interval"), + resetFrameThrottleCost = c.getInt("reset-frame.throttle-cost"), + resetFrameThrottleBurst = c.getInt("reset-frame.throttle-burst"), + resetFrameThrottleInterval = c.getFiniteDuration("reset-frame.throttle-interval"), None // no possibility to configure internal settings with config ) } diff --git a/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2ServerDisableResetSpec.scala b/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2ServerDisableResetSpec.scala index 6fc138062..be9efc555 100644 --- a/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2ServerDisableResetSpec.scala +++ b/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2ServerDisableResetSpec.scala @@ -14,9 +14,9 @@ package org.apache.pekko.http.impl.engine.http2 import org.apache.pekko -import org.apache.pekko.http.impl.engine.http2.Http2Protocol.FrameType -import org.apache.pekko.http.impl.engine.http2.framing.FrameRenderer -import org.apache.pekko.util.ByteStringBuilder +import pekko.http.impl.engine.http2.Http2Protocol.FrameType +import pekko.http.impl.engine.http2.framing.FrameRenderer +import pekko.util.ByteStringBuilder import java.nio.ByteOrder @@ -26,7 +26,7 @@ import java.nio.ByteOrder class Http2ServerDisableResetSpec extends Http2SpecWithMaterializer(""" pekko.http.server.remote-address-header = on pekko.http.server.http2.log-frames = on - pekko.http.server.http2.reset-frame-throttle-interval = 0s + pekko.http.server.http2.reset-frame.throttle-interval = 0s """) { override def failOnSevereMessages: Boolean = true diff --git a/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2ServerSpec.scala b/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2ServerSpec.scala index d56899fcb..cd3f459be 100644 --- a/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2ServerSpec.scala +++ b/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2ServerSpec.scala @@ -19,7 +19,6 @@ import pekko.http.impl.engine.http2.FrameEvent._ import pekko.http.impl.engine.http2.Http2Protocol.{ ErrorCode, Flags, FrameType, SettingIdentifier } import pekko.http.impl.engine.server.{ HttpAttributes, ServerTerminator } import pekko.http.impl.engine.ws.ByteStringSinkProbe -import pekko.http.impl.util.PekkoSpecWithMaterializer import pekko.http.scaladsl.client.RequestBuilding.Get import pekko.http.scaladsl.model._ import pekko.http.scaladsl.model.headers.{ CacheDirectives, RawHeader }