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

[opt](memory) All LRU Cache inherit from LRUCachePolicy #28940

Merged
merged 11 commits into from
Dec 29, 2023

Conversation

xinyiZzz
Copy link
Contributor

@xinyiZzz xinyiZzz commented Dec 24, 2023

Proposed changes

  1. After all LRU Cache inherits from LRUCachePolicy, this will allow prune stale entry, eviction when memory exceeds limit, and define common properties. LRUCache constructor change to private, only allow LRUCachePolicy to construct it.

  2. Impl DummyLRUCache, when LRU Cache capacity is 0, will no longer be meaningless insert and evict.

Further comments

If this is a relatively large or complex change, kick off the discussion at [email protected] by explaining why you chose the solution you did and what alternatives you considered, etc...

@xinyiZzz
Copy link
Contributor Author

run buildall

Copy link
Contributor

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

@doris-robot
Copy link

TPC-H test result on machine: 'aliyun_ecs.c7a.8xlarge_32C64G'

Tpch sf100 test result on commit 7a845e87dda8d2f1058f77b5ddbb4df5df4dec72, data reload: false

run tpch-sf100 query with default conf and session variables
q1	4723	4408	4438	4408
q2	369	146	159	146
q3	1465	1259	1287	1259
q4	1103	886	861	861
q5	3170	3145	3165	3145
q6	252	135	133	133
q7	988	495	491	491
q8	2210	2224	2213	2213
q9	6701	6640	6655	6640
q10	3221	3258	3252	3252
q11	308	190	192	190
q12	353	206	212	206
q13	4555	3831	3815	3815
q14	247	213	214	213
q15	575	525	527	525
q16	441	392	392	392
q17	988	614	538	538
q18	7122	6726	8019	6726
q19	1535	1441	1472	1441
q20	529	328	295	295
q21	3064	2673	2651	2651
q22	347	279	287	279
Total cold run time: 44266 ms
Total hot run time: 39819 ms

run tpch-sf100 query with default conf and set session variable runtime_filter_mode=off
q1	4332	4336	4332	4332
q2	273	167	174	167
q3	3508	3501	3488	3488
q4	2397	2373	2386	2373
q5	5731	5751	5737	5737
q6	245	125	123	123
q7	2364	1872	1850	1850
q8	3539	3537	3524	3524
q9	9066	9019	9027	9019
q10	3914	4024	4021	4021
q11	496	370	362	362
q12	765	600	585	585
q13	4299	3519	3543	3519
q14	296	261	255	255
q15	581	510	514	510
q16	501	445	449	445
q17	1907	1880	1860	1860
q18	8450	8058	8063	8058
q19	1774	1782	1760	1760
q20	2262	1956	1941	1941
q21	6508	6173	6172	6172
q22	492	418	420	418
Total cold run time: 63700 ms
Total hot run time: 60519 ms

@doris-robot
Copy link

(From new machine)TeamCity pipeline, clickbench performance test result:
the sum of best hot time: 44.28 seconds
stream load tsv: 577 seconds loaded 74807831229 Bytes, about 123 MB/s
stream load json: 19 seconds loaded 2358488459 Bytes, about 118 MB/s
stream load orc: 66 seconds loaded 1101869774 Bytes, about 15 MB/s
stream load parquet: 32 seconds loaded 861443392 Bytes, about 25 MB/s
insert into select: 28.3 seconds inserted 10000000 Rows, about 353K ops/s
storage size: 17184023863 Bytes

@xinyiZzz
Copy link
Contributor Author

run buildall

Copy link
Contributor

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

@xinyiZzz
Copy link
Contributor Author

run buildall

Copy link
Contributor

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

@doris-robot
Copy link

TeamCity be ut coverage result:
Function Coverage: 36.59% (8560/23394)
Line Coverage: 28.66% (69594/242810)
Region Coverage: 27.66% (35993/130105)
Branch Coverage: 24.40% (18406/75434)
Coverage Report: http://coverage.selectdb-in.cc/coverage/112cd8fd7b82e1257df1b3b1d956d54e8afc6cfb_112cd8fd7b82e1257df1b3b1d956d54e8afc6cfb/report/index.html

