- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在开发一种用 Python 编写的系统服务(实际上它只是一个日志解析器)。该程序应该长时间连续工作(希望我的意思是几天和几周没有失败和重新启动的需要)。这就是我担心内存消耗的原因。
我将来自不同站点的有关进程内存使用情况的不同信息汇总到一个简单的函数中:
#!/usr/bin/env python
from pprint import pprint
from guppy import hpy
from datetime import datetime
import sys
import os
import resource
import re
def debug_memory_leak():
#Getting virtual memory size
pid = os.getpid()
with open(os.path.join("/proc", str(pid), "status")) as f:
lines = f.readlines()
_vmsize = [l for l in lines if l.startswith("VmSize")][0]
vmsize = int(_vmsize.split()[1])
#Getting physical memory size
pmsize = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
#Analyzing the dynamical memory segment - total number of objects in memory and heap size
h = hpy().heap()
if __debug__:
print str(h)
m = re.match(
"Partition of a set of ([0-9]+) objects. Total size = ([0-9]+) bytes(.*)", str(h))
objects = m.group(1)
heap = int(m.group(2))/1024 #to Kb
current_time = datetime.now().strftime("%H:%M:%S")
data = (current_time, objects, heap, pmsize, vmsize)
print("\t".join([str(d) for d in data]))
这个函数已经被用来研究我长时间播放过程的内存消耗动态,我仍然无法解释它的行为。可以看到,在这 20 分钟内,堆大小和对象总量没有变化,而物理内存和虚拟内存分别增加了 11% 和 1%。
UPD:到目前为止,该过程已经运行了将近 15 个小时。堆还是一样,但是物理内存增加了六倍,虚拟内存增加了 50%。除了凌晨 3:00 的奇怪异常值外,曲线似乎是线性的:
Time Obj Heap PhM VM
19:04:19 31424 3928 5460 143732
19:04:29 30582 3704 10276 158240
19:04:39 30582 3704 10372 157772
19:04:50 30582 3709 10372 157772
19:05:00 30582 3704 10372 157772
(...)
19:25:00 30583 3704 11524 159900
09:53:23 30581 3704 62380 210756
我想知道我的进程的地址空间发生了什么。堆的恒定大小表明所有动态对象都已正确释放。但我毫不怀疑,从长远来看,不断增长的内存消耗会影响这一生命关键过程的可持续性。
谁能澄清一下这个问题?谢谢。
(我使用 RHEL 6.4,内核 2.6.32-358 和 Python 2.6.6)
最佳答案
在不知道您的程序在做什么的情况下,这可能会有所帮助。
不久前我在做一个项目时看到了这篇文章: http://chase-seibert.github.io/blog/2013/08/03/diagnosing-memory-leaks-python.html其中说,“长时间运行的 Python 作业在运行时会消耗大量内存,在进程实际终止之前可能不会将该内存返回给操作系统,即使所有内容都已正确收集垃圾。”
我最终使用多处理模块让我的项目派生出一个单独的进程并在需要工作时返回,此后我没有注意到任何内存问题。
或者在 Python 3.3 中尝试一下 http://bugs.python.org/issue11849
关于Linux 上的 Python 内存消耗 : physical and virtual memory are growing while the heap size remains the same,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23369937/
在 ARM 中,内存类型指定为: 正常 设备 强烈有序 在Device type里面,好像这个类型也可以区分 不可共享的设备内存 可共享设备内存 不可共享和可共享设备内存有什么区别?我们如何分别使用这
在 ARM 中,内存类型指定为: 正常 设备 强烈有序 在Device type里面,好像这个类型也可以区分 不可共享的设备内存 可共享设备内存 不可共享和可共享设备内存有什么区别?我们如何分别使用这
This diagram很清楚不同YARN和Spark内存相关设置之间的关系,除了spark.python.worker.memory。 spark.python.worker.memory 如何适应
我正在尝试使用复杂的if-else决策树来实现GLSL片段着色器。不幸的是,着色器编译器很早就失败,并出现“语法错误-内存耗尽”错误。 GLSL中的代码大小或决策树深度是否有任何限制?有什么建议如何克
什么是“标记内存”,它如何帮助减小程序大小? 最佳答案 您可能指的是 tagged union ,或更具体地说是硬件实现,如 LISP 机器中使用的标记架构。基本上是一种存储具有类型信息的数据的方法。
我的内存有问题。我不明白为什么当我的程序长时间运行时 Go 使用越来越多的内存(从不释放它)。 第一次分配后,程序使用了将近 9 MB 的内存。然后在 12 小时后,它开始以指数方式使用更多内存,直到
在 Windows 机器上,MATLAB 用户可以使用 memory或 feature memstats命令。但是,这些都不能在机器上工作,失败如下: >> memory??? Error using
引导 Linux 内核时,可以在 RAM 中加载 initramfs 存档和 DTB 文件,并将这些物理地址指定给内核。例如,使用 U-Boot,您可以执行以下操作: bootz 0x80008000
我正在学习虚拟内存的概念,但是这个问题让我困惑了一段时间。由于大多数现代计算机都使用虚拟内存,因此当程序正在执行时,操作系统应该在 RAM 和磁盘之间将数据分页进出。但为什么我们仍然遇到“内存不足”的
我在 Colab Pro+(使用高 RAM 选项)上运行神经网络时发现了这个问题。 运行时错误:CUDA 内存不足。尝试分配 8.00 GiB(GPU 0;15.90 GiB 总容量;12.04 Gi
当我在任何地方阅读基于操作系统的书籍时,考虑到时间限制和开销很高,从内存和 I\O(子系统)获取数据是昂贵的,这就是为什么在某些硬件制造商中提供一些其他方式来访问它们,如ARM7 some ISAs像
据我所知,ADS v.10 尝试将查询结果保留在内存中,直到它变得非常大。对于 __output 表和临时表也应该如此。当结果变大时,交换声明。 问题是为查询、 worker 等设置了什么内存限制?可
序言 我正在写一个小演示文稿来列出使用 Docker 时的一些“陷阱”,我也遇到了自己的一个问题。 在解释让 Docker 在没有内存限制的情况下运行的危险时,我发现它的行为不像我预期的那样。 我使用
我们有一个 ASP.NET 项目(40 个左右的 Web 表单、50 个表、相当标准的 IO 内容,并尽可能减少),很快需要部署。系统上大约有 100 个并发用户,但任何时候只有大约 20 个用户在使
我在 dotcloud 上使用 redis 内存存储,但尽管 key 已过期,但它的 used_memory 再也不会下降。从 redis-cli 使用 flushdb 或 flushall 不会导致
我使用的是 Xcode 10.2.1 和 macOS Catalina Developer Beta 2。每当我尝试使用内存图调试器时,我都会收到此错误: Memory Graph Debugger:
所以我一直在寻找这个问题的解决方案有一段时间了。我编写了一个程序来从两个单独的文本文件中获取数据,对其进行解析,然后输出到另一个文本文件和一个 ARFF 文件以供 Weka 分析。我遇到的问题是我编写
对不起,我对 erlang 文档中的以下描述不太清楚: erlang:memory() -> [{Type, Size}] with Type: "total" means: "The total a
在查看示例合约时,有时会在带有“内存”的方法中声明数组,有时则不会。有什么区别? 最佳答案 如果没有内存关键字,Solidity会尝试在存储中声明变量。 首席 Solidity 开发者 chriset
我不明白Matlab并行计算工具箱中的parfor cicle是如何与内存一起工作的:我读到它在所有worker之间共享内存(然后我认为每个worker(核心)都可以访问感兴趣的内存位置而无需制作本地
我是一名优秀的程序员,十分优秀!