{"action":"created","issue":{"url":"https://api.github.com/repos/apache/spark/issues/13042","repository_url":"https://api.github.com/repos/apache/spark","labels_url":"https://api.github.com/repos/apache/spark/issues/13042/labels{/name}","comments_url":"https://api.github.com/repos/apache/spark/issues/13042/comments","events_url":"https://api.github.com/repos/apache/spark/issues/13042/events","html_url":"https://github.com/apache/spark/pull/13042","id":154145934,"number":13042,"title":"[SPARK-15263][Core] Make shuffle service dir cleanup faster by using `rm -rf`","user":{"login":"tejasapatil","id":3230057,"avatar_url":"https://avatars.githubusercontent.com/u/3230057?v=3","gravatar_id":"","url":"https://api.github.com/users/tejasapatil","html_url":"https://github.com/tejasapatil","followers_url":"https://api.github.com/users/tejasapatil/followers","following_url":"https://api.github.com/users/tejasapatil/following{/other_user}","gists_url":"https://api.github.com/users/tejasapatil/gists{/gist_id}","starred_url":"https://api.github.com/users/tejasapatil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tejasapatil/subscriptions","organizations_url":"https://api.github.com/users/tejasapatil/orgs","repos_url":"https://api.github.com/users/tejasapatil/repos","events_url":"https://api.github.com/users/tejasapatil/events{/privacy}","received_events_url":"https://api.github.com/users/tejasapatil/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-05-11T02:16:02Z","updated_at":"2016-05-11T05:57:36Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/13042","html_url":"https://github.com/apache/spark/pull/13042","diff_url":"https://github.com/apache/spark/pull/13042.diff","patch_url":"https://github.com/apache/spark/pull/13042.patch"},"body":"## What changes were proposed in this pull request?\r\n\r\nJira: https://issues.apache.org/jira/browse/SPARK-15263\r\n\r\nThe current logic for directory cleanup is slow because it does directory listing, recurses over child directories, checks for symbolic links, deletes leaf files and finally deletes the dirs when they are empty. There is back-and-forth switching from kernel space to user space while doing this. Since most of the deployment backends would be Unix systems, we could essentially just do `rm -rf` so that entire deletion logic runs in kernel space.\r\n\r\nThe current Java based impl in Spark seems to be similar to what standard libraries like guava and commons IO do (eg. http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/FileUtils.java?view=markup#l1540). However, guava removed this method in favour of shelling out to an operating system command (like in this PR). See the `Deprecated` note in older javadocs for guava for details : http://google.github.io/guava/releases/10.0.1/api/docs/com/google/common/io/Files.html#deleteRecursively(java.io.File)\r\n\r\nIdeally, Java should be providing such APIs so that users won't have to do such things to get platform specific code. Also, its not just about speed, but also handling race conditions while doing at FS deletions is tricky. I could find this bug for Java in similar context : http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7148952\r\n\r\n## How was this patch tested?\r\n\r\nI am relying on existing test cases to test the method. If there are suggestions about testing it, welcome to hear about it.\r\n\r\n## Performance gains\r\n\r\n*Input setup* : Created a nested directory structure of depth 3 and each entry having 50 sub-dirs. The input being cleaned up had total ~125k dirs.\r\n\r\nRan both approaches (in isolation) for 6 times to get average numbers:\r\n\r\nNative Java cleanup  | `rm -rf` as a separate process\r\n------------ | -------------\r\n10.04 sec | 4.11 sec\r\n\r\nThis change made deletion 2.4 times faster for the given test input."},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/218368903","html_url":"https://github.com/apache/spark/pull/13042#issuecomment-218368903","issue_url":"https://api.github.com/repos/apache/spark/issues/13042","id":218368903,"user":{"login":"SparkQA","id":8108735,"avatar_url":"https://avatars.githubusercontent.com/u/8108735?v=3","gravatar_id":"","url":"https://api.github.com/users/SparkQA","html_url":"https://github.com/SparkQA","followers_url":"https://api.github.com/users/SparkQA/followers","following_url":"https://api.github.com/users/SparkQA/following{/other_user}","gists_url":"https://api.github.com/users/SparkQA/gists{/gist_id}","starred_url":"https://api.github.com/users/SparkQA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SparkQA/subscriptions","organizations_url":"https://api.github.com/users/SparkQA/orgs","repos_url":"https://api.github.com/users/SparkQA/repos","events_url":"https://api.github.com/users/SparkQA/events{/privacy}","received_events_url":"https://api.github.com/users/SparkQA/received_events","type":"User","site_admin":false},"created_at":"2016-05-11T05:57:36Z","updated_at":"2016-05-11T05:57:36Z","body":"**[Test build #58332 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/58332/consoleFull)** for PR 13042 at commit [`1877ad4`](https://github.com/apache/spark/commit/1877ad4ea0dc003c042728d36c65e1f74297b7a1)."}}