You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2021/12/01 17:25:00 UTC

[GitHub] [kafka] mimaison opened a new pull request #11560: KAFKA-7589: Allow configuring network threads per listener

mimaison opened a new pull request #11560:
URL: https://github.com/apache/kafka/pull/11560


   Implements KIP-788. The number of network threads can be set per listener using the following syntax:
   listener.name.<listener>.num.network.threads=<num>
   
   It's currently a draft PR, there are still a bunch of TODOs and disabled tests. Before fixing them, I'd like to discuss a couple of things:
   - I renamed processor threads. They used to be numbered globally and now are numbered by listener.
   - I updated processor metrics to include the listener name otherwise metrics would collide.
   
   These are not described in the KIP but while implementing it, it made sense to handle all the processor creation/deletion in Acceptor. As there's an acceptor by listener, I made DataPlaneAcceptor a ListenerReconfigurable.
   
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   


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

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kafka] mimaison commented on pull request #11560: KAFKA-7589: Allow configuring network threads per listener

Posted by GitBox <gi...@apache.org>.
mimaison commented on pull request #11560:
URL: https://github.com/apache/kafka/pull/11560#issuecomment-1005536732


   @dajac @rajinisivaram Do you also want to take a look? If not, I'll merge later this week. Thanks


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

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kafka] mimaison commented on pull request #11560: KAFKA-7589: Allow configuring network threads per listener

Posted by GitBox <gi...@apache.org>.
mimaison commented on pull request #11560:
URL: https://github.com/apache/kafka/pull/11560#issuecomment-992306969


   @rajinisivaram @tombentley @dajac This PR is now ready for reviews. Thanks


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

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kafka] dajac commented on a change in pull request #11560: KAFKA-7589: Allow configuring network threads per listener

Posted by GitBox <gi...@apache.org>.
dajac commented on a change in pull request #11560:
URL: https://github.com/apache/kafka/pull/11560#discussion_r761930382



##########
File path: core/src/main/scala/kafka/network/SocketServer.scala
##########
@@ -841,16 +974,17 @@ private[kafka] class Processor(val id: Int,
     Option(metrics.metric(metrics.metricName("io-wait-ratio", MetricsGroup, metricTags))).fold(0.0)(m =>
       Math.min(m.metricValue.asInstanceOf[Double], 1.0))
   },
+    //TODO is this an issue if we change the metrics tags?

Review comment:
       I think so because it is not backward compatible. It seems that we already kept that metrics for backward compatibility reason. I am not sure if it was deprecated at some point or not. If it would, we could perhaps drop it in a future release. Is this the only problematic metric? 




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

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kafka] mimaison commented on pull request #11560: KAFKA-7589: Allow configuring network threads per listener

Posted by GitBox <gi...@apache.org>.
mimaison commented on pull request #11560:
URL: https://github.com/apache/kafka/pull/11560#issuecomment-983865906


   cc @rajinisivaram @tombentley @dajac 


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

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kafka] mimaison merged pull request #11560: KAFKA-7589: Allow configuring network threads per listener

Posted by GitBox <gi...@apache.org>.
mimaison merged pull request #11560:
URL: https://github.com/apache/kafka/pull/11560


   


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

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kafka] mimaison commented on a change in pull request #11560: KAFKA-7589: Allow configuring network threads per listener

Posted by GitBox <gi...@apache.org>.
mimaison commented on a change in pull request #11560:
URL: https://github.com/apache/kafka/pull/11560#discussion_r766857004



##########
File path: core/src/main/scala/kafka/network/SocketServer.scala
##########
@@ -841,16 +974,17 @@ private[kafka] class Processor(val id: Int,
     Option(metrics.metric(metrics.metricName("io-wait-ratio", MetricsGroup, metricTags))).fold(0.0)(m =>
       Math.min(m.metricValue.asInstanceOf[Double], 1.0))
   },
+    //TODO is this an issue if we change the metrics tags?

Review comment:
       I've pushed an update to keep all existing metric names.




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

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kafka] mimaison commented on a change in pull request #11560: KAFKA-7589: Allow configuring network threads per listener

Posted by GitBox <gi...@apache.org>.
mimaison commented on a change in pull request #11560:
URL: https://github.com/apache/kafka/pull/11560#discussion_r770452647



