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](profile) Store profile on disk so that we can hold more profile in memory #33690

Merged
merged 85 commits into from
Jul 26, 2024

Conversation

zhiqiang-hhhh
Copy link
Contributor

@zhiqiang-hhhh zhiqiang-hhhh commented Apr 16, 2024

Step 3 of #33744

Store profile on disk of FE, in the same path with audit log.

  1. ProfileManager will have a daemon thread that checks whether a profile should be stored on disk
  2. Which profile can be stored?
    a. query finished.
    b. collection of profile has finished or query itself has finished for a long time, like 5 seconds
  3. Profile structure on disk:
* Integer: n(size of summary profile)
* String: json of summary profile
* Integer: m(size of compressed execution profile)
* String: compressed binary of execution profile
  1. IO thread of ProfileManager will also remove garbage from disk.
  2. Once a profile is stored to disk, its detail content will be release from memory, so that we can hold more profiles in memory, further access to profile will read from disk directly.
  3. Basic but necessary UT for profile serialization.
  4. Refine constructor of ExecutionProfile.

Further work:

  1. Abstract class ProfileReader/ProfileWriter, they define common interface for profile io, and we can implement ProfileDiskReader/ProfileDiskWriter and also ProfileS3Reader/ProfileS3Writer to support profile io on object storage.
  2. Finer granularity for profile creation. Currently for ddl like create/drop table, profile is also created, this is unnecessary.
  3. More regression test.
  4. More reasonable default value of max_profile_on_disk.
  5. system table for profile storage, so that we can figure out how much storage is costed for profile

@doris-robot
Copy link

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

Since 2024-03-18, the Document has been moved to doris-website.
See Doris Document.

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/runtime/fragment_mgr.cpp Outdated Show resolved Hide resolved
be/src/runtime/fragment_mgr.h Outdated Show resolved Hide resolved
be/src/runtime/plan_fragment_executor.cpp Outdated Show resolved Hide resolved
be/src/runtime/plan_fragment_executor.cpp Outdated Show resolved Hide resolved
be/src/runtime/plan_fragment_executor.h Outdated Show resolved Hide resolved
be/src/runtime/runtime_query_statistics_mgr.cpp Outdated Show resolved Hide resolved
be/src/runtime/runtime_query_statistics_mgr.cpp Outdated Show resolved Hide resolved
be/src/runtime/runtime_query_statistics_mgr.h Outdated Show resolved Hide resolved
be/src/service/backend_service.cpp Outdated Show resolved Hide resolved
be/src/service/backend_service.cpp Outdated Show resolved Hide resolved
private static final Logger LOG = LogManager.getLogger(ProfileManager.class);
private static volatile ProfileManager INSTANCE = null;
private static final String PROFILE_STORAGE_PATH = Config.audit_log_dir + File.separator + "profile";
Copy link
Contributor

Choose a reason for hiding this comment

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

