Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[BUG] - Memory consumption creating folder with Resolve-PnPFolder #1637

Closed
1 task done
verdeterrejim opened this issue Feb 15, 2022 · 8 comments
Closed
1 task done
Labels
bug Something isn't working

Comments

@verdeterrejim
Copy link

Notice

Many bugs reported are actually related to the PnP Framework which is used behind the scenes. Consider carefully where to report an issue:

  1. Are you using Invoke-PnPSiteTemplate or Get-PnPSiteTemplate? The issue is most likely related to the Provisioning Engine. The Provisioning engine is not located in the PowerShell repo. Please report the issue here: https://github.com/pnp/pnpframework/issues.
  2. Is the issue related to the cmdlet itself, its parameters, the syntax, or do you suspect it is the code of the cmdlet that is causing the issue? Then please continue reporting the issue in this repo.
  3. If you think that the functionality might be related to the underlying libraries that the cmdlet is calling (We realize that might be difficult to determine), please first double check the code of the cmdlet, which can be found here: https://github.com/pnp/powershell/tree/master/src/Commands. If related to the cmdlet, continue reporting the issue here, otherwise report the issue at https://github.com/pnp/pnpframework/issues

Reporting an Issue or Missing Feature

Issue with memory consumption creating folder with Resolve-PnPFolder

Expected behavior

When running a script to process thousands of list items in one library, folders are being created in a new library to prepare for
moving the documents to the new library within the newly created folder. As the script is running I expect that memory
consumption will stay stable and not continually increase.

Actual behavior

As the script is running, memory continues to increase until the machine runs out of memory.

Steps to reproduce behavior

This is the simple script that will cause memory to continually increase:

Get-PnPListItem -Connection $SPConnection -List $LibraryTitle  `
  -PageSize 500 -ScriptBlock { Param($items) $items.Context.ExecuteQuery() } | `
  ForEach-Object {  
    $targetFolderSiteRelUrl = # site relative reference to folder path in different library (where folder doesn't exist)
    Resolve-PnPFolder -Connection $SPConnection -SiteRelativePath $targetFolderSiteRelUrl
  }

What is the version of the Cmdlet module you are running?

1.9.0

Which operating system/environment are you running PnP PowerShell on?

  • Windows
@verdeterrejim verdeterrejim added the bug Something isn't working label Feb 15, 2022
@veronicageek veronicageek changed the title [BUG] [BUG] - Memory consumption creating folder with Resolve-PnPFolder Feb 15, 2022
@jackpoz
Copy link
Contributor

jackpoz commented Mar 17, 2022

Resolve-PnPFolder returns the folder, so your powershell instance is keeping an object with the created folder to show as output at the end.
I would suggest trying with Resolve-PnPFolder | Out-Null . See https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/out-null?view=powershell-7.2 for documentation about Out-Null.

This sounds more like a powershell issue than a PnP PowerShell issue.

@verdeterrejim
Copy link
Author

I tried piping to Out-Null but still experienced the memory consumption issue. I did a memory profile and it's showing that ObjectPathIdentity objects are being retained in the ContextCache. It's the same issue as reported here: pnp/PnP-PowerShell#1182
2022-03-17_10-14-01
.

@jackpoz
Copy link
Contributor

jackpoz commented May 16, 2022

On slightly unrelated note, I ran a script that tried to connect to 210'000 sites one at a time, load $web.LastItemUserModifiedDate, output it to a csv (with -Append) and disconnect from the current site. After 70'000 sites the ram usage reached 3.5 GB and the script got stuck due to memory pressure.

I will try getting a memory dump on the next run to check if it's caused by the same ObjectPathIdentity. Not sure what would be a good approach to fix this, automatically free'ing the cache based on some rules or allowing to manually clear it or both or yet another way.

@gautamdsheth
Copy link
Collaborator

@jackpoz , @verdeterrejim - can you guys try the script with tomorrow's nightly build ? Have managed to reduce usage of ExecuteQuery , so should definitely help and speed up folder creation.

@gautamdsheth
Copy link
Collaborator

@jackpoz / @verdeterrejim - any feedback on this ? Would love to here your thoughts on this.

@verdeterrejim
Copy link
Author

verdeterrejim commented Jun 17, 2022 via email

@jackpoz
Copy link
Contributor

jackpoz commented Jul 4, 2022

@gautamdsheth please note my case was about loading $web.LastItemUserModifiedDate for few thousands of sites and not creating any folder. I have not had time yet to inspect the .NET memory dump.

@jackpoz
Copy link
Contributor

jackpoz commented Jul 11, 2022

I have not had time to inspect the .NET memory dump but I ran the inventory script again (just reading data from 220'000 site collections) and this time the RAM usage stayed low. I don't use Resolve-PnPFolder but some other unrelated changes might have fixed my issue.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants