python - 如何测量 multiprocessing.shared_memory.SharedMemory 分配/使用的实际共享内存?
问题描述
我尝试使用“/usr/bin/time -v”来测量以下代码的实际内存使用情况。但是发现无论给 SharedMemory(..) 的大小是多少,报告的“最大驻留集大小 (kbytes)”都是相同的。
from multiprocessing.shared_memory import SharedMemory
data_bytes_len = 10 ** 8
shm = SharedMemory(create=True, size=data_bytes_len)
print("size of shm:", shm.size)
shm.unlink()
见下面的输出
大小为 100:
size of shm: 100
Command being timed: "python shm.py"
User time (seconds): 0.04
System time (seconds): 0.00
Percent of CPU this job got: 100%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.05
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 13124
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 2809
Voluntary context switches: 0
Involuntary context switches: 2
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
大小如果 100000000
size of shm: 100000000
Command being timed: "python shm.py"
User time (seconds): 0.03
System time (seconds): 0.00
Percent of CPU this job got: 100%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.04
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 12996
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 2811
Voluntary context switches: 0
Involuntary context switches: 2
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
解决方案
推荐阅读
- javascript - 从分组的日期时间创建对象
- python - 在 Python 中按顺序获取查询字符串参数
- java - 从 Firebase 数据库检索时对象缺少数据
- c# - Quartz.NET如何在任务失败或成功时获得结果
- django - 在带有 json api 的 django rest 框架中使用 slug 而不是 ID
- javascript - 新附加的项目会导致之前附加的项目失去切换功能
- python - Python3 `builtins` 并不总是 `__builtins__`
- java - zxing中如何指定扫描区域
- r - 为什么我不能在 ubuntu 的 R 控制台中写“é”?
- delphi - 避免调用重复验证