性能调优
概述
PlantPulse 的性能需要通过依次消除采集 → 处理 → 存储各层级的瓶颈来改进。关键不在于无条件地提高所有参数,而在于监看指标后只调整瓶颈点。
调优的 3 条原则
- 每次只改一个:同时改多个变量会无法判断哪个变更有效。
- 基于运营数据:在测试环境中复现真实流量后再改。
- 记录变更:将改动的值和改前改后的指标存入 GitOps / 运营 wiki。
环境别推荐起始配置
| 环境 | CPU | 内存 | 磁盘 | 推荐 PIPELINE_THREADS | 推荐 PIPELINE_RATELIMIT |
|---|---|---|---|---|---|
| 开发 | 16 vCPU | 64 GB | SSD | 16 | 10,000 MPS |
| 标准 | 32 vCPU | 128 GB | NVMe | 36 | 40,000 MPS |
| 大规模 | 48+ vCPU | 200+ GB | NVMe | 64 | 100,000 MPS |
env.sh 核心调优变量
运营环境中最常调整的变量由主机上的 bin/env.sh 和 compose/docker-compose.yml 管理 → 环境变量参考
| 变量 | 默认值 | 影响 |
|---|---|---|
PP_CLUSTER_CORES | 30 | Spark / 分析内核分配 |
PP_CLUSTER_MEMORY_BY_CORE | 2G | Spark executor 内存/内核 |
PP_LANG / PP_TZ | ko / Asia/Seoul | JVM 地区 / 时区 |
JAVA_TOOL_OPTIONS | 自动生成 | 自动应用于所有子 JVM |
详细变量见 属性参考 中的 env.sh 变量索引。
测量工具
可用于比较调优前后效果的工具:
cd /opt/kopens/plantpulse-platform/plantpulse-datalake-cli/bin
./status.sh # 모듈별 CPU / 메모리(PSS) 요약
./ops-check.sh # 헬스 + critical log
./memory-check.sh # 모듈별 메모리 상세
./memory-rank.sh # 메모리 순위
./pd node tpstats # Cassandra 스레드풀
./pd node compactionstats # Cassandra 컴팩션
./pd node table-stats # 테이블별 통계
./pd node proxyhistograms # Cassandra 지연 히스토그램
# Kafka consumer lag
./pd node topic
# JVM Heap / GC (컨테이너 진입 후)
./shell.sh
jcmd <pid> GC.heap_info
jcmd <pid> GC.heap_dump /tmp/heap.hprof
外部监控(Grafana / Prometheus)参考 系统监控 页面。
提示:性能调优的最优值因服务器规格、数据规模和使用模式而异。建议以下述推荐设置为基准开始,并根据监控结果逐步调整。
引擎管道调优
配置文件:plantpulse-server/config/plantpulse-engine.properties
提示:引擎管道是传感器采集的数据处理的关键路径。通过此设置可以调节数据的处理速度和容量。
管道核心参数
| 参数 | 默认值 | 说明 | 调优指南 |
|---|---|---|---|
engine.pipeline.threads | 36 | 管道工作线程数 | 建议为主机内核数的 70~80%(验证环境 48 核 → 36) |
engine.pipeline.ratelimit | 40000 | 每秒最大处理消息数(MPS) | 按服务器规格调整 |
engine.pipeline.queue.size | 1200000 | 管道队列最大容量 | 按内存余量调整 |
engine.pipeline.queue.o3.delay | 50 | 乱序延迟处理(ms) | 根据网络延迟调整 |
engine.pipeline.task.mode | SINGLE | 管道任务模式 | SINGLE 或 MULTI |
engine.async.parallelism | 256 | 异步并行处理数 | 建议为 CPU 内核的 8~16 倍 |
流处理设置
| 参数 | 默认值 | 说明 |
|---|---|---|
engine.stream.processor | DIRECT | 流处理模式 |
engine.streaming.messaging.warning.ms | 5000 | 消息延迟预警基准(ms) |
engine.streaming.messaging.timeout.ms | 10000 | 消息超时(ms) |
engine.streaming.messaging.timeout.store.type | FILE_QUEUE | 超时消息保存方式 |
engine.streaming.messaging.timeout.recovery.type | DB | 超时恢复方式 |
工作线程
| 参数 | 默认值 | 说明 |
|---|---|---|
engine.job.thread.asset | 8 | 资产任务线程数 |
engine.job.thread.point | 8 | 数据点任务线程数 |
规格别推荐设置
下表为根据服务器规格推荐的设置值。请根据运营环境的规格参考相应列进行设置。
| 项目 | 小规模(8 核/64GB) | 中等规模(16 核/128GB) | 大规模(32 核/256GB) |
|---|---|---|---|
pipeline.threads | 16 | 36 | 64 |
pipeline.ratelimit | 10,000 | 40,000 | 100,000 |
pipeline.queue.size | 300,000 | 1,200,000 | 3,000,000 |
async.parallelism | 64 | 256 | 512 |
Cassandra 调优
配置文件:plantpulse-storage/db/cassandra/conf/cassandra.yaml
提示:Cassandra 是存储时序数据的核心数据库。随着数据规模增大,Cassandra 调优对整体性能影响越来越大,建议根据运营环境进行调整。
内存设置
| 参数 | 默认值 | 说明 |
|---|---|---|
memtable_heap_space | 2GiB | Memtable 堆内存 |
memtable_offheap_space | 2GiB | Memtable 堆外内存 |
memtable_allocation_type | offheap_objects | 内存分配类型 |
memtable_flush_writers | 8 | Memtable 刷新线程数 |
并发设置
| 参数 | 默认值 | 说明 | 调优指南 |
|---|---|---|---|
concurrent_reads | 256 | 并发读线程 | 建议为磁盘数 x 16 |
concurrent_writes | 256 | 并发写线程 | 建议为 CPU 内核 x 8 |
concurrent_counter_writes | 256 | 并发计数器写 | 建议与 concurrent_writes 相同 |
concurrent_compactors | 8 | 并发合并线程 | 建议为 CPU 内核数的 1/4 |
提交日志
| 参数 | 默认值 | 说明 |
|---|---|---|
commitlog_sync | periodic | 同步方式 |
commitlog_sync_period | 10000ms | 同步周期 |
commitlog_segment_size | 320MiB | 段大小 |
commitlog_total_space | 32GiB | 总提交日志空间 |
超时
| 参数 | 默认值 | 说明 |
|---|---|---|
read_request_timeout | 10000ms | 读超时 |
write_request_timeout | 60000ms | 写超时 |
counter_write_request_timeout | 10000ms | 计数器写超时 |
cas_contention_timeout | 1000ms | CAS 竞合超时 |
truncate_request_timeout | 600000ms | Truncate 超时 |
合并策略
PlantPulse 采用适配时序数据特性的 UCS(统一合并策略)。
提示:合并(Compaction)是 Cassandra 对磁盘上存储的数据文件(SSTable)进行整理和合并的操作。使用恰当的合并策略可以节省磁盘空间并提高读取性能。
storage.properties 设置:
| 参数 | 默认值 | 说明 |
|---|---|---|
storage.table.compaction.strategy | UCS | 合并策略(UCS 或 TWCS) |
storage.table.compaction.strategy.ucs.scailing_parameter | T8 | 缩放参数 |
storage.table.compaction.strategy.ucs.min_sstable_size | 128MiB | 最小 SSTable 大小 |
storage.table.compaction.strategy.ucs.target_sstable_size | 512MiB | 目标 SSTable 大小 |
storage.table.compaction.strategy.ucs.base_shard_count | 8 | 基础分片数 |
storage.table.compaction.strategy.ucs.max_sstables_to_compact | 6 | 最大合并 SSTable 数 |
压缩
使用 ZStandard 字典压缩:
| 参数 | 默认值 | 说明 |
|---|---|---|
storage.compression.zstd.type | ZstdDictionaryCompressor | 压缩方式 |
storage.compression.zstd.level | 3 | 压缩级别(1~22,级别越高压缩率越高但速度越慢) |
TTL(数据保留周期)
在 storage.properties 中按表配置 TTL。数据超过 TTL 后会自动删除,请根据数据保留要求进行设置。
| 参数 | 默认值 | 说明 |
|---|---|---|
storage.tag.point.ttl | 62(天) | 标签数据点原始数据 |
storage.tag.point.map.ttl | 1(天) | 标签数据点映射 |
storage.tag.point.sampling.ttl | 93(天) | 采样数据 |
storage.tag.point.snapshot.ttl | 93(天) | 快照数据 |
storage.tag.point.aggregation.ttl | 93(天) | 聚合数据 |
storage.tag.point.archive.ttl | 365(天) | 归档数据 |
storage.tag.blob.ttl | 93(天) | BLOB 数据 |
storage.asset.data.ttl | 10(天) | 资产数据 |
storage.asset.data.sampling.ttl | 31(天) | 资产采样数据 |
Cassandra 性能检查命令
可使用以下命令检查 Cassandra 的性能状态:
# 컴팩션 상태 확인
/opt/kopens/plantpulse-platform/plantpulse-datalake-cli/bin/pd node compactionstats
# 테이블별 통계 확인
/opt/kopens/plantpulse-platform/plantpulse-datalake-cli/bin/pd node table-stats
# 테이블 히스토그램 (읽기/쓰기 지연)
/opt/kopens/plantpulse-platform/plantpulse-datalake-cli/bin/pd node table-histograms
# SSTable 크기 확인
/opt/kopens/plantpulse-platform/plantpulse-datalake-cli/bin/pd node sstable-size
# 스레드풀 통계
/opt/kopens/plantpulse-platform/plantpulse-datalake-cli/bin/pd node tpstats
Spark 调优
配置文件:plantpulse-analytics/spark/conf/spark-defaults.conf
提示:Apache Spark 是用于大数据分析的分布式处理引擎。为提高分析作业的速度和稳定性,请参考下述设置。
资源分配
| 参数 | 默认值 | 说明 |
|---|---|---|
spark.cores.max | 16 | Spark 最大使用内核 |
spark.driver.cores | 2 | 驱动程序内核数 |
spark.driver.memory | 4g | 驱动程序内存 |
spark.executor.cores | 1 | Executor 内核数 |
spark.executor.memory | 2G | Executor 内存 |
spark.executor.memoryOverhead | 2g | Executor 开销内存 |
动态分配
| 参数 | 默认值 | 说明 |
|---|---|---|
spark.dynamicAllocation.enabled | true | 动态 Executor 分配 |
spark.dynamicAllocation.minExecutors | 2 | 最小 Executor 数 |
spark.dynamicAllocation.maxExecutors | 16 | 最大 Executor 数 |
spark.dynamicAllocation.executorIdleTimeout | 30 | 空闲 Executor 释放时间(秒) |
Shuffle 和并行度
| 参数 | 默认值 | 说明 |
|---|---|---|
spark.default.parallelism | 64 | 默认并行度 |
spark.sql.shuffle.partitions | 128 | SQL Shuffle 分区数 |
spark.sql.adaptive.enabled | true | 自适应查询执行 |
spark.sql.adaptive.coalescePartitions.enabled | true | 分区自动合并 |
JVM 设置
Spark 驱动程序/Executor 均使用 ZGC:
-XX:+UseZGC
-XX:+AlwaysPreTouch
-XX:+UseTLAB
-XX:+ResizeTLAB
-XX:+DisableExplicitGC
S3(MinIO)集成设置
| 参数 | 默认值 | 说明 |
|---|---|---|
spark.hadoop.fs.s3a.connection.maximum | 400 | 最大 S3 连接数 |
spark.hadoop.fs.s3a.threads.max | 128 | 最大 S3 线程数 |
spark.hadoop.fs.s3a.max.total.tasks | 1024 | 最大异步操作数 |
spark.hadoop.fs.s3a.fast.upload | true | 启用快速上传 |
spark.hadoop.fs.s3a.fast.upload.buffer | disk | 上传缓冲区类型 |
spark.hadoop.fs.s3a.block.size | 128MB | S3 块大小 |
Iceberg 设置
| 参数 | 默认值 | 说明 |
|---|---|---|
spark.sql.iceberg.write.target-file-size-bytes | 256MB | 目标文件大小 |
spark.sql.iceberg.column-stats.enabled | true | 启用列统计 |
spark.sql.iceberg.vectorization.enabled | true | 启用向量化读取 |
spark.sql.iceberg.manifest.merge.enabled | true | 清单合并 |
spark.sql.parquet.compression.codec | zstd | Parquet 压缩编码 |
Kafka 调优
配置文件:plantpulse-messaging/kafka/config/server.properties
提示:Kafka 是传递传感器数据的实时消息代理。当数据量增加时,可通过调整 Kafka 设置来提高处理性能。
核心设置
| 参数 | 默认值 | 说明 |
|---|---|---|
num.network.threads | 3 | 网络处理线程 |
num.io.threads | 8 | I/O 处理线程 |
socket.send.buffer.bytes | 102400 | 套接字发送缓冲 |
socket.receive.buffer.bytes | 102400 | 套接字接收缓冲 |
socket.request.max.bytes | 104857600 | 最大请求大小(100MB) |
num.partitions | 1 | 默认分区数 |
log.retention.hours | 168 | 日志保留期(7 天) |
log.segment.bytes | 1073741824 | 日志段大小(1GB) |
大容量处理调优
处理大量 IoT 数据时,请参考以下设置进行调整:
# 파티션 수 증가 (메시지 병렬 처리)
num.partitions=4
# I/O 스레드 증가
num.io.threads=16
# 네트워크 스레드 증가
num.network.threads=8
# 소켓 버퍼 증가
socket.send.buffer.bytes=1048576
socket.receive.buffer.bytes=1048576
消息传递设置
配置文件:plantpulse-server/config/plantpulse-mq.properties
Kafka DDS 主题
| 参数 | 默认值 | 用途 |
|---|---|---|
mq.dds.kafka.topic.tag.point | pp-tag-point | 标签数据点值 |
mq.dds.kafka.topic.tag.alarm | pp-tag-alarm | 标签报警 |
mq.dds.kafka.topic.asset.data | pp-asset-data | 资产数据 |
mq.dds.kafka.topic.asset.alarm | pp-asset-alarm | 资产报警 |
mq.dds.kafka.topic.asset.event | pp-asset-event | 资产事件 |
mq.dds.kafka.topic.asset.aggregation | pp-asset-aggregation | 资产聚合 |
mq.dds.kafka.topic.domain.changed.event | pp-domain-changed-event | 元数据变更 |
MQTT DDS 主题
| 参数 | 默认值 | 用途 |
|---|---|---|
mq.dds.mqtt.topic.tag.point | tag/point/{tag_id} | 每个标签的数据点值 |
mq.dds.mqtt.topic.tag.alarm | tag/alarm/{tag_id} | 每个标签的报警 |
mq.dds.mqtt.topic.asset.data | asset/data/{asset_id} | 每个资产的数据 |
mq.dds.mqtt.topic.asset.command | asset/command/{asset_id} | 资产控制命令 |
调度程序设置
配置文件:quartz.properties(Web 应用内部类路径资源 — 非外部化目标)
| 参数 | 默认值 | 说明 |
|---|---|---|
org.quartz.threadPool.threadCount | 8 | 调度程序线程数 |
org.quartz.threadPool.threadPriority | 5 | 线程优先级 |
邮件 / 通知设置
配置文件:plantpulse-server/config/plantpulse-mail.properties
| 参数 | 默认值 | 说明 |
|---|---|---|
mail.smtp.host | 192.168.0.41 | SMTP 服务器地址 |
mail.smtp.port | 25 | SMTP 端口 |
mail.smtp.auth | false | 启用身份验证 |
mail.smtp.starttls.enable | false | 启用 TLS |
应用程序设置
application.properties 文件已在 2026.06 中删除。主题 / 主页等控制台操作设置现在在控制台的系统 > 设置管理(PostgreSQL mm_config 表)中管理,而 alarm.duplicate.check.minutes(重复报警检查间隔,单位:分)已迁移至 plantpulse-server/config/plantpulse-engine.properties。
性能瓶颈诊断
性能问题发生时,请参考下述按症状的诊断方法和解决方案。
1. 管道队列积压
症状:管道等待队列持续增加
# Grafana 대시보드에서 "파이프라인 대기 큐" 패널을 확인해 주세요
# 또는 JMX: pipeline.queue.size 값을 확인해 주세요
解决方法:
- 增加
engine.pipeline.threads值 - 提高
engine.pipeline.ratelimit值 - 检查 Cassandra 写入性能
2. Cassandra 写入延迟
症状:出现写入超时或 WriteTimeoutException
# 컴팩션 상태 확인
/opt/kopens/plantpulse-platform/plantpulse-datalake-cli/bin/pd node compactionstats
# Memtable 플러시
/opt/kopens/plantpulse-platform/plantpulse-datalake-cli/bin/pd node flush
解决方法:
- 增加
concurrent_writes值 - 增加
compaction_throughput值 - 检查磁盘 I/O 性能(建议使用 SSD)
3. 内存不足
症状:JVM GC 频繁发生或出现 OutOfMemoryError
解决方法:
- 在服务模块的
bin/start.sh中增加-Xmx值 - 减少
engine.pipeline.queue.size值以节省内存使用 - 禁用不必要的缓存
4. 网络延迟
症状:数据接收延迟增加(可在 Grafana"网络延迟"面板确认)
解决方法:
- 检查 OPC 服务器与 PlantPulse 间的网络状况
- 调整
engine.streaming.messaging.timeout.ms值 - 检查 MQTT QoS 级别
技术支持
性能调优相关问询:webmaster@kopens.com