Dataproc中Spark任务占满核心但CPU使用率偏低,监控数据存疑
问题:Spark任务CPU使用率与监控数据不符的困惑
基础测试场景
我有一个2节点测试集群,每个节点配置:
- 16 GiB 内存
- 16 核心
使用以下Spark配置运行简单的Parquet计数任务:
from pyspark.sql import SparkSession spark = SparkSession.builder.\ config("spark.executor.cores","5").\ config("spark.executor.instances","6").\ config("spark.executor.memory","4100m").\ config("spark.dynamicAllocation.enabled", False).\ getOrCreate() df_sales = spark.read.parquet("gs://xxxxxxx-xxxxxxxx.appspot.com/spark_datasets/sales_parquet_dtc") df_sales.count()
任务与监控矛盾点
- YARN界面显示集群几乎全部资源已分配,任务有30个并行任务(6个executor × 每个executor5个核心),仅预留2个核心给操作系统
- 但Dataproc CPU监控图表显示CPU使用率最高仅12.5%
- 任务DAG显示Stage1有78个任务,事件时间线显示大部分时间有30个核心处于忙碌状态,按我的理解此时CPU使用率应至少达到30/32≈93.75%
- 已通过
df_sales.withColumn("part_id", spark_partition_id()).groupby("part_id").count().collect()验证,所有分区大小几乎一致
CPU密集型任务测试
为排除工作负载过轻的可能,我调整配置并运行CPU密集型任务:
Spark配置与代码
#spark config spark = SparkSession.builder.\ config("spark.executor.cores","15").\ config("spark.executor.instances","2").\ config("spark.executor.memory","12100m").\ config("spark.dynamicAllocation.enabled", False).\ config("spark.sql.adaptive.enabled", False).\ config("spark.sql.files.maxPartitionBytes","9g").\ getOrCreate() #cache the data (the data is 55 GiBs in csv and ~10 GiB in memory deserialized) df_covid = spark.read.csv("gs://monsoon-credittech.appspot.com/spark_datasets/covid40g.csv", header=True, inferSchema=False) df_covid.cache() df_covid.count() #Run heavy transformations df_covid = df_covid.withColumn("catted",F.concat_ws('',*df_covid.columns)) df_covid = df_covid.withColumn("size0", F.length(F.split("catted", "a").getItem(0))) df_covid = df_covid.withColumn("size1", F.length(F.split("catted", "a").getItem(1))) df_covid = df_covid.withColumn("size2", F.length(F.split("catted", "a").getItem(2))) df_covid.filter((df_covid.size0 > 5) & (df_covid.size1 > 5) & (df_covid.size2 > 5)).count()
监控矛盾点
- 在工作节点用
htop查看,所有核心处于完全忙碌状态 - 但Dataproc YARN CPU使用率图表显示最高仅63%
核心疑问
- 基础测试中,明明30个核心并行处理任务,为何CPU使用率仅12.5%?我的理解是否有误?
- CPU密集型任务中,
htop显示核心满载但YARN监控仅63%,这种差异的原因是什么? - Dataproc YARN监控的CPU使用率指标具体是如何计算的?
内容的提问来源于stack exchange,提问作者figs_and_nuts
相关产品推荐
相关产品推荐

