Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Enhancement][Cherry-pick][Branch-2.5] Optimize memory usage of primary key table large load (#12068) #13744

Merged
merged 2 commits into from
Nov 27, 2022

Conversation

sevev
Copy link
Contributor

@sevev sevev commented Nov 21, 2022

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Which issues of this PR fixes :

Fixes #

Problem Summary(Required) :

Currently, RowsetUpdateState::load will preload all segments primary keys into memory, if the load(rowset) is very large, it will use a lot of memory during the commit or apply phrase.

For large load(rowset), we don't preload all segment's primary keys but process segment by segment, which can reduce the memory usage during apply.

It is important to note that the limitation is a soft limit because we can't tolerate the failure to apply, so memory usage may still exceed the limitation.

In my test env, one BE with two HDD, using Broker load, create a table with persistent index:

use tpcds to test
create table sql, using broker load:

CREATE TABLE store_sales (
ss_item_sk bigint(20) NOT NULL COMMENT "",
ss_ticket_number bigint(20) NOT NULL COMMENT "",
ss_sold_date_sk bigint(20) NULL COMMENT "",
ss_sold_time_sk bigint(20) NULL COMMENT "",
ss_customer_sk bigint(20) NULL COMMENT "",
ss_cdemo_sk bigint(20) NULL COMMENT "",
ss_hdemo_sk bigint(20) NULL COMMENT "",
ss_addr_sk bigint(20) NULL COMMENT "",
ss_store_sk bigint(20) NULL COMMENT "",
ss_promo_sk bigint(20) NULL COMMENT "",
ss_quantity bigint(20) NULL COMMENT "",
ss_wholesale_cost decimal64(7, 2) NULL COMMENT "",
ss_list_price decimal64(7, 2) NULL COMMENT "",
ss_sales_price decimal64(7, 2) NULL COMMENT "",
ss_ext_discount_amt decimal64(7, 2) NULL COMMENT "",
ss_ext_sales_price decimal64(7, 2) NULL COMMENT "",
ss_ext_wholesale_cost decimal64(7, 2) NULL COMMENT "",
ss_ext_list_price decimal64(7, 2) NULL COMMENT "",
ss_ext_tax decimal64(7, 2) NULL COMMENT "",
ss_coupon_amt decimal64(7, 2) NULL COMMENT "",
ss_net_paid decimal64(7, 2) NULL COMMENT "",
ss_net_paid_inc_tax decimal64(7, 2) NULL COMMENT "",
ss_net_profit decimal64(7, 2) NULL COMMENT ""
) ENGINE=OLAP
PRIMARY KEY(ss_item_sk, ss_ticket_number)
COMMENT "OLAP"
DISTRIBUTED BY HASH(ss_item_sk, ss_ticket_number) BUCKETS 2 PROPERTIES (
"replication_num" = "1",
"in_memory" = "false",
"storage_format" = "DEFAULT",
"enable_persistent_index" = "true",
"compression" = "LZ4"
);
PrimaryKey Length RowNum BucketNum Load time(s) Apply time(ms) Peak Memory usage(GB) Note 16 Bytes 864001869 2 7643 355200 25.03 branch-opt
16 Bytes 864001869 2 7591 348465 46.45 branch-main 16 Bytes 864001869 100 7194 32705 25.11 branch-opt 16 Bytes 864001869 100 7104 30705 43.14 branch-main Note there are still some scenarios we don't resolve in this pr:

In the partial update, the read column data maybe very large and we don't resolve it in this pr We still need to load all primary key into L0 of persistent index first which maybe cause OOM

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr will affect users' behaviors
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function

…tarRocks#12068)

Currently, RowsetUpdateState::load will preload all segments primary keys into memory, if the load(rowset) is very large, it will use a lot of memory during the commit or apply phrase.

For large load(rowset), we don't preload all segment's primary keys but process segment by segment, which can reduce the memory usage during apply.

It is important to note that the limitation is a soft limit because we can't tolerate the failure to apply, so memory usage may still exceed the limitation.

In my test env, one BE with two HDD, using Broker load, create a table with persistent index:

use tpcds to test
create table sql, using broker load:

CREATE TABLE `store_sales` (
  `ss_item_sk` bigint(20) NOT NULL COMMENT "",
  `ss_ticket_number` bigint(20) NOT NULL COMMENT "",
  `ss_sold_date_sk` bigint(20) NULL COMMENT "",
  `ss_sold_time_sk` bigint(20) NULL COMMENT "",
  `ss_customer_sk` bigint(20) NULL COMMENT "",
  `ss_cdemo_sk` bigint(20) NULL COMMENT "",
  `ss_hdemo_sk` bigint(20) NULL COMMENT "",
  `ss_addr_sk` bigint(20) NULL COMMENT "",
  `ss_store_sk` bigint(20) NULL COMMENT "",
  `ss_promo_sk` bigint(20) NULL COMMENT "",
  `ss_quantity` bigint(20) NULL COMMENT "",
  `ss_wholesale_cost` decimal64(7, 2) NULL COMMENT "",
  `ss_list_price` decimal64(7, 2) NULL COMMENT "",
  `ss_sales_price` decimal64(7, 2) NULL COMMENT "",
  `ss_ext_discount_amt` decimal64(7, 2) NULL COMMENT "",
  `ss_ext_sales_price` decimal64(7, 2) NULL COMMENT "",
  `ss_ext_wholesale_cost` decimal64(7, 2) NULL COMMENT "",
  `ss_ext_list_price` decimal64(7, 2) NULL COMMENT "",
  `ss_ext_tax` decimal64(7, 2) NULL COMMENT "",
  `ss_coupon_amt` decimal64(7, 2) NULL COMMENT "",
  `ss_net_paid` decimal64(7, 2) NULL COMMENT "",
  `ss_net_paid_inc_tax` decimal64(7, 2) NULL COMMENT "",
  `ss_net_profit` decimal64(7, 2) NULL COMMENT ""
) ENGINE=OLAP
PRIMARY KEY(`ss_item_sk`, `ss_ticket_number`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`ss_item_sk`, `ss_ticket_number`) BUCKETS 2
PROPERTIES (
"replication_num" = "1",
"in_memory" = "false",
"storage_format" = "DEFAULT",
"enable_persistent_index" = "true",
"compression" = "LZ4"
);
PrimaryKey Length	RowNum	BucketNum	Load time(s)	Apply time(ms)	Peak Memory usage(GB)	Note
16 Bytes	864001869	2	7643	355200	25.03	branch-opt
16 Bytes	864001869	2	7591	348465	46.45	branch-main
16 Bytes	864001869	100	7194	32705	25.11	branch-opt
16 Bytes	864001869	100	7104	30705	43.14	branch-main
Note there are still some scenarios we don't resolve in this pr:

In the partial update, the read column data maybe very large and we don't resolve it in this pr
We still need to load all primary key into L0 of persistent index first which maybe cause OOM
@github-actions
Copy link

clang-tidy review says "All clean, LGTM! 👍"

auto-merge was automatically disabled November 25, 2022 06:37

Head branch was pushed to by a user without write access

@github-actions github-actions bot removed the be-build label Nov 25, 2022
@sevev
Copy link
Contributor Author

sevev commented Nov 25, 2022

run starrocks_be_unittest

@github-actions
Copy link

clang-tidy review says "All clean, LGTM! 👍"

@chaoyli chaoyli changed the title [Enhancement][Cherry-pick][Branch-2.5] Optimize memory usage of primary key table large load (… [Enhancement][Cherry-pick][Branch-2.5] Optimize memory usage of primary key table large load (#12068) Nov 27, 2022
@chaoyli chaoyli merged commit fcc14b2 into StarRocks:branch-2.5 Nov 27, 2022
@github-actions github-actions bot removed the be-build label Nov 27, 2022
@github-actions
Copy link

clang-tidy review says "All clean, LGTM! 👍"

@sonarcloud
Copy link

sonarcloud bot commented Nov 27, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.7% 0.7% Duplication

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

Successfully merging this pull request may close these issues.

3 participants