##########
File path: core/src/test/scala/integration/kafka/network/DynamicNumNetworkThreadsTest.scala
##########
@@ -0,0 +1,102 @@
+/**
+ * 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 integration.kafka.network
+
+import kafka.server.{BaseRequestTest, Defaults, KafkaConfig}
+import kafka.utils.TestUtils
+import org.apache.kafka.clients.admin.{Admin, AdminClientConfig}
+import org.apache.kafka.common.network.ListenerName
+import org.junit.jupiter.api.Assertions._
+import org.junit.jupiter.api.{BeforeEach, Test, TestInfo}
+
+import java.util.Properties
+import scala.jdk.CollectionConverters._
+
+class DynamicNumNetworkThreadsTest extends BaseRequestTest {
+
+  override def brokerCount = 1
+
+  val internal = "PLAINTEXT"
+  val external = "EXTERNAL"
+
+  override def brokerPropertyOverrides(properties: Properties): Unit = {
+    properties.put(KafkaConfig.ListenersProp, s"$internal://localhost:0, $external://localhost:0")
+    properties.put(KafkaConfig.ListenerSecurityProtocolMapProp, s"$internal:PLAINTEXT, $external:PLAINTEXT")
+    properties.put(s"listener.name.${internal.toLowerCase}.${KafkaConfig.NumNetworkThreadsProp}", "2")
+  }
+
+  @BeforeEach
+  override def setUp(testInfo: TestInfo): Unit = {
+    super.setUp(testInfo)
+    TestUtils.createTopic(zkClient, "test", brokerCount, brokerCount, servers)
+    assertEquals(2, getNumNetworkThreads(internal))
+    assertEquals(Defaults.NumNetworkThreads, getNumNetworkThreads(external))
+  }
+
+  def getNumNetworkThreads(listener: String): Int = {
+    brokers.head.metrics.metrics().keySet().asScala
+      .filter(_.name() == "request-rate")
+      .count(listener == _.tags().get("listener"))
+  }
+
+  @Test
+  def testDynamicNumNetworkThreads(): Unit = {

Review comment:
       The control place always has a single processor thread.




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

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kafka] mimaison commented on a change in pull request #11560: KAFKA-7589: Allow configuring network threads per listener

Posted by GitBox <gi...@apache.org>.
mimaison commented on a change in pull request #11560:
URL: https://github.com/apache/kafka/pull/11560#discussion_r770451653



##########
File path: core/src/main/scala/kafka/network/SocketServer.scala
##########
@@ -95,20 +95,22 @@ class SocketServer(val config: KafkaConfig,
   memoryPoolSensor.add(new Meter(TimeUnit.MILLISECONDS, memoryPoolDepletedPercentMetricName, memoryPoolDepletedTimeMetricName))
   private val memoryPool = if (config.queuedMaxBytes > 0) new SimpleMemoryPool(config.queuedMaxBytes, config.socketRequestMaxBytes, false, memoryPoolSensor) else MemoryPool.NONE
   // data-plane
-  private val dataPlaneProcessors = new ConcurrentHashMap[Int, Processor]()
-  private[network] val dataPlaneAcceptors = new ConcurrentHashMap[EndPoint, Acceptor]()
-  val dataPlaneRequestChannel = new RequestChannel(maxQueuedRequests, DataPlaneMetricPrefix, time, apiVersionManager.newRequestMetrics)
+  private[network] val dataPlaneAcceptors = new ConcurrentHashMap[EndPoint, DataPlaneAcceptor]()
+  val dataPlaneRequestChannel = new RequestChannel(maxQueuedRequests, DataPlaneAcceptor.MetricPrefix, time, apiVersionManager.newRequestMetrics)
   // control-plane
-  private var controlPlaneProcessorOpt : Option[Processor] = None
-  private[network] var controlPlaneAcceptorOpt : Option[Acceptor] = None
+  private[network] var controlPlaneAcceptorOpt: Option[ControlPlaneAcceptor] = None
   val controlPlaneRequestChannelOpt: Option[RequestChannel] = config.controlPlaneListenerName.map(_ =>
-    new RequestChannel(20, ControlPlaneMetricPrefix, time, apiVersionManager.newRequestMetrics))
+    new RequestChannel(20, ControlPlaneAcceptor.MetricPrefix, time, apiVersionManager.newRequestMetrics))
 
-  private var nextProcessorId = 0
+  private val nextPId: AtomicInteger = new AtomicInteger(0)
   val connectionQuotas = new ConnectionQuotas(config, time, metrics)
   private var startedProcessingRequests = false
   private var stoppedProcessingRequests = false
 
+  def nextProcessorId(): Int = {
+    nextPId.getAndIncrement()

Review comment:
       I've renamed the field to `nextProcessorId`, this is not an issue as it's private




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

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kafka] mimaison commented on a change in pull request #11560: KAFKA-7589: Allow configuring network threads per listener

Posted by GitBox <gi...@apache.org>.
mimaison commented on a change in pull request #11560:
URL: https://github.com/apache/kafka/pull/11560#discussion_r770444358



##########
File path: core/src/main/scala/kafka/server/DynamicBrokerConfig.scala
##########
@@ -920,7 +919,7 @@ class DynamicListenerConfig(server: KafkaBroker) extends BrokerReconfigurable wi
       def immutableListenerConfigs(kafkaConfig: KafkaConfig, prefix: String): Map[String, AnyRef] = {
         kafkaConfig.originalsWithPrefix(prefix, true).asScala.filter { case (key, _) =>
           // skip the reconfigurable configs
-          !DynamicSecurityConfigs.contains(key) && !SocketServer.ListenerReconfigurableConfigs.contains(key)
+          !DynamicSecurityConfigs.contains(key) && !SocketServer.ListenerReconfigurableConfigs.contains(key) && !DataPlaneAcceptor.ListenerReconfigurableConfigs.contains(key)

Review comment:
       Configuring the number of processor threads is unique to the data plane. The control place always has a single processor to guarantee controller requests are handled in order.




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

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kafka] mimaison commented on pull request #11560: KAFKA-7589: Allow configuring network threads per listener

Posted by GitBox <gi...@apache.org>.
mimaison commented on pull request #11560:
URL: https://github.com/apache/kafka/pull/11560#issuecomment-995703478


   Thanks for the review @tombentley! I've pushed an update addressing your findings.


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

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kafka] tombentley commented on a change in pull request #11560: KAFKA-7589: Allow configuring network threads per listener

Posted by GitBox <gi...@apache.org>.
tombentley commented on a change in pull request #11560:
URL: https://github.com/apache/kafka/pull/11560#discussion_r769814004



##########
File path: core/src/main/scala/kafka/network/SocketServer.scala
##########
@@ -203,23 +207,22 @@ class SocketServer(val config: KafkaConfig,
    * Before starting them, we ensure that authorizer has all the metadata to authorize
    * requests on that endpoint by waiting on the provided future.
    */
