使用spark.streaming.receiver.maxRate这个属性限制每秒的最大吞吐。官方文档如下:
Maximum rate (number of records per second) at which each receiver will receive data. Effectively, each stream will consume at most this number of records per second. Setting this configuration to 0 or a negative number will put no limit on the rate. See the deployment guide in the Spark Streaming programing guide for mode details.
默认没有设置,也就是做没做限制。
如果做限制100,那么每秒最大吞吐就是100条。
然后文档中还有一个属性spark.streaming.kafka.maxRatePerPartition,也是限制吞吐的,不过是限制kafka读取的速度,官方文档是这么说的:
Maximum rate (number of records per second) at which data will be read from each Kafka partition when using the new Kafka direct stream API. See the Kafka Integration guide for more details.
默认也是没有设置。
现在还搞不清楚这两个的关联。 这个需要去研究源代码。 猜想spark.streaming.receiver.maxRate是限制除kafka以外的吞吐,而spark.streaming.kafka.macRatePerPartition的吞吐。