@doris-robot
Copy link

TPC-H test result on machine: 'aliyun_ecs.c7a.8xlarge_32C64G'

Tpch sf100 test result on commit 112cd8fd7b82e1257df1b3b1d956d54e8afc6cfb, data reload: false

run tpch-sf100 query with default conf and session variables
q1	4669	4396	4399	4396
q2	371	145	158	145
q3	1449	1274	1249	1249
q4	1118	887	922	887
q5	3155	3169	3167	3167
q6	251	133	132	132
q7	989	487	493	487
q8	2199	2216	2198	2198
q9	6724	6685	6644	6644
q10	3223	3281	3269	3269
q11	305	183	197	183
q12	351	207	206	206
q13	4570	3803	3793	3793
q14	244	215	211	211
q15	575	519	524	519
q16	436	386	377	377
q17	1009	665	545	545
q18	7007	6752	6794	6752
q19	1521	1398	1466	1398
q20	517	300	283	283
q21	3069	2610	2637	2610
q22	347	275	281	275
Total cold run time: 44099 ms
Total hot run time: 39726 ms

run tpch-sf100 query with default conf and set session variable runtime_filter_mode=off
q1	4375	4322	4342	4322
q2	307	165	167	165
q3	3515	3498	3504	3498
q4	2393	2360	2378	2360
q5	5725	5703	5720	5703
q6	242	126	124	124
q7	2365	1862	1864	1862
q8	3530	3529	3521	3521
q9	9025	8973	8964	8964
q10	3914	4011	4022	4011
q11	482	369	377	369
q12	765	606	591	591
q13	4273	3543	3536	3536
q14	284	255	263	255
q15	569	521	521	521
q16	488	464	449	449
q17	1874	1854	1833	1833
q18	8539	8183	8154	8154
q19	1730	1739	1756	1739
q20	2274	1955	1937	1937
q21	6477	6145	6134	6134
q22	495	429	443	429
Total cold run time: 63641 ms
Total hot run time: 60477 ms

@doris-robot
Copy link

(From new machine)TeamCity pipeline, clickbench performance test result:
the sum of best hot time: 44.3 seconds
stream load tsv: 577 seconds loaded 74807831229 Bytes, about 123 MB/s
stream load json: 19 seconds loaded 2358488459 Bytes, about 118 MB/s
stream load orc: 66 seconds loaded 1101869774 Bytes, about 15 MB/s
stream load parquet: 32 seconds loaded 861443392 Bytes, about 25 MB/s
insert into select: 28.7 seconds inserted 10000000 Rows, about 348K ops/s
storage size: 17184050921 Bytes

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

be/src/olap/lru_cache.h Show resolved Hide resolved
be/src/runtime/memory/lru_cache_policy.h Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

be/src/olap/lru_cache.cpp Show resolved Hide resolved
be/src/runtime/memory/lru_cache_policy.h Show resolved Hide resolved
@xinyiZzz
Copy link
Contributor Author

run buildall

be/src/olap/lru_cache.cpp Outdated Show resolved Hide resolved
be/src/olap/lru_cache.cpp Outdated Show resolved Hide resolved
@xinyiZzz
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

TeamCity be ut coverage result:
Function Coverage: 36.58% (8597/23499)
Line Coverage: 28.67% (69897/243792)
Region Coverage: 27.66% (36164/130724)
Branch Coverage: 24.39% (18488/75800)
Coverage Report: http://coverage.selectdb-in.cc/coverage/a49d9fe41c0f1d1e59637e41d115258d83f55209_a49d9fe41c0f1d1e59637e41d115258d83f55209/report/index.html

init(capacity, lru_cache_type, num_shards);
}

bool prepare(size_t capacity, uint32_t num_shards) {
Copy link
Contributor

Choose a reason for hiding this comment

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

prepare 和 init 实际是相同的意思。
这个函数,你实现的实际就是check。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

em。。因为把 check init 和 init = true 也加进来了,所以改叫 prepare

_enable_prune = false;
return false;
}
_is_init = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

