跳到主要内容

性能调优

概述

PlantPulse 的性能需要通过依次消除采集 → 处理 → 存储各层级的瓶颈来改进。关键不在于无条件地提高所有参数,而在于监看指标后只调整瓶颈点

调优的 3 条原则

  1. 每次只改一个:同时改多个变量会无法判断哪个变更有效。
  2. 基于运营数据:在测试环境中复现真实流量后再改。
  3. 记录变更:将改动的值和改前改后的指标存入 GitOps / 运营 wiki。

环境别推荐起始配置

环境CPU内存磁盘推荐 PIPELINE_THREADS推荐 PIPELINE_RATELIMIT
开发16 vCPU64 GBSSD1610,000 MPS
标准32 vCPU128 GBNVMe3640,000 MPS
大规模48+ vCPU200+ GBNVMe64100,000 MPS

env.sh 核心调优变量

运营环境中最常调整的变量由主机上的 bin/env.shcompose/docker-compose.yml 管理 → 环境变量参考

变量默认值影响
PP_CLUSTER_CORES30Spark / 分析内核分配
PP_CLUSTER_MEMORY_BY_CORE2GSpark executor 内存/内核
PP_LANG / PP_TZko / Asia/SeoulJVM 地区 / 时区
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.threads36管道工作线程数建议为主机内核数的 70~80%(验证环境 48 核 → 36)
engine.pipeline.ratelimit40000每秒最大处理消息数(MPS)按服务器规格调整
engine.pipeline.queue.size1200000管道队列最大容量按内存余量调整
engine.pipeline.queue.o3.delay50乱序延迟处理(ms)根据网络延迟调整
engine.pipeline.task.modeSINGLE管道任务模式SINGLEMULTI
engine.async.parallelism256异步并行处理数建议为 CPU 内核的 8~16 倍

流处理设置

参数默认值说明
engine.stream.processorDIRECT流处理模式
engine.streaming.messaging.warning.ms5000消息延迟预警基准(ms)
engine.streaming.messaging.timeout.ms10000消息超时(ms)
engine.streaming.messaging.timeout.store.typeFILE_QUEUE超时消息保存方式
engine.streaming.messaging.timeout.recovery.typeDB超时恢复方式

工作线程

参数默认值说明
engine.job.thread.asset8资产任务线程数
engine.job.thread.point8数据点任务线程数

规格别推荐设置

下表为根据服务器规格推荐的设置值。请根据运营环境的规格参考相应列进行设置。

项目小规模(8 核/64GB)中等规模(16 核/128GB)大规模(32 核/256GB)
pipeline.threads163664
pipeline.ratelimit10,00040,000100,000
pipeline.queue.size300,0001,200,0003,000,000
async.parallelism64256512

Cassandra 调优

配置文件:plantpulse-storage/db/cassandra/conf/cassandra.yaml

提示:Cassandra 是存储时序数据的核心数据库。随着数据规模增大,Cassandra 调优对整体性能影响越来越大,建议根据运营环境进行调整。

内存设置

参数默认值说明
memtable_heap_space2GiBMemtable 堆内存
memtable_offheap_space2GiBMemtable 堆外内存
memtable_allocation_typeoffheap_objects内存分配类型
memtable_flush_writers8Memtable 刷新线程数

并发设置

参数默认值说明调优指南
concurrent_reads256并发读线程建议为磁盘数 x 16
concurrent_writes256并发写线程建议为 CPU 内核 x 8
concurrent_counter_writes256并发计数器写建议与 concurrent_writes 相同
concurrent_compactors8并发合并线程建议为 CPU 内核数的 1/4

提交日志

参数默认值说明
commitlog_syncperiodic同步方式
commitlog_sync_period10000ms同步周期
commitlog_segment_size320MiB段大小
commitlog_total_space32GiB总提交日志空间

超时

参数默认值说明
read_request_timeout10000ms读超时
write_request_timeout60000ms写超时
counter_write_request_timeout10000ms计数器写超时
cas_contention_timeout1000msCAS 竞合超时
truncate_request_timeout600000msTruncate 超时

合并策略

PlantPulse 采用适配时序数据特性的 UCS(统一合并策略)

提示:合并(Compaction)是 Cassandra 对磁盘上存储的数据文件(SSTable)进行整理和合并的操作。使用恰当的合并策略可以节省磁盘空间并提高读取性能。

storage.properties 设置:

