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

[WIP](segment) Segment footer PB cache #48924

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

zhiqiang-hhhh
Copy link
Contributor

NED

What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary:

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

@Thearas
Copy link
Contributor

Thearas commented Mar 11, 2025

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@zhiqiang-hhhh
Copy link
Contributor Author

run buildall

2 similar comments
@zhiqiang-hhhh
Copy link
Contributor Author

run buildall

@zhiqiang-hhhh
Copy link
Contributor Author

run buildall

// Do load if not found in cache.
// Return nullptr if load failed.
// Return non-null pointer if load success.
std::shared_ptr<segment_v2::SegmentFooterPB> get_or_load(StoragePageCache::CacheKey cache_key,
Copy link
Contributor

Choose a reason for hiding this comment

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

方法名字跟所有的cache 保持一致, insert, lookup

std::shared_ptr<segment_v2::SegmentFooterPB> _load_and_update() {
std::shared_ptr<segment_v2::SegmentFooterPB> footer =
std::make_shared<segment_v2::SegmentFooterPB>();
Status load_status = _load_function(footer);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

不要这么写。 在cloud 上,我们同步的确保只有一个线程去load 可能是不对的,比如他访问s3 不稳定之类的。反而我们多个线程同时加载,谁成功用谁的,可以避免多个query 之间互相干扰。

我感觉没必要,如果file cache miss了,那这里并不并发已经没意义了,而且访问 S3 的并发控制应该是File Cache负责的,我们这里考虑本地 file cache 命中的情况。

@@ -230,6 +230,7 @@ class DorisMetrics {
IntCounter* scanner_ctx_cnt = nullptr;
IntCounter* scanner_cnt = nullptr;
IntCounter* scanner_task_cnt = nullptr;
IntCounter* column_reader_cnt = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

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

不需要加这个,之前有一个bvar 解决这个问题。
当前,我们已经去不掉bvar了,后面我们想办法把bvar 通过doris metric 这个接口暴露出去就行了。

*/

class SegmentFooterDataPage : public PageBase<Allocator<false>> {
// Need to implement some virtual methods.
Copy link
Contributor

Choose a reason for hiding this comment

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

这么写应该是不够的。
比如说我们没有更新size 这些东东,此时会发现page cache 实际用了很多内存,但是从memtracker 上看用的内存又不多。
得看看page base 里的实现

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这么写应该是不够的。 比如说我们没有更新size 这些东东,此时会发现page cache 实际用了很多内存,但是从memtracker 上看用的内存又不多。 得看看page base 里的实现

size 跟 capacity 都更新了的,在 load_and_update 里面

@zhiqiang-hhhh
Copy link
Contributor Author

run buildall

1 similar comment
@zhiqiang-hhhh
Copy link
Contributor Author

run buildall

template <typename TAllocator>
class PageBase : private TAllocator, public LRUCacheValueBase {
template <typename TAllocator, typename T>
class MemoryTrackedPageBase : protected TAllocator, public LRUCacheValueBase {
Copy link
Contributor

Choose a reason for hiding this comment

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

这个类,为什么需要有Allocator 这个模板参数?

Slice data() const;

template <typename T>
T as() const {
Copy link
Contributor

Choose a reason for hiding this comment

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

用get 不要用as, as 一般表示吧当前this 转换为某个类型


footer_pb_page->set_data(footer_pb_shared);

segment_footer_cache->insert(cache_key, (void*)(footer_pb_page.get()),
Copy link
Contributor

Choose a reason for hiding this comment

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

我觉得你这个传入 void*, 但是get 出来是shared ptr 我不好说哪个好。
你看如果我们直接能传递一个shared ptr 进去,那么1216 行和1222 行就是一行代码。
而且,从用户角度看,他传入的是一个shared ptr,拿出来的也是一个shared ptr,这样也会比较一致。

Copy link
Contributor

Choose a reason for hiding this comment

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

而且你这个写法,得外部感知到MemoryTrackedPageWithPagePtr,实际这个东东外面不需要感知,外部感知的应该只有一个他自己的footer 对象。 这个MemoryTrackedPageWithPagePtr类是我们内部自己需要导致的一个wrapper 对象。


footer_pb_page->set_data(footer_pb_shared);

segment_footer_cache->insert(cache_key, (void*)(footer_pb_page.get()),
Copy link
Contributor

Choose a reason for hiding this comment

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

insert(param1, std::shared_ptr param2)

@zhiqiang-hhhh
Copy link
Contributor Author

run buildall

@zhiqiang-hhhh
Copy link
Contributor Author

run buildall

@zhiqiang-hhhh
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

TPC-H: Total hot run time: 32930 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit c26d2689e3286de7cf83e0cff2efab247964399f, data reload: false

------ Round 1 ----------------------------------
q1	17628	5200	5180	5180
q2	2055	302	160	160
q3	10402	1265	758	758
q4	10196	1021	537	537
q5	7528	2432	2356	2356
q6	193	168	135	135
q7	940	766	625	625
q8	9326	1306	1203	1203
q9	5002	4844	4756	4756
q10	6841	2322	1887	1887
q11	502	277	265	265
q12	344	346	214	214
q13	17763	3718	3105	3105
q14	228	222	217	217
q15	530	493	480	480
q16	639	619	600	600
q17	586	884	354	354
q18	6899	6555	6393	6393
q19	1221	978	572	572
q20	308	335	200	200
q21	2785	2140	1946	1946
q22	1063	1028	987	987
Total cold run time: 102979 ms
Total hot run time: 32930 ms

----- Round 2, with runtime_filter_mode=off -----
q1	5166	5122	5159	5122
q2	238	331	230	230
q3	2185	2738	2369	2369
q4	1458	1846	1358	1358
q5	4275	4161	4162	4161
q6	211	167	125	125
q7	1904	1932	1806	1806
q8	2655	2595	2534	2534
q9	7457	7268	7243	7243
q10	3081	3223	2774	2774
q11	573	512	491	491
q12	671	716	570	570
q13	3568	3949	3289	3289
q14	295	291	290	290
q15	541	480	492	480
q16	673	699	650	650
q17	1176	1623	1367	1367
q18	7863	7575	7427	7427
q19	839	900	939	900
q20	1966	2090	1896	1896
q21	5479	4995	4729	4729
q22	1117	1137	1059	1059
Total cold run time: 53391 ms
Total hot run time: 50870 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 191969 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit c26d2689e3286de7cf83e0cff2efab247964399f, data reload: false

query1	1410	1009	979	979
query2	6202	1924	1872	1872
query3	11086	4661	4416	4416
query4	53504	25643	23163	23163
query5	5261	585	496	496
query6	384	201	205	201
query7	5116	499	288	288
query8	330	245	235	235
query9	6455	2625	2628	2625
query10	429	310	247	247
query11	15284	15079	14954	14954
query12	154	112	103	103
query13	1164	524	411	411
query14	10202	6739	6848	6739
query15	199	216	181	181
query16	7017	665	493	493
query17	1059	697	561	561
query18	1497	406	314	314
query19	210	190	156	156
query20	130	118	121	118
query21	206	125	102	102
query22	4594	4633	4362	4362
query23	34166	33262	33554	33262
query24	5702	2434	2472	2434
query25	450	444	394	394
query26	654	274	155	155
query27	1714	500	344	344
query28	2782	2462	2477	2462
query29	559	569	437	437
query30	282	223	195	195
query31	892	880	816	816
query32	77	70	65	65
query33	474	386	323	323
query34	759	882	502	502
query35	800	854	762	762
query36	966	1042	907	907
query37	123	108	81	81
query38	4227	4274	4139	4139
query39	1509	1444	1475	1444
query40	207	129	110	110
query41	60	57	56	56
query42	133	118	107	107
query43	504	516	501	501
query44	1370	817	822	817
query45	186	181	174	174
query46	866	1058	649	649
query47	1878	1898	1879	1879
query48	391	440	314	314
query49	720	510	424	424
query50	703	751	417	417
query51	4229	4379	4183	4183
query52	104	102	97	97
query53	257	283	189	189
query54	474	493	410	410
query55	86	83	85	83
query56	272	284	264	264
query57	1177	1175	1104	1104
query58	250	243	242	242
query59	2663	2906	2670	2670
query60	288	273	276	273
query61	124	120	120	120
query62	750	780	689	689
query63	226	187	191	187
query64	1420	1034	766	766
query65	4651	4475	4319	4319
query66	765	423	293	293
query67	15977	15555	15330	15330
query68	7838	824	495	495
query69	525	292	262	262
query70	1242	1119	1104	1104
query71	498	282	264	264
query72	5539	3544	3782	3544
query73	1286	721	346	346
query74	9029	8915	9069	8915
query75	3910	3166	2679	2679
query76	4363	1198	760	760
query77	613	368	275	275
query78	10088	10071	9199	9199
query79	2536	828	589	589
query80	652	514	445	445
query81	480	253	220	220
query82	669	123	91	91
query83	297	167	155	155
query84	283	92	72	72
query85	785	352	307	307
query86	352	316	289	289
query87	4494	4473	4448	4448
query88	3194	2293	2284	2284
query89	420	319	276	276
query90	1948	220	217	217
query91	142	149	111	111
query92	79	55	55	55
query93	1242	1062	584	584
query94	695	423	311	311
query95	353	270	267	267
query96	486	556	281	281
query97	3371	3396	3288	3288
query98	217	210	193	193
query99	1419	1366	1238	1238
Total cold run time: 297805 ms
Total hot run time: 191969 ms

@doris-robot
Copy link

ClickBench: Total hot run time: 31.56 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit c26d2689e3286de7cf83e0cff2efab247964399f, data reload: false

query1	0.04	0.03	0.04
query2	0.07	0.04	0.03
query3	0.24	0.06	0.06
query4	1.62	0.11	0.11
query5	0.59	0.54	0.54
query6	1.22	0.71	0.73
query7	0.03	0.02	0.01
query8	0.04	0.03	0.03
query9	0.58	0.52	0.50
query10	0.58	0.59	0.57
query11	0.16	0.11	0.11
query12	0.14	0.12	0.11
query13	0.61	0.60	0.59
query14	2.71	2.69	2.74
query15	0.92	0.86	0.85
query16	0.38	0.37	0.37
query17	1.04	1.03	1.04
query18	0.22	0.19	0.19
query19	1.85	1.84	1.98
query20	0.01	0.02	0.01
query21	15.36	0.91	0.56
query22	0.75	1.27	0.85
query23	14.71	1.41	0.63
query24	6.82	1.21	1.22
query25	0.47	0.31	0.11
query26	0.60	0.16	0.13
query27	0.05	0.04	0.05
query28	9.44	0.86	0.42
query29	12.56	4.09	3.36
query30	0.25	0.09	0.06
query31	2.82	0.59	0.40
query32	3.23	0.56	0.47
query33	3.03	3.00	3.09
query34	15.74	5.15	4.57
query35	4.59	4.59	4.58
query36	0.66	0.50	0.47
query37	0.11	0.07	0.08
query38	0.05	0.04	0.04
query39	0.03	0.02	0.03
query40	0.18	0.14	0.12
query41	0.08	0.03	0.02
query42	0.03	0.02	0.03
query43	0.03	0.03	0.03
Total cold run time: 104.64 s
Total hot run time: 31.56 s

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.

4 participants