这里默认值可以是这个,但是应该有单独的配置项,来单独设置profile 的存储路径,如果设置了,那么就不应该用这个默认的路径了

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -2694,6 +2694,10 @@ public class Config extends ConfigBase {
@ConfField(mutable = true)
public static boolean enable_cooldown_replica_affinity = true;

// The max number of profiles that can be stored to storage.
@ConfField
public static int max_spilled_profile_num = 500;
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

@zhiqiang-hhhh zhiqiang-hhhh Jul 24, 2024

Choose a reason for hiding this comment

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

个数限制 + 磁盘大小可能都得需要,个数限制防止产生大量小文件。我们后台有很多 select @@version_comment limit 1 类似这样的查询。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

readLock.lock();
try {
ExecutionProfile execProfile = queryIdToExecutionProfiles.get(queryId);
if (execProfile == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

一个profile 对应多个execution profile,这里不要从profilemanager 里读取了,直接profile
对象里就包含多个execution profile,直接都设置了吧

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里拿不到 Profile 对象,入参是 TUniqueId,只能对应 ExecutionProfile

@@ -167,18 +167,13 @@ public void unregisterQuery(TUniqueId queryId) {
if (LOG.isDebugEnabled()) {
LOG.debug("Deregister query id {}", DebugUtil.printId(queryId));
}
ExecutionProfile executionProfile = ProfileManager.getInstance().getExecutionProfile(queryId);
if (executionProfile != null) {
executionProfile.setQueryFinishTime(System.currentTimeMillis());
Copy link
Contributor

Choose a reason for hiding this comment

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

为什么要动这里,这里只跟cood 有关,跟profile 本身不相关。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

逻辑没变,只是把对 ExecutionProfile 的操作都通过 ProfileManager 去做了

@zhiqiang-hhhh
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	18777	4464	4346	4346
q2	2013	191	187	187
q3	10467	1156	1108	1108
q4	10183	838	806	806
q5	7552	2695	2640	2640
q6	221	143	142	142
q7	947	602	606	602
q8	9215	2074	2109	2074
q9	8759	6553	6534	6534
q10	8660	3817	3771	3771
q11	453	223	239	223
q12	400	227	229	227
q13	17775	2978	2983	2978
q14	277	234	235	234
q15	523	470	479	470
q16	474	403	372	372
q17	974	715	625	625
q18	8047	7530	7536	7530
q19	9055	1423	1406	1406
q20	719	305	328	305
q21	4947	3205	3308	3205
q22	342	291	280	280
Total cold run time: 120780 ms
Total hot run time: 40065 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4400	4283	4298	4283
q2	379	278	278	278
q3	3058	2827	2780	2780
q4	1904	1548	1606	1548
q5	5306	5325	5316	5316
q6	241	131	132	131
q7	2128	1709	1750	1709
q8	3203	3370	3322	3322
q9	8487	8422	8432	8422
q10	3948	3727	3727	3727
q11	616	482	493	482
q12	787	591	600	591
q13	16341	3014	2990	2990
q14	305	258	266	258
q15	535	481	476	476
q16	464	416	442	416
q17	1790	1523	1494	1494
q18	7631	7509	7309	7309
q19	1669	1638	1505	1505
q20	2043	1791	1769	1769
q21	4987	4765	4690	4690
q22	570	477	525	477
Total cold run time: 70792 ms
Total hot run time: 53973 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 172883 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 dbd54912a5dfe24bb2196831bbd44fa0860d93cf, data reload: false

query1	912	368	373	368
query2	6443	1981	1966	1966
query3	6670	206	220	206
query4	27616	17688	17089	17089
query5	4200	477	470	470
query6	278	181	184	181
query7	4596	291	284	284
query8	241	203	201	201
query9	8535	2449	2398	2398
query10	439	282	291	282
query11	11470	10009	10144	10009
query12	148	89	84	84
query13	1664	380	367	367
query14	10201	7294	7779	7294
query15	217	169	167	167
query16	7727	493	485	485
query17	1608	590	552	552
query18	1778	288	291	288
query19	201	158	165	158
query20	97	83	83	83
query21	208	136	123	123
query22	4242	4067	3942	3942
query23	33969	33081	32972	32972
query24	12065	2924	2868	2868
query25	671	387	421	387
query26	1851	154	152	152
query27	2976	279	280	279
query28	7453	2037	2012	2012
query29	1132	644	636	636
query30	290	148	151	148
query31	959	722	761	722
query32	102	54	64	54
query33	792	425	330	330
query34	908	483	494	483
query35	857	749	736	736
query36	1110	937	934	934
query37	277	78	80	78
query38	2927	2764	2731	2731
query39	883	803	811	803
query40	269	124	115	115
query41	47	45	45	45
query42	132	99	101	99
query43	536	467	489	467
query44	1275	728	741	728
query45	202	178	170	170
query46	1082	708	710	708
query47	1846	1754	1773	1754
query48	364	295	287	287
query49	1214	415	417	415
query50	781	392	389	389
query51	6753	6668	6611	6611
query52	100	94	91	91
query53	355	287	297	287
query54	983	446	443	443
query55	73	75	73	73
query56	287	268	282	268
query57	1181	1081	1073	1073
query58	272	250	266	250
query59	2881	2874	2617	2617
query60	289	281	268	268
query61	99	93	93	93
query62	838	649	663	649
query63	331	301	293	293
query64	10496	2204	1685	1685
query65	3153	3112	3110	3110
query66	1345	338	349	338
query67	15595	15005	15044	15005
query68	5397	549	542	542
query69	722	436	356	356
query70	1170	1108	1114	1108
query71	507	279	282	279
query72	8967	5825	6120	5825
query73	783	328	329	328
query74	6247	5631	5613	5613
query75	4527	2699	2689	2689
query76	4059	1007	905	905
query77	735	319	318	318
query78	9710	9194	8967	8967
query79	3933	528	531	528
query80	2542	478	476	476
query81	593	222	220	220
query82	1301	139	132	132
query83	312	166	169	166
query84	273	88	90	88
query85	1606	323	358	323
query86	457	316	334	316
query87	3298	3116	3090	3090
query88	4953	2374	2405	2374
query89	512	382	393	382
query90	1988	195	194	194
query91	129	105	99	99
query92	66	52	49	49
query93	5168	517	523	517
query94	1368	275	286	275
query95	404	319	318	318
query96	624	274	274	274
query97	3217	3037	3033	3033
query98	219	200	198	198
query99	1568	1248	1280	1248
Total cold run time: 298847 ms
Total hot run time: 172883 ms

@doris-robot
Copy link

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

query1	0.04	0.04	0.04
query2	0.08	0.04	0.04
query3	0.22	0.05	0.04
query4	1.67	0.07	0.07
query5	0.50	0.47	0.48
query6	1.13	0.72	0.72
query7	0.02	0.01	0.01
query8	0.05	0.05	0.05
query9	0.55	0.48	0.50
query10	0.55	0.54	0.54
query11	0.14	0.11	0.12
query12	0.15	0.13	0.12
query13	0.59	0.58	0.59
query14	0.76	0.77	0.79
query15	0.85	0.82	0.81
query16	0.36	0.36	0.36
query17	1.02	0.99	1.04
query18	0.22	0.21	0.21
query19	1.92	1.67	1.70
query20	0.02	0.01	0.01
query21	15.40	0.78	0.66
query22	4.68	5.79	2.60
query23	18.30	1.47	1.28
query24	2.17	0.23	0.22
query25	0.16	0.09	0.08
query26	0.30	0.21	0.20
query27	0.45	0.23	0.23
query28	13.26	1.05	0.99
query29	12.61	3.31	3.30
query30	0.25	0.05	0.06
query31	2.87	0.38	0.39
query32	3.28	0.49	0.46
query33	2.86	2.93	2.95
query34	17.09	4.31	4.37
query35	4.42	4.43	4.42
query36	0.66	0.48	0.46
query37	0.18	0.15	0.16
query38	0.16	0.15	0.15
query39	0.05	0.03	0.03
query40	0.16	0.12	0.11
query41	0.09	0.05	0.05
query42	0.05	0.05	0.05
query43	0.05	0.04	0.04
Total cold run time: 110.34 s
Total hot run time: 31.24 s

Copy link
Contributor

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

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Jul 25, 2024
Copy link
Contributor

PR approved by anyone and no changes requested.

@yiguolei yiguolei merged commit dc2734a into apache:master Jul 26, 2024
29 of 31 checks passed
hello-stephen pushed a commit that referenced this pull request Jul 26, 2024
@zhiqiang-hhhh zhiqiang-hhhh deleted the profile-persist branch July 30, 2024 14:12
dataroaring pushed a commit that referenced this pull request Aug 11, 2024
… profile in memory (#33690)

Step 3 of #33744

Store profile on disk of FE, in the same path with audit log.
1. ProfileManager will have a daemon thread that checks whether a
profile should be stored on disk
2. Which profile can be stored? 
     a. query finished.
b. collection of profile has finished or query itself has finished for a
long time, like 5 seconds
3. Profile structure on disk:
```
* Integer: n(size of summary profile)
* String: json of summary profile
* Integer: m(size of compressed execution profile)
* String: compressed binary of execution profile
```
4. IO thread of ProfileManager will also remove garbage from disk.
5. Once a profile is stored to disk, its detail content will be release
from memory, so that we can hold more profiles in memory, further access
to profile will read from disk directly.
6. Basic but necessary UT for profile serialization.
7. Refine constructor of ExecutionProfile.

Further work:
1. Abstract class ProfileReader/ProfileWriter, they define common
interface for profile io, and we can implement
ProfileDiskReader/ProfileDiskWriter and also
ProfileS3Reader/ProfileS3Writer to support profile io on object storage.
2. Finer granularity for profile creation. Currently for ddl like
`create/drop table`, profile is also created, this is unnecessary.
3. More regression test.
4. More reasonable default value of max_profile_on_disk.
5. system table for profile storage, so that we can figure out how much
storage is costed for profile

---------

Co-authored-by: yiguolei <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
dataroaring pushed a commit that referenced this pull request Aug 12, 2024
dataroaring pushed a commit that referenced this pull request Aug 16, 2024
… profile in memory (#33690)

Step 3 of #33744

Store profile on disk of FE, in the same path with audit log.
1. ProfileManager will have a daemon thread that checks whether a
profile should be stored on disk
2. Which profile can be stored? 
     a. query finished.
b. collection of profile has finished or query itself has finished for a
long time, like 5 seconds
3. Profile structure on disk:
```
* Integer: n(size of summary profile)
* String: json of summary profile
* Integer: m(size of compressed execution profile)
* String: compressed binary of execution profile
```
4. IO thread of ProfileManager will also remove garbage from disk.
5. Once a profile is stored to disk, its detail content will be release
from memory, so that we can hold more profiles in memory, further access
to profile will read from disk directly.
6. Basic but necessary UT for profile serialization.
7. Refine constructor of ExecutionProfile.

Further work:
1. Abstract class ProfileReader/ProfileWriter, they define common
interface for profile io, and we can implement
ProfileDiskReader/ProfileDiskWriter and also
ProfileS3Reader/ProfileS3Writer to support profile io on object storage.
2. Finer granularity for profile creation. Currently for ddl like
`create/drop table`, profile is also created, this is unnecessary.
3. More regression test.
4. More reasonable default value of max_profile_on_disk.
5. system table for profile storage, so that we can figure out how much
storage is costed for profile

---------

Co-authored-by: yiguolei <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
dataroaring pushed a commit that referenced this pull request Aug 16, 2024
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. dev/3.0.2-merged meta-change reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants