question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: rmdir recursive - is it safe to parallelize?

See original GitHub issue

I see that the rmdir method can remove recursively. However, I need to remove a very large tree. Because this function does an await on every delete, it is painfully slow for my use case.

See https://github.com/theophilusx/ssh2-sftp-client/blob/d6b170aaefaaca21a3f95f84f581410141c222ac/src/index.js#L943-L948

Just wonder if you happen to know if this operation is safe to parallelize? Even if I have to manually implement a limit that be ok.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
theophilusxcommented, Apr 5, 2022

Just about to push v8.0.0, so closing this issue now.

1reaction
theophilusxcommented, Mar 27, 2022

I have made some changes to the rmdir method which might help your use case. Two main tings I have done are

  • Re-worked the tracking of event listeners to eliminate the previous problem where recursive and parallel calls would tread on each other.
  • Modified the rmdir method so that now it uses Promise.all() to run all delete file methods asynchronously. This should improve performance when directories have large numbers of files which need to be removed before the directory can be removed.

The actual removal of directories is still synchronous because the recursive nature makes it too easy to blow out when there is a deep tree and many recursive calls.

I would be great if you could try this out and see if it helps your use case or not. The updated code is in the github repository under the branch called ‘rmdir-performance’. Be great to have it tested on a large directory tree.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parallelize recursive deletion with find - Unix Stack Exchange
Save this question. Show activity on this post. I want to recursively delete all files that end with .
Read more >
Doing an rm -rf on a massive directory tree takes hours
No. rm -rf does a recursive depth-first traversal of your filesystem, calling unlink() on every file. The two operations that cause the ...
Read more >
Is node.js rmdir recursive ? Will it work on non empty ...
I don't know if it's me or a general problem, but files inside deleted directory will act very odd. after rmdirSync is done,...
Read more >
Parallel Builds - redo: a recursive build system
Parallelism if more than one target depends on the same subdir. Recursive make is especially painful when it comes to parallelism.
Read more >
The Pitfalls and Benefits of GNU Make Parallelization
The classic recursive Make style that uses a shell for loop processes each sub-Make in turn which doesn't allow more than one sub-Make...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found