为啥在prepare 里更新 is_init=true? 而不是在init里? 这yang很混乱。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

因为三个 init 方法要写三次啊 = =

@@ -177,20 +177,20 @@ class StoragePageCache {
Cache* _get_page_cache(segment_v2::PageTypePB page_type) {
switch (page_type) {
case segment_v2::DATA_PAGE: {
if (_data_page_cache) {
return _data_page_cache->get();
if (_data_page_cache->is_init()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

这里为啥要检查 is init?直接返回不行吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

上面有个 is_available 方法检查了 nullptr,用于短路 page cache 的使用,而 _data_page_cache->get() 不会返回nullptr

已修改,把 is_available 和 is_init 都删了,不需要短路了

return _cache.get();
}

void reset() { _cache.reset(); }
Copy link
Contributor

Choose a reason for hiding this comment

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

这个函数有用么?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

没用了,已删

@doris-robot
Copy link

(From new machine)TeamCity pipeline, clickbench performance test result:
the sum of best hot time: 47.39 seconds
stream load tsv: 563 seconds loaded 74807831229 Bytes, about 126 MB/s
stream load json: 19 seconds loaded 2358488459 Bytes, about 118 MB/s
stream load orc: 66 seconds loaded 1101869774 Bytes, about 15 MB/s
stream load parquet: 32 seconds loaded 861443392 Bytes, about 25 MB/s
insert into select: 28.7 seconds inserted 10000000 Rows, about 348K ops/s
storage size: 17183829705 Bytes

@doris-robot
Copy link

TPC-H test result on machine: 'aliyun_ecs.c7a.8xlarge_32C64G'

Tpch sf100 test result on commit a49d9fe41c0f1d1e59637e41d115258d83f55209, data reload: false

run tpch-sf100 query with default conf and session variables
q1	5012	4664	4693	4664
q2	367	147	159	147
q3	1473	1303	1193	1193
q4	1152	977	902	902
q5	3181	3172	3183	3172
q6	255	129	130	129
q7	1039	505	498	498
q8	2283	2269	2257	2257
q9	6727	6699	6681	6681
q10	3187	3271	3268	3268
q11	336	203	208	203
q12	355	209	217	209
q13	4192	3432	3424	3424
q14	243	215	218	215
q15	570	524	524	524
q16	440	391	395	391
q17	1042	812	581	581
q18	7147	6901	6824	6824
q19	1641	1643	1641	1641
q20	523	288	299	288
q21	3209	2749	2735	2735
q22	363	296	309	296
Total cold run time: 44737 ms
Total hot run time: 40242 ms

run tpch-sf100 query with default conf and set session variable runtime_filter_mode=off
q1	4565	4604	4583	4583
q2	277	167	173	167
q3	3378	3369	3367	3367
q4	2245	2212	2212	2212
q5	5739	5722	5710	5710
q6	240	120	122	120
q7	2373	1854	1853	1853
q8	3627	3635	3621	3621
q9	9009	8980	8919	8919
q10	3825	3895	3900	3895
q11	493	356	381	356
q12	771	630	604	604
q13	3891	3216	3190	3190
q14	297	265	259	259
q15	569	514	515	514
q16	519	448	452	448
q17	1977	1950	1970	1950
q18	8589	8249	8286	8249
q19	1761	1748	1776	1748
q20	2251	1932	1934	1932
q21	6131	5752	5778	5752
q22	547	480	444	444
Total cold run time: 63074 ms
Total hot run time: 59893 ms

@xinyiZzz
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

TPC-H test result on machine: 'aliyun_ecs.c7a.8xlarge_32C64G'

Tpch sf100 test result on commit a63ee593a20d3df972803ac0ad8c3870095f3859, data reload: false

run tpch-sf100 query with default conf and session variables
q1	5480	5140	5230	5140
q2	406	180	158	158
q3	1537	1180	1196	1180
q4	1108	888	828	828
q5	3085	3013	3090	3013
q6	233	147	138	138
q7	976	575	542	542
q8	2143	2276	2283	2276
q9	6885	6872	6865	6865
q10	3198	3176	3148	3148
q11	360	234	220	220
q12	395	243	240	240
q13	4391	3636	3629	3629
q14	254	227	227	227
q15	632	572	568	568
q16	477	418	395	395
q17	1057	559	596	559
q18	7040	6823	6753	6753
q19	1646	1579	1588	1579
q20	574	427	337	337
q21	2931	2494	2484	2484
q22	394	309	310	309
Total cold run time: 45202 ms
Total hot run time: 40588 ms

run tpch-sf100 query with default conf and set session variable runtime_filter_mode=off
q1	5135	5116	5037	5037
q2	339	256	265	256
q3	3368	3302	3300	3300
q4	2197	2011	2020	2011
q5	5949	5926	5878	5878
q6	235	132	133	132
q7	2414	1943	1926	1926
q8	3561	3628	3653	3628
q9	9074	9042	9031	9031
q10	3880	3926	3933	3926
q11	567	491	465	465
q12	803	637	650	637
q13	3877	3208	3191	3191
q14	293	274	274	274
q15	617	555	570	555
q16	544	501	517	501
q17	2038	1817	1801	1801
q18	8782	8328	8348	8328
q19	1753	1727	1736	1727
q20	2260	2023	1986	1986
q21	5719	5322	5308	5308
q22	566	516	503	503
Total cold run time: 63971 ms
Total hot run time: 60401 ms

@xinyiZzz
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

TPC-H test result on machine: 'aliyun_ecs.c7a.8xlarge_32C64G'

Tpch sf100 test result on commit 2fb285d701a8168e58701d3ec398f498eeedc96c, data reload: false

run tpch-sf100 query with default conf and session variables
q1	5435	5196	5188	5188
q2	407	187	198	187
q3	1454	1167	1141	1141
q4	1086	851	787	787
q5	3121	3110	3112	3110
q6	234	141	137	137
q7	958	560	555	555
q8	2138	2260	2204	2204
q9	6848	6843	6826	6826
q10	3187	3152	3131	3131
q11	347	213	231	213
q12	393	243	246	243
q13	4409	3647	3620	3620
q14	258	230	217	217
q15	641	565	577	565
q16	461	425	414	414
q17	1042	594	545	545
q18	7071	6842	6902	6842
q19	1637	1538	1582	1538
q20	607	359	375	359
q21	2893	2475	2500	2475
q22	383	332	310	310
Total cold run time: 45010 ms
Total hot run time: 40607 ms

run tpch-sf100 query with default conf and set session variable runtime_filter_mode=off
q1	5116	5103	5078	5078
q2	346	264	259	259
q3	3358	3300	3281	3281
q4	2182	2077	2060	2060
q5	5944	5917	5887	5887
q6	238	131	132	131
q7	2399	1927	1902	1902
q8	3524	3649	3639	3639
q9	9087	9071	9013	9013
q10	3879	3913	3941	3913
q11	574	473	491	473
q12	809	615	631	615
q13	3851	3219	3214	3214
q14	313	279	265	265
q15	617	547	573	547
q16	580	537	528	528
q17	2023	1831	1768	1768
q18	8742	8369	8400	8369
q19	1764	1698	1721	1698
q20	2304	1997	1993	1993
q21	5724	5429	5286	5286
q22	572	456	515	456
Total cold run time: 63946 ms
Total hot run time: 60375 ms

@doris-robot
Copy link

(From new machine)TeamCity pipeline, clickbench performance test result:
the sum of best hot time: 47.79 seconds
stream load tsv: 582 seconds loaded 74807831229 Bytes, about 122 MB/s
stream load json: 19 seconds loaded 2358488459 Bytes, about 118 MB/s
stream load orc: 66 seconds loaded 1101869774 Bytes, about 15 MB/s
stream load parquet: 33 seconds loaded 861443392 Bytes, about 24 MB/s
insert into select: 28.9 seconds inserted 10000000 Rows, about 346K ops/s
storage size: 17183598894 Bytes

@xinyiZzz
Copy link
Contributor Author

run buildall

@xinyiZzz
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

TeamCity be ut coverage result:
Function Coverage: 36.60% (8602/23500)
Line Coverage: 28.67% (69920/243921)
Region Coverage: 27.66% (36181/130802)
Branch Coverage: 24.38% (18499/75870)
Coverage Report: http://coverage.selectdb-in.cc/coverage/76f1e790205f6f56833b5388ae8fbee6b405cb68_76f1e790205f6f56833b5388ae8fbee6b405cb68/report/index.html

Copy link
Contributor

@yiguolei yiguolei left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

PR approved by at least one committer and no changes requested.

@github-actions github-actions bot added approved Indicates a PR has been approved by one committer. reviewed labels Dec 29, 2023
Copy link
Contributor

PR approved by anyone and no changes requested.

@doris-robot
Copy link

TPC-H test result on machine: 'aliyun_ecs.c7a.8xlarge_32C64G'

Tpch sf100 test result on commit 76f1e790205f6f56833b5388ae8fbee6b405cb68, data reload: false

run tpch-sf100 query with default conf and session variables
q1	5437	5193	5172	5172
q2	399	176	156	156
q3	1473	1231	1191	1191
q4	1083	853	774	774
q5	3137	3121	3149	3121
q6	232	144	138	138
q7	988	580	539	539
q8	2147	2222	2208	2208
q9	6699	6672	6666	6666
q10	3197	3113	3138	3113
q11	336	227	235	227
q12	396	241	243	241
q13	4391	3675	3662	3662
q14	261	215	217	215
q15	618	572	587	572
q16	462	407	404	404
q17	1046	540	567	540
q18	7096	6774	6796	6774
q19	1643	1550	1559	1550
q20	617	351	375	351
q21	2887	2492	2518	2492
q22	378	310	323	310
Total cold run time: 44923 ms
Total hot run time: 40416 ms

run tpch-sf100 query with default conf and set session variable runtime_filter_mode=off
q1	5111	5088	5036	5036
q2	336	269	254	254
q3	3346	3277	3244	3244
q4	2168	1997	2031	1997
q5	5916	5935	5950	5935
q6	235	131	132	131
q7	2384	1966	1996	1966
q8	3542	3641	3651	3641
q9	9046	8992	8974	8974
q10	3868	3927	3921	3921
q11	594	492	481	481
q12	794	644	649	644
q13	3878	3220	3185	3185
q14	291	257	258	257
q15	629	582	565	565
q16	548	544	541	541
q17	2033	1824	1830	1824
q18	8708	8406	8349	8349
q19	1769	1698	1712	1698
q20	2307	2005	1988	1988
q21	5724	5361	5347	5347
q22	576	495	502	495
Total cold run time: 63803 ms
Total hot run time: 60473 ms

@doris-robot
Copy link

(From new machine)TeamCity pipeline, clickbench performance test result:
the sum of best hot time: 47.15 seconds
stream load tsv: 577 seconds loaded 74807831229 Bytes, about 123 MB/s
stream load json: 19 seconds loaded 2358488459 Bytes, about 118 MB/s
stream load orc: 66 seconds loaded 1101869774 Bytes, about 15 MB/s
stream load parquet: 32 seconds loaded 861443392 Bytes, about 25 MB/s
insert into select: 28.4 seconds inserted 10000000 Rows, about 352K ops/s
storage size: 17184269125 Bytes

Copy link
Contributor

@zhiqiang-hhhh zhiqiang-hhhh left a comment

Choose a reason for hiding this comment

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

LGTM

@yiguolei yiguolei merged commit 82635d4 into apache:master Dec 29, 2023
25 of 28 checks passed
HappenLee pushed a commit to HappenLee/incubator-doris that referenced this pull request Jan 12, 2024
After all LRU Cache inherits from LRUCachePolicy, this will allow prune stale entry, eviction when memory exceeds limit, and define common properties. LRUCache constructor change to private, only allow LRUCachePolicy to construct it.

Impl DummyLRUCache, when LRU Cache capacity is 0, will no longer be meaningless insert and evict.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by one committer. reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants