我的 spark 流应用程序正在使用 DStream 方法从 kafka 中读取数据,我试图让批处理大小在 10 秒内处理 60,000 条消息。
我所做的,
- 创建了一个包含 3 个分区的主题
spark.streaming.kafka.maxRatePerPartition = 60000
spark.streaming.backpressure.enabled = true
- 创建 StreamingContext 时将批处理持续时间设置为 10 秒
- 以 2 个执行器在纱线模式下运行(3 个分区共 4 个核心)
现在我如何测试它是否有效。
我有一个生产者一次向该主题发送 60,000 条消息。当我检查 spark UI 时,我得到以下信息:
batch time | Input size | processing time
10:54:30 | 17610 | 5s
10:54:20 | 32790 | 8s
10:54:10 | 9600 | 3s
所以每批时间间隔 10 秒。我期望的是 1 批有 60,000 条记录。还有其他一些我没有设置的参数吗?从我读到的关于我目前设置的内容来看,我应该在一个批次中获得 10 * 60,000 * 3 = 1800000。
spark.app.id = application_1551747423133_0677
spark.app.name = KafkaCallDEV
spark.driver.cores = 2
spark.driver.extraJavaOptions = -XX:+UseG1GC -XX:ConcGCThreads=2
-XX:InitiatingHeapOccupancyPercent=35 -Dlog4j.configuration=log4j.properties -verbose:gc
spark.driver.memory = 3g
spark.driver.port = 33917
spark.executor.cores = 2
spark.executor.extraJavaOptions = -XX:+UseG1GC -XX:ConcGCThreads=2
-XX:InitiatingHeapOccupancyPercent=35 -Dlog4j.configuration=log4j.properties -verbose:gc
spark.executor.id = driver
spark.executor.instances = 2
spark.executor.memory = 2g
spark.master = yarn
spark.scheduler.mode = FIFO
spark.streaming.backpressure.enabled = true
spark.streaming.kafka.maxRatePerPartition = 60000
spark.submit.deployMode = cluster
spark.ui.filters = org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter
spark.ui.port = 0
spark.yarn.app.container.log.dir = /data0/yarn/container-logs/application_1551747423133_0677/container_1551747423133_0677_01_000002
下面是我使用打印出来的
logger.info(sparkSession.sparkContext.getConf.getAll.mkString("\n"))
我删除了一些不必要的日志,如服务器地址、应用程序名称等。
(spark.executor.extraJavaOptions,-XX:+UseG1GC -XX:ConcGCThreads=2
-XX:InitiatingHeapOccupancyPercent=35 -Dlog4j.configuration=log4j.properties -verbose:gc) (spark.yarn.app.id,application_1551747423133_0681)
(spark.submit.deployMode,cluster)
(spark.streaming.backpressure.enabled,true)
(spark.yarn.credentials.renewalTime,1562764821939ms)
(spark.ui.filters,org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter)
(spark.executor.memory,2g)
(spark.yarn.credentials.updateTime,1562769141873ms)
(spark.driver.cores,2)
(spark.executor.id,driver)
(spark.executor.cores,2)
(spark.master,yarn)
(spark.driver.memory,3g)
(spark.sql.warehouse.dir,/user/hive/warehouse)
(spark.ui.port,0)
(spark.driver.extraJavaOptions,-XX:+UseG1GC -XX:ConcGCThreads=2
-XX:InitiatingHeapOccupancyPercent=35 -Dlog4j.configuration=log4j.properties -verbose:gc)
(spark.executor.instances,2)
(spark.driver.port,37375)
我还有一些正在打印的 Kafka 配置,所以我也会在下面发布这些配置。
org.apache.kafka.clients.consumer.ConsumerConfig:178 - ConsumerConfig values:
metric.reporters = []
metadata.max.age.ms = 300000
partition.assignment.strategy = [org.apache.kafka.clients.consumer.RangeAssignor]
reconnect.backoff.ms = 50
sasl.kerberos.ticket.renew.window.factor = 0.8
max.partition.fetch.bytes = 1048576
ssl.keystore.type = JKS
enable.auto.commit = false
sasl.mechanism = GSSAPI
interceptor.classes = null
exclude.internal.topics = true
ssl.truststore.password = null
client.id =
ssl.endpoint.identification.algorithm = null
max.poll.records = 60000
check.crcs = true
request.timeout.ms = 40000
heartbeat.interval.ms = 3000
auto.commit.interval.ms = 5000
receive.buffer.bytes = 65536
ssl.truststore.type = JKS
ssl.truststore.location = null
ssl.keystore.password = null
fetch.min.bytes = 1
send.buffer.bytes = 131072
value.deserializer = class org.apache.kafka.common.serialization.StringDeserializer
retry.backoff.ms = 100
ssl.secure.random.implementation = null
sasl.kerberos.kinit.cmd = /usr/bin/kinit
sasl.kerberos.service.name = null
sasl.kerberos.ticket.renew.jitter = 0.05
ssl.trustmanager.algorithm = PKIX
ssl.key.password = null
fetch.max.wait.ms = 500
sasl.kerberos.min.time.before.relogin = 60000
connections.max.idle.ms = 540000
session.timeout.ms = 30000
metrics.num.samples = 2
key.deserializer = class org.apache.kafka.common.serialization.StringDeserializer
ssl.protocol = TLS
ssl.provider = null
ssl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1]
ssl.keystore.location = null
ssl.cipher.suites = null
security.protocol = PLAINTEXT
ssl.keymanager.algorithm = SunX509
metrics.sample.window.ms = 30000
auto.offset.reset = latest