参数默认值说明
storage.table.compaction.strategyUCS合并策略(UCSTWCS
storage.table.compaction.strategy.ucs.scailing_parameterT8缩放参数
storage.table.compaction.strategy.ucs.min_sstable_size128MiB最小 SSTable 大小
storage.table.compaction.strategy.ucs.target_sstable_size512MiB目标 SSTable 大小
storage.table.compaction.strategy.ucs.base_shard_count8基础分片数
storage.table.compaction.strategy.ucs.max_sstables_to_compact6最大合并 SSTable 数

压缩

使用 ZStandard 字典压缩:

参数默认值说明
storage.compression.zstd.typeZstdDictionaryCompressor压缩方式
storage.compression.zstd.level3压缩级别(1~22,级别越高压缩率越高但速度越慢)

TTL(数据保留周期)

storage.properties 中按表配置 TTL。数据超过 TTL 后会自动删除,请根据数据保留要求进行设置。

参数默认值说明
storage.tag.point.ttl62(天)标签数据点原始数据
storage.tag.point.map.ttl1(天)标签数据点映射
storage.tag.point.sampling.ttl93(天)采样数据
storage.tag.point.snapshot.ttl93(天)快照数据
storage.tag.point.aggregation.ttl93(天)聚合数据
storage.tag.point.archive.ttl365(天)归档数据
storage.tag.blob.ttl93(天)BLOB 数据
storage.asset.data.ttl10(天)资产数据
storage.asset.data.sampling.ttl31(天)资产采样数据

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.max16Spark 最大使用内核
spark.driver.cores2驱动程序内核数
spark.driver.memory4g驱动程序内存
spark.executor.cores1Executor 内核数
spark.executor.memory2GExecutor 内存
spark.executor.memoryOverhead2gExecutor 开销内存

动态分配

参数默认值说明
spark.dynamicAllocation.enabledtrue动态 Executor 分配
spark.dynamicAllocation.minExecutors2最小 Executor 数
spark.dynamicAllocation.maxExecutors16最大 Executor 数
spark.dynamicAllocation.executorIdleTimeout30空闲 Executor 释放时间(秒)

Shuffle 和并行度

参数默认值说明
spark.default.parallelism64默认并行度
spark.sql.shuffle.partitions128SQL Shuffle 分区数
spark.sql.adaptive.enabledtrue自适应查询执行
spark.sql.adaptive.coalescePartitions.enabledtrue分区自动合并

JVM 设置

Spark 驱动程序/Executor 均使用 ZGC

-XX:+UseZGC
-XX:+AlwaysPreTouch
-XX:+UseTLAB
-XX:+ResizeTLAB
-XX:+DisableExplicitGC

S3(MinIO)集成设置

参数默认值说明
spark.hadoop.fs.s3a.connection.maximum400最大 S3 连接数
spark.hadoop.fs.s3a.threads.max128最大 S3 线程数
spark.hadoop.fs.s3a.max.total.tasks1024最大异步操作数
spark.hadoop.fs.s3a.fast.uploadtrue启用快速上传
spark.hadoop.fs.s3a.fast.upload.bufferdisk上传缓冲区类型
spark.hadoop.fs.s3a.block.size128MBS3 块大小

Iceberg 设置

参数默认值说明
spark.sql.iceberg.write.target-file-size-bytes256MB目标文件大小
spark.sql.iceberg.column-stats.enabledtrue启用列统计
spark.sql.iceberg.vectorization.enabledtrue启用向量化读取
spark.sql.iceberg.manifest.merge.enabledtrue清单合并
spark.sql.parquet.compression.codeczstdParquet 压缩编码

Kafka 调优

配置文件:plantpulse-messaging/kafka/config/server.properties

提示:Kafka 是传递传感器数据的实时消息代理。当数据量增加时,可通过调整 Kafka 设置来提高处理性能。

核心设置

参数默认值说明
num.network.threads3网络处理线程
num.io.threads8I/O 处理线程
socket.send.buffer.bytes102400套接字发送缓冲
socket.receive.buffer.bytes102400套接字接收缓冲
socket.request.max.bytes104857600最大请求大小(100MB)
num.partitions1默认分区数
log.retention.hours168日志保留期(7 天)
log.segment.bytes1073741824日志段大小(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.pointpp-tag-point标签数据点值
mq.dds.kafka.topic.tag.alarmpp-tag-alarm标签报警
mq.dds.kafka.topic.asset.datapp-asset-data资产数据
mq.dds.kafka.topic.asset.alarmpp-asset-alarm资产报警
mq.dds.kafka.topic.asset.eventpp-asset-event资产事件
mq.dds.kafka.topic.asset.aggregationpp-asset-aggregation资产聚合
mq.dds.kafka.topic.domain.changed.eventpp-domain-changed-event元数据变更

MQTT DDS 主题

参数默认值用途
mq.dds.mqtt.topic.tag.pointtag/point/{tag_id}每个标签的数据点值
mq.dds.mqtt.topic.tag.alarmtag/alarm/{tag_id}每个标签的报警
mq.dds.mqtt.topic.asset.dataasset/data/{asset_id}每个资产的数据
mq.dds.mqtt.topic.asset.commandasset/command/{asset_id}资产控制命令

调度程序设置

配置文件:quartz.properties(Web 应用内部类路径资源 — 非外部化目标)

参数默认值说明
org.quartz.threadPool.threadCount8调度程序线程数
org.quartz.threadPool.threadPriority5线程优先级

邮件 / 通知设置

配置文件:plantpulse-server/config/plantpulse-mail.properties

参数默认值说明
mail.smtp.host192.168.0.41SMTP 服务器地址
mail.smtp.port25SMTP 端口
mail.smtp.authfalse启用身份验证
mail.smtp.starttls.enablefalse启用 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