脚本消耗GB的RAM [英] Script consumes GBs of RAM
问题描述
我有一个脚本使用Get-ACL读取文件夹的文件系统权限,然后枚举组成员资格(包括跨域嵌套)。 (非常正常的东西)。
我使用的对象是:
- 存储收集的信息
- 存储a以前收集的信息的副本
- 存储计算的差异以便处理到数据库中
运行时的脚本包含GB的RAM并且变得越来越慢,因为它这样做。 我正在寻找有关如何减少此问题的建议?
阅读我相信我应该更多地使用管道 - 但是我必须重新编写脚本并且松散了很多如果我这样做的可读性,那么我宁愿不在这一点。
我可以从定期删除然后重新创建我的对象变量中获益吗? (使用New-Object System.Collections.ArrayList创建)。 Remove-Variable会这样做吗? 我的测试表明这无济于事。 允许$ b $ b脚本完成,然后删除了各种变量,我看到ISE没有减少RAM使用量。
我正在使用Compare-Object。 围绕这些填充内置变量的差异是否会出现缓慢消耗RAM的问题? 有什么我可以做的来减少这里的限制吗?
我唯一的另一个想法是尝试进一步打破脚本 - 一个'父'脚本来获取列表要处理的事情,然后为每个要处理的区域调用"子"脚本。
TIA
< blockquote>它可能是您存储和处理的大量数据,可能使用管道和/或日志文件将结果保存到磁盘而不是内存中?
I have a script that uses Get-ACL to read the file system permissions on a folder, then enumerates the group membership (including cross domain nesting). (Very normal stuff).
I am using objects to:
- Store gathered information
- Store a copy of the previously gathered information
- Store calculated differences for processing into database
The script when run comsumes GBs of RAM and gets slower and slower as it does so. I am looking for advice on how to reduce this?
Reading around I believe I should make more use of the pipeline - however I'd have to re-write the script and loose a lot of readability if I did this, so I would rather not at this point.
Might I benefit from regularly removing then re-creating my object variables? (Created using New-Object System.Collections.ArrayList). Would Remove-Variable do this properly? My testing suggest this will not help. Having allowed the script to complete, then removed various variables I have seen no reduction in RAM usage by ISE.
I am using Compare-Object. Could there be something around this populating inbuilt variables of the differences that are slowly consuming RAM? Is there anything I could do to reduce\limit\housekeep this?
My only other thought is to try and break the script further - a 'parent' script to get the list of things to process, then a 'child' script to be called for each area to process.
TIA
It may be the bulk of data you are storing and processing, maybe using pipelines and/or log files to save results to disk as you go rather than in memory?
这篇关于脚本消耗GB的RAM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!