-  private def startAcceptorAndProcessors(threadPrefix: String,
-                                         endpoint: EndPoint,
+  private def startAcceptorAndProcessors(endpoint: EndPoint,

Review comment:
       If `acceptor` has `endpoint` as a member, why do we need to pass it explicitly here? 

##########
File path: core/src/main/scala/kafka/network/SocketServer.scala
##########
@@ -95,20 +95,22 @@ class SocketServer(val config: KafkaConfig,
   memoryPoolSensor.add(new Meter(TimeUnit.MILLISECONDS, memoryPoolDepletedPercentMetricName, memoryPoolDepletedTimeMetricName))
   private val memoryPool = if (config.queuedMaxBytes > 0) new SimpleMemoryPool(config.queuedMaxBytes, config.socketRequestMaxBytes, false, memoryPoolSensor) else MemoryPool.NONE
   // data-plane
-  private val dataPlaneProcessors = new ConcurrentHashMap[Int, Processor]()
-  private[network] val dataPlaneAcceptors = new ConcurrentHashMap[EndPoint, Acceptor]()
-  val dataPlaneRequestChannel = new RequestChannel(maxQueuedRequests, DataPlaneMetricPrefix, time, apiVersionManager.newRequestMetrics)
+  private[network] val dataPlaneAcceptors = new ConcurrentHashMap[EndPoint, DataPlaneAcceptor]()
+  val dataPlaneRequestChannel = new RequestChannel(maxQueuedRequests, DataPlaneAcceptor.MetricPrefix, time, apiVersionManager.newRequestMetrics)
   // control-plane
-  private var controlPlaneProcessorOpt : Option[Processor] = None
-  private[network] var controlPlaneAcceptorOpt : Option[Acceptor] = None
+  private[network] var controlPlaneAcceptorOpt: Option[ControlPlaneAcceptor] = None
   val controlPlaneRequestChannelOpt: Option[RequestChannel] = config.controlPlaneListenerName.map(_ =>
-    new RequestChannel(20, ControlPlaneMetricPrefix, time, apiVersionManager.newRequestMetrics))
+    new RequestChannel(20, ControlPlaneAcceptor.MetricPrefix, time, apiVersionManager.newRequestMetrics))
 
-  private var nextProcessorId = 0
+  private val nextPId: AtomicInteger = new AtomicInteger(0)
   val connectionQuotas = new ConnectionQuotas(config, time, metrics)
   private var startedProcessingRequests = false
   private var stoppedProcessingRequests = false
 
+  def nextProcessorId(): Int = {
+    nextPId.getAndIncrement()

Review comment:
       `nextPId` is a bit hard on the eyes. `_nextProcessorId` perhaps? Also perhaps a comment that this it only needed for the legacy metric names. 

##########
File path: core/src/main/scala/kafka/server/DynamicBrokerConfig.scala
##########
@@ -920,7 +919,7 @@ class DynamicListenerConfig(server: KafkaBroker) extends BrokerReconfigurable wi
       def immutableListenerConfigs(kafkaConfig: KafkaConfig, prefix: String): Map[String, AnyRef] = {
         kafkaConfig.originalsWithPrefix(prefix, true).asScala.filter { case (key, _) =>
           // skip the reconfigurable configs
-          !DynamicSecurityConfigs.contains(key) && !SocketServer.ListenerReconfigurableConfigs.contains(key)
+          !DynamicSecurityConfigs.contains(key) && !SocketServer.ListenerReconfigurableConfigs.contains(key) && !DataPlaneAcceptor.ListenerReconfigurableConfigs.contains(key)

Review comment:
       IIUC the reconfigurability of thread numbers is not specific to the data plane, so why is the constant declared on `DataPlaneAcceptor` rather than `Acceptor`?

##########
File path: core/src/test/scala/unit/kafka/network/SocketServerTest.scala
##########
@@ -82,6 +82,11 @@ class SocketServerTest {
 
   private val kafkaLogger = org.apache.log4j.LogManager.getLogger("kafka")
   private var logLevelToRestore: Level = _
+  def endpoint: EndPoint = {
+    KafkaConfig.fromProps(props, doLog = false).dataPlaneListeners.head
+  }
+  def listener: String = endpoint.listenerName.value
+  @volatile var uncaughtExceptions = 0

Review comment:
       `uncaughtExceptions` gets incremented with += 1, which would require atomic CAS rather than `volatile`. 

##########
File path: core/src/test/scala/integration/kafka/network/DynamicNumNetworkThreadsTest.scala
##########
@@ -0,0 +1,102 @@
+/**
+ * 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 integration.kafka.network
+
+import kafka.server.{BaseRequestTest, Defaults, KafkaConfig}
+import kafka.utils.TestUtils
+import org.apache.kafka.clients.admin.{Admin, AdminClientConfig}
+import org.apache.kafka.common.network.ListenerName
+import org.junit.jupiter.api.Assertions._
+import org.junit.jupiter.api.{BeforeEach, Test, TestInfo}
+
+import java.util.Properties
+import scala.jdk.CollectionConverters._
+
+class DynamicNumNetworkThreadsTest extends BaseRequestTest {
+
+  override def brokerCount = 1
+
+  val internal = "PLAINTEXT"
+  val external = "EXTERNAL"
+
+  override def brokerPropertyOverrides(properties: Properties): Unit = {
+    properties.put(KafkaConfig.ListenersProp, s"$internal://localhost:0, $external://localhost:0")
+    properties.put(KafkaConfig.ListenerSecurityProtocolMapProp, s"$internal:PLAINTEXT, $external:PLAINTEXT")
+    properties.put(s"listener.name.${internal.toLowerCase}.${KafkaConfig.NumNetworkThreadsProp}", "2")
+  }
+
+  @BeforeEach
+  override def setUp(testInfo: TestInfo): Unit = {
+    super.setUp(testInfo)
+    TestUtils.createTopic(zkClient, "test", brokerCount, brokerCount, servers)
+    assertEquals(2, getNumNetworkThreads(internal))
+    assertEquals(Defaults.NumNetworkThreads, getNumNetworkThreads(external))
+  }
+
+  def getNumNetworkThreads(listener: String): Int = {
+    brokers.head.metrics.metrics().keySet().asScala
+      .filter(_.name() == "request-rate")
+      .count(listener == _.tags().get("listener"))
+  }
+
+  @Test
+  def testDynamicNumNetworkThreads(): Unit = {

Review comment:
       Is it worth having a test to cover changing the control plane listener's threads too?




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

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kafka] tombentley commented on a change in pull request #11560: KAFKA-7589: Allow configuring network threads per listener

Posted by GitBox <gi...@apache.org>.
tombentley commented on a change in pull request #11560:
URL: https://github.com/apache/kafka/pull/11560#discussion_r771207226



##########
File path: core/src/main/scala/kafka/server/DynamicBrokerConfig.scala
##########
@@ -920,7 +919,7 @@ class DynamicListenerConfig(server: KafkaBroker) extends BrokerReconfigurable wi
       def immutableListenerConfigs(kafkaConfig: KafkaConfig, prefix: String): Map[String, AnyRef] = {
         kafkaConfig.originalsWithPrefix(prefix, true).asScala.filter { case (key, _) =>
           // skip the reconfigurable configs
-          !DynamicSecurityConfigs.contains(key) && !SocketServer.ListenerReconfigurableConfigs.contains(key)
+          !DynamicSecurityConfigs.contains(key) && !SocketServer.ListenerReconfigurableConfigs.contains(key) && !DataPlaneAcceptor.ListenerReconfigurableConfigs.contains(key)

Review comment:
       Oh, of course it's single threaded! Thanks.




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

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org