- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我开始使用 pyspark 学习 Spark,想知道以下日志消息的含义是什么?
UserWarning: Please install psutil to have better support with spilling
导致溢出的操作是两个 RDD 之间的连接
:
print(user_types.join(user_genres).collect())
这听起来可能有点明显,但我的第一个问题是
我确实安装了 psutil
,并且警告消失了,但我想了解到底发生了什么。有一个very similar question here ,但OP主要询问如何安装psutil
。
最佳答案
Spill 这里意味着将内存中的数据帧写入磁盘,这会降低 pyspark 的性能,因为写入磁盘很慢。
查看节点已使用的内存。
这是 pyspark 源代码 shuffle.py 的原始片段,取自 here这会引发警告。下面的代码定义了一个函数,用于在 psutil 存在或者系统是 Linux 的情况下获取已用内存。
try:
import psutil
def get_used_memory():
""" Return the used memory in MB """
process = psutil.Process(os.getpid())
if hasattr(process, "memory_info"):
info = process.memory_info()
else:
info = process.get_memory_info()
return info.rss >> 20
except ImportError:
def get_used_memory():
""" Return the used memory in MB """
if platform.system() == 'Linux':
for line in open('/proc/self/status'):
if line.startswith('VmRSS:'):
return int(line.split()[1]) >> 10
else:
warnings.warn("Please install psutil to have better "
"support with spilling")
if platform.system() == "Darwin":
import resource
rss = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
return rss >> 20
# TODO: support windows
return 0
如果节点的使用内存大于预设限制,下面的代码将调用将数据帧写入磁盘。
def mergeCombiners(self, iterator, check=True):
""" Merge (K,V) pair by mergeCombiner """
iterator = iter(iterator)
# speedup attribute lookup
d, comb, batch = self.data, self.agg.mergeCombiners, self.batch
c = 0
for k, v in iterator:
d[k] = comb(d[k], v) if k in d else v
if not check:
continue
c += 1
if c % batch == 0 and get_used_memory() > self.memory_limit:
self._spill()
self._partitioned_mergeCombiners(iterator, self._next_limit())
break
此代码实际上将数据帧溢出写入磁盘,以防使用的内存大于预设限制。
def _spill(self):
"""
dump already partitioned data into disks.
It will dump the data in batch for better performance.
"""
global MemoryBytesSpilled, DiskBytesSpilled
path = self._get_spill_dir(self.spills)
if not os.path.exists(path):
os.makedirs(path)
used_memory = get_used_memory()
if not self.pdata:
# The data has not been partitioned, it will iterator the
# dataset once, write them into different files, has no
# additional memory. It only called when the memory goes
# above limit at the first time.
# open all the files for writing
streams = [open(os.path.join(path, str(i)), 'w')
for i in range(self.partitions)]
for k, v in self.data.iteritems():
h = self._partition(k)
# put one item in batch, make it compatitable with load_stream
# it will increase the memory if dump them in batch
self.serializer.dump_stream([(k, v)], streams[h])
for s in streams:
DiskBytesSpilled += s.tell()
s.close()
self.data.clear()
self.pdata = [{} for i in range(self.partitions)]
else:
for i in range(self.partitions):
p = os.path.join(path, str(i))
with open(p, "w") as f:
# dump items in batch
self.serializer.dump_stream(self.pdata[i].iteritems(), f)
self.pdata[i].clear()
DiskBytesSpilled += os.path.getsize(p)
self.spills += 1
gc.collect() # release the memory as much as possible
MemoryBytesSpilled += (used_memory - get_used_memory()) << 20
关于python - pyspark 需要 psutil 做什么? (面对 "UserWarning: Please install psutil to have better support with spilling")?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51226469/
我试图用 python psutil 做一些事情但是得到了一个奇怪的错误。 procs = psutil.get_process_list() 出现以下错误: AttributeError: 'mod
我正在尝试使用 psutil 终止进程 (zoom.exe)。但是,我收到错误 psutil.AccessDenied。我拥有执行此操作的所有权限,并且已经在另一台电脑上进行了测试。 代码 def k
我正在尝试为我的 Linux 服务器编写一个小的异常警报应用程序,我发现 psutil 是一个非常方便的库。 不过,我不是很清楚psutil.cpu_percent(interval=1)和psuti
我开始使用 pyspark 学习 Spark,想知道以下日志消息的含义是什么? UserWarning: Please install psutil to have better support wi
我在我的 Snakemake 工作流程中包含了一些规则的 benchmark 指令,生成的文件具有以下 header : s h:m:s max_rss max_vms max_uss max
我正在尝试在 centos 中安装 psutil 并且同样因 gcc 错误而失败。我在这个论坛上提到了各种帖子,但没有一个有帮助。许多线程建议使用 pydev 但它已经存在于我的系统中 #sudo /
有人能帮我理解为什么我不能安装 psutil 吗?我在 MacOS 上。我是一个菜鸟,所以请耐心等待,但任何帮助将不胜感激。这可能与我安装的默认 Python 安装 vs v3 有关吗?我是命令行的新
我正在尝试运行这段代码,但我没有按名称获取进程列表: import psutil PROCNAME = "python.exe" for proc in psutil.process_iter():
我正在尝试安装 lib psutil,使用命令 !pip install psutil。当我运行这段代码时,我得到了这个 Requirement already satisfied: psutil i
也许我忽略了一些东西,但我无法弄清楚如何在不遍历所有进程的情况下一次获取所有进程的 current_process.cpu_percent(interval=0.1)。当前迭代需要 process_c
我正在为 Linux 编写一个 Python 脚本,该脚本应该在满足给定条件时暂停进程,然后再恢复它。为此,我使用 psutil (http://code.google.com/p/psutil)。我
我正在尝试查找所有可用的端口来连接计算机。我正在使用下面的代码 import psutil for proc in psutil.process_iter(): print (proc)
我有一个小的 python 脚本,基本上如下所示: import os import psutil def processtree(): pid = os.getpid() # hav
我正在尝试测量进程树的 CPU 使用率。 目前获取一个进程(没有子进程)的 cpu_usage 就可以了,但是我得到了奇怪的结果。 import psutil p = psutil.Process(P
当运行 psutil.virtual_memory() 时,我得到这样的输出: >>psutil.virtual_memory() vmem(total=8374149120L, av
Glances v2.11.1 with psutil v5.4.3 /usr/lib/python3.6/site-packages/psutil/_pslinux.py:1152: Runtime
我正在编写一些代码,根据进程的名称和所有者来终止进程。这在 Windows XP 上运行良好,但当我在 Windows 7 上运行相同的代码时,在尝试获取进程的用户名时出现“访问被拒绝”错误。 是否有
我的目标只是列出占用内存最多的 5 个进程,以及它们“使用”了多少内存。我已通读文档,似乎 process.memory_info().rss 就是我想要的,但是这个数字明显小于 Windows 任务
get_cpu_percent()函数具体如何使用? 我的代码是: SDKTestSuite.DijSDK_CalculateFps(int(timeForFPS),int(index),camera
我在 python 解释器中执行以下两个语句。 >>> psutil.cpu_percent(interval=None, percpu=False) 2.0 >>> psutil.cpu_perce
我是一名优秀的程序员,十分优秀!