Skip to content

Conversation

@scwf
Copy link
Contributor

@scwf scwf commented Jul 10, 2015

Now the hash based writer dynamic partitioning show the bad performance for big data and cause many small files and high GC. This patch we do external sort first so that each time we only need open one writer.

before this patch:
gc

after this patch:
gc-optimize-externalsort

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can add a config here to control whether to shuffle before insert

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, please add a SQLConf option, and probably make it off by default.

@scwf
Copy link
Contributor Author

scwf commented Jul 10, 2015

/cc @liancheng

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this private.

@liancheng
Copy link
Contributor

I'm thinking maybe we should make the change in InsertIntoHiveTable.sideEffectResult, where the writer container gets created. So that you don't bother doing a pattern match later.

Another high level comment is that, although this change does work for your workload, the following statement made in the PR description isn't correct:

This patch we shuffle data by the partition columns firstly so that each partition will have ony one partition file and this also reduce the gc overhead.

By repartitioning the dataset by dynamic partition columns, you potentially reduce the number of dynamic partitions handled per task (that's why it reduces GC overhead), but the number can't be guaranteed to be reduced to 1.

Actually we are also considering to improve dynamic partitioning insertion via local sorting (sort by partition columns with the spillable ExternalSorter). Because when writing sorted data, a task only need to open a single writer, and local sorting doesn't require shuffling.

@SparkQA
Copy link

SparkQA commented Jul 10, 2015

Test build #36989 has finished for PR 7336 at commit 10d9f6c.

  • This patch fails PySpark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

+1 for local sorting. I met OOM when writing parquet with many partitions, and my first idea was also shuffle by partition column. But shuffle is expensive, local sort seems better, we may need to profile these 2 approaches.

@scwf
Copy link
Contributor Author

scwf commented Jul 10, 2015

This patch we shuffle data by the partition columns firstly so that each partition will have ony one partition file and this also reduce the gc overhead.

@liancheng here i am not mean the partition of spark rdd, i mean for each partition dir for the table such as .../a=2/b=5 there will be only one file. before this patch there maybe many small files under the partition dir.

@cloud-fan @liancheng I have tested this patch and it shows that the performance not become bad(in my situation, it improved 20%-30%).
Anyway i will also have a try to use ExternalSorter to do a local sorting and will report the performance later.

@scwf scwf changed the title [SPARK-8968] [SQL] shuffled by the partition clomns when dynamic partitioning to optimize the memory overhead [WIP][SPARK-8968] [SQL] shuffled by the partition clomns when dynamic partitioning to optimize the memory overhead Jul 10, 2015
@liancheng
Copy link
Contributor

@scwf Ah I see, these two "partition" concepts are really confusing sometimes... Although I mentioned local sorting, I do tend to also include this repartitioning optimization. But we need to add a SQLConf configuration for it first.

@SparkQA
Copy link

SparkQA commented Jul 13, 2015

Test build #37110 has finished for PR 7336 at commit cb797de.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@scwf scwf changed the title [WIP][SPARK-8968] [SQL] shuffled by the partition clomns when dynamic partitioning to optimize the memory overhead [SPARK-8968] [SQL] shuffled by the partition clomns when dynamic partitioning to optimize the memory overhead Jul 13, 2015
@SparkQA
Copy link

SparkQA commented Jul 13, 2015

Test build #37121 has finished for PR 7336 at commit b8b30d5.

  • This patch fails PySpark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@scwf
Copy link
Contributor Author

scwf commented Jul 13, 2015

retest this please

@SparkQA
Copy link

SparkQA commented Jul 13, 2015

Test build #37126 has finished for PR 7336 at commit b8b30d5.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@liancheng
Copy link
Contributor

@scwf Could you please help verifying whether the HiveQL CLUSTER BY clause helps in your scenario? Essentially what CLUSTER BY does is just adding an Exchange operator, similar to the changes you made in this PR. Sorry that I didn't think of this earlier.

@SparkQA
Copy link

SparkQA commented Jul 16, 2015

Test build #37459 has finished for PR 7336 at commit b5ada0a.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@scwf scwf changed the title [SPARK-8968] [SQL] shuffled by the partition clomns when dynamic partitioning to optimize the memory overhead [SPARK-8968] [SQL] external sort by the partition clomns when dynamic partitioning to optimize the memory overhead Jul 16, 2015
@SparkQA
Copy link

SparkQA commented Jul 16, 2015

Test build #37503 has finished for PR 7336 at commit ef4cc65.

  • This patch fails Scala style tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jul 16, 2015

Test build #37506 has finished for PR 7336 at commit df19e87.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jul 16, 2015

Test build #37519 has finished for PR 7336 at commit 5420868.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@rxin
Copy link
Contributor

rxin commented Jul 18, 2015

Is this related to https://issues.apache.org/jira/browse/SPARK-8890 ?

@liancheng
Copy link
Contributor

@rxin Sort of. This PR tries to fix the same issue on the Hive support side.

@scwf
Copy link
Contributor Author

scwf commented Jul 20, 2015

@rxin, yes we found this issue when do dynamic partitioning in our case, so here i do local sort data on the partition columns to reduce the gc overhead.

@scwf
Copy link
Contributor Author

scwf commented Jul 23, 2015

@rxin any comments here?

@scwf scwf force-pushed the dynamic-optimize-basedon-apachespark branch from 5420868 to c75abcb Compare August 8, 2015 08:12
@SparkQA
Copy link

SparkQA commented Aug 8, 2015

Test build #40231 has finished for PR 7336 at commit c75abcb.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Aug 8, 2015

Test build #40239 has finished for PR 7336 at commit aab3983.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@scwf
Copy link
Contributor Author

scwf commented Aug 12, 2015

/cc @marmbrus can you take a look at this?

@scwf
Copy link
Contributor Author

scwf commented Aug 12, 2015

retest this please

@marmbrus
Copy link
Contributor

This looks good, but i'd like to wait until 1.6 since we are now past the deadline and this is a pretty big change.

@SparkQA
Copy link

SparkQA commented Nov 21, 2015

Test build #46449 timed out for PR 7336 at commit aab3983 after a configured wait of 175m.

@scwf scwf force-pushed the dynamic-optimize-basedon-apachespark branch from aab3983 to b137a0b Compare January 10, 2016 15:13
@scwf
Copy link
Contributor Author

scwf commented Jan 10, 2016

Back to update, @marmbrus @rxin please help review this when you have time.

@scwf scwf force-pushed the dynamic-optimize-basedon-apachespark branch from b137a0b to 7766247 Compare January 10, 2016 15:26
@SparkQA
Copy link

SparkQA commented Jan 10, 2016

Test build #49057 has finished for PR 7336 at commit 7766247.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@rxin
Copy link
Contributor

rxin commented Jan 10, 2016

Is this covering a different code path from #10638 ?

@scwf
Copy link
Contributor Author

scwf commented Jan 11, 2016

@rxin, yes, This PR try to fix the same issue on the Hive support side.

@scwf
Copy link
Contributor Author

scwf commented Jan 16, 2016

Ping @rxin

@rxin
Copy link
Contributor

rxin commented Jan 16, 2016

cc @cloud-fan

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the above code duplicated in parent class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, extracted a common method for it.

@cloud-fan
Copy link
Contributor

retest this please

@SparkQA
Copy link

SparkQA commented Jan 19, 2016

Test build #49690 has finished for PR 7336 at commit 7766247.

  • This patch fails Scala style tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@scwf
Copy link
Contributor Author

scwf commented Jan 20, 2016

retest this please

@SparkQA
Copy link

SparkQA commented Jan 20, 2016

Test build #49789 has finished for PR 7336 at commit 7adbcca.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

LGTM, can you update the statistics pictures in your PR description?

@rxin
Copy link
Contributor

rxin commented Jan 21, 2016

I'm going to merge this. The pictures won't really show up in the commit log so it is not that big of a deal, although in the future we should make sure we update it.

@asfgit asfgit closed this in 015c8ef Jan 21, 2016
@yhuai
Copy link
Contributor

yhuai commented Jan 21, 2016

@scwf It breaks scala 2.11 build. I am going to fix it.

@yhuai
Copy link
Contributor

yhuai commented Jan 21, 2016

Fixed by d60f8d7.

@scwf
Copy link
Contributor Author

scwf commented Jan 21, 2016

@yhuai thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants