Skip to content

Conversation

@morningman
Copy link
Contributor

@morningman morningman commented Mar 26, 2024

Proposed changes

In previously, when enabling FQDN, Doris will call dns resolver to get IP from hostname
each time when 1) FE gets BE's grpc client. 2) BE gets other BE's brpc client.
So when in high concurrency case, the dns resolver be overloaded and failed to resolve hostname.

This PR mainly changes:

  1. Add DNSCache for both FE and BE.
    The DNSCache will run on every FE and BE node. It has a cache, key is hostname and value is IP.
    Caller can get IP by hostname from this cache, and if hostname does not exist, it will try to resolve it
    and update the cache.
    In addition, DNSCache has a daemon thread to refresh the cache every 1 min, in case that the IP may
    be changed at anytime.

There are other implements of this dns cache:

  1. kaka11chen@36fed13
    This is for BE side, but it does not handle the IP change case.

  2. [fix](proxy) Fix getProxy frequently parse hostname to ip #28479
    This is for FE side, but it can only work with Master FE. Other FE node will not be aware of the IP change.
    And there are a bunch of BackendServiceProxy, this PR only handle cache in one of them.

Further comments

If this is a relatively large or complex change, kick off the discussion at dev@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc...

@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

return Status::OK();
}

void DNSCache::_refresh_cache() {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: method '_refresh_cache' can be made const [readability-make-member-function-const]

Suggested change
void DNSCache::_refresh_cache() {
void DNSCache::_refresh_cache() const {

be/src/util/dns_cache.h:41:

-     void _refresh_cache();
+     void _refresh_cache() const;

~DNSCache();

// get ip by hostname
Status get(const std::string& hostname, std::string* ip);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: unknown type name 'Status' [clang-diagnostic-error]

    Status get(const std::string& hostname, std::string* ip);
    ^


private:
// update the ip of hostname in cache
Status _update(const std::string& hostname);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: unknown type name 'Status' [clang-diagnostic-error]

    Status _update(const std::string& hostname);
    ^

// update cache at fix internal
void _refresh_cache();

private:
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]

Suggested change
private:
Additional context

be/src/util/dns_cache.h:35: previously declared here

private:
^

@morningman
Copy link
Contributor Author

run buildall

1 similar comment
@morningman
Copy link
Contributor Author

run buildall

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

// update cache at fix internal
void _refresh_cache();

private:
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]

Suggested change
private:
Additional context

be/src/util/dns_cache.h:40: previously declared here

private:
^

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17631	4386	4143	4143
q2	2114	159	157	157
q3	10575	1190	1162	1162
q4	10225	750	848	750
q5	7473	3020	3021	3020
q6	204	125	123	123
q7	1058	589	588	588
q8	9335	2003	1964	1964
q9	7165	6629	6574	6574
q10	8452	3425	3563	3425
q11	436	224	220	220
q12	382	202	208	202
q13	17795	2847	2887	2847
q14	247	211	212	211
q15	515	460	455	455
q16	494	372	370	370
q17	964	616	582	582
q18	7266	6622	6493	6493
q19	3446	1395	1385	1385
q20	557	256	288	256
q21	3569	2851	2948	2851
q22	350	295	298	295
Total cold run time: 110253 ms
Total hot run time: 38073 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4159	4092	4034	4034
q2	333	235	231	231
q3	2952	2893	2864	2864
q4	1869	1547	1555	1547
q5	5270	5380	5359	5359
q6	196	118	118	118
q7	2244	1851	1844	1844
q8	3167	3305	3301	3301
q9	8668	8728	8687	8687
q10	3811	3820	3736	3736
q11	535	456	451	451
q12	732	570	563	563
q13	16876	2881	2873	2873
q14	273	249	261	249
q15	501	459	452	452
q16	487	428	423	423
q17	1734	1499	1458	1458
q18	7571	7315	7063	7063
q19	1598	1482	1537	1482
q20	1907	1737	1712	1712
q21	4817	4687	4664	4664
q22	517	429	465	429
Total cold run time: 70217 ms
Total hot run time: 53540 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 181357 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 54828b494a66af12315ecd79a552c862bfb9ab34, data reload: false

query1	940	356	349	349
query2	6568	1942	1791	1791
query3	6707	209	210	209
query4	31737	21321	21264	21264
query5	4302	403	402	402
query6	279	179	175	175
query7	4621	290	293	290
query8	229	165	179	165
query9	9548	2338	2294	2294
query10	555	243	258	243
query11	15490	14382	14234	14234
query12	139	88	84	84
query13	1611	400	411	400
query14	9901	7754	7571	7571
query15	234	207	210	207
query16	8042	261	258	258
query17	1952	575	549	549
query18	1989	297	287	287
query19	240	156	161	156
query20	92	86	92	86
query21	203	137	129	129
query22	4958	4815	4801	4801
query23	33999	32978	32771	32771
query24	11111	2902	2824	2824
query25	614	383	385	383
query26	1201	152	156	152
query27	3038	353	358	353
query28	7251	1888	1888	1888
query29	894	676	637	637
query30	305	150	152	150
query31	996	725	730	725
query32	93	62	57	57
query33	766	259	249	249
query34	1013	487	488	487
query35	832	622	634	622
query36	1042	917	888	888
query37	126	70	66	66
query38	3555	3415	3402	3402
query39	1467	1436	1426	1426
query40	210	117	111	111
query41	53	45	47	45
query42	104	94	96	94
query43	487	436	449	436
query44	1140	734	729	729
query45	284	256	273	256
query46	1117	700	699	699
query47	1929	1871	1841	1841
query48	459	358	359	358
query49	1127	341	349	341
query50	768	366	375	366
query51	6754	6536	6660	6536
query52	111	91	91	91
query53	351	280	272	272
query54	299	246	234	234
query55	86	78	87	78
query56	247	234	236	234
query57	1216	1143	1135	1135
query58	236	208	213	208
query59	2796	2711	2672	2672
query60	259	239	240	239
query61	97	93	98	93
query62	656	471	441	441
query63	301	279	269	269
query64	5739	4096	3890	3890
query65	3080	3013	3026	3013
query66	881	364	360	360
query67	15236	15248	14863	14863
query68	6122	515	524	515
query69	581	387	378	378
query70	1283	1171	1184	1171
query71	466	271	267	267
query72	6639	2743	2530	2530
query73	707	313	320	313
query74	7717	6378	6472	6378
query75	3276	2218	2169	2169
query76	4149	905	879	879
query77	639	253	257	253
query78	10878	10243	10114	10114
query79	7579	515	519	515
query80	1799	380	371	371
query81	534	214	226	214
query82	1602	85	85	85
query83	276	140	144	140
query84	290	81	85	81
query85	1681	376	367	367
query86	494	308	299	299
query87	3747	3510	3549	3510
query88	5110	2334	2323	2323
query89	481	383	373	373
query90	1949	180	182	180
query91	179	147	149	147
query92	63	48	49	48
query93	6021	498	480	480
query94	1204	188	187	187
query95	439	330	332	330
query96	604	270	261	261
query97	2691	2445	2485	2445
query98	236	215	209	209
query99	1211	897	908	897
Total cold run time: 305310 ms
Total hot run time: 181357 ms

@doris-robot
Copy link

Load test result on machine: 'aliyun_ecs.c7a.8xlarge_32C64G'

Load test result on commit 54828b494a66af12315ecd79a552c862bfb9ab34 with default session variables
Stream load json:         18 seconds loaded 2358488459 Bytes, about 124 MB/s
Stream load orc:          60 seconds loaded 1101869774 Bytes, about 17 MB/s
Stream load parquet:      31 seconds loaded 861443392 Bytes, about 26 MB/s
Insert into select:       13.7 seconds inserted 10000000 Rows, about 729K ops/s

1
2

3

4

4

5

6
@morningman
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17725	4809	4151	4151
q2	2134	170	157	157
q3	11298	1147	1143	1143
q4	10568	793	802	793
q5	7782	3095	3078	3078
q6	208	126	125	125
q7	1066	626	586	586
q8	9407	2070	2015	2015
q9	7318	6755	6712	6712
q10	9114	3514	3586	3514
q11	429	232	221	221
q12	370	199	199	199
q13	17796	2915	2882	2882
q14	239	203	205	203
q15	514	475	472	472
q16	464	380	376	376
q17	972	605	524	524
q18	7140	6408	6431	6408
q19	1542	1424	1480	1424
q20	555	260	250	250
q21	3593	2978	2831	2831
q22	351	291	296	291
Total cold run time: 110585 ms
Total hot run time: 38355 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4102	4094	4149	4094
q2	331	244	230	230
q3	2996	2871	2867	2867
q4	1813	1577	1546	1546
q5	5330	5337	5394	5337
q6	196	116	116	116
q7	2273	1885	1859	1859
q8	3153	3301	3305	3301
q9	8731	8639	8682	8639
q10	3766	3797	3825	3797
q11	546	439	447	439
q12	723	599	522	522
q13	14557	2858	2884	2858
q14	273	252	242	242
q15	502	463	463	463
q16	475	424	414	414
q17	1734	1534	1492	1492
q18	7367	7267	7030	7030
q19	1635	1514	1564	1514
q20	1901	1724	1696	1696
q21	4836	4705	4645	4645
q22	541	442	431	431
Total cold run time: 67781 ms
Total hot run time: 53532 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 181392 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 9319f1c79b70a6c837744461df3bd3e7f0906c5c, data reload: false

query1	930	372	350	350
query2	6537	2016	1844	1844
query3	6706	205	207	205
query4	31852	21437	21365	21365
query5	4328	395	390	390
query6	273	186	199	186
query7	4631	298	294	294
query8	233	179	175	175
query9	9544	2333	2301	2301
query10	558	248	257	248
query11	15378	14225	14221	14221
query12	134	89	90	89
query13	1623	417	444	417
query14	10998	7605	7577	7577
query15	242	205	197	197
query16	7976	254	266	254
query17	1955	579	553	553
query18	1380	289	288	288
query19	322	159	156	156
query20	90	92	91	91
query21	208	129	129	129
query22	4967	4805	4738	4738
query23	33551	32803	32607	32607
query24	11963	2882	2853	2853
query25	648	401	388	388
query26	1742	166	158	158
query27	3148	357	366	357
query28	7808	1881	1847	1847
query29	979	639	618	618
query30	309	150	148	148
query31	969	705	740	705
query32	89	59	56	56
query33	772	247	257	247
query34	1164	494	493	493
query35	837	609	618	609
query36	1006	882	915	882
query37	270	70	64	64
query38	3500	3496	3418	3418
query39	1482	1453	1457	1453
query40	302	115	115	115
query41	52	49	47	47
query42	110	97	98	97
query43	499	460	452	452
query44	1189	756	742	742
query45	280	246	257	246
query46	1108	722	710	710
query47	1910	1874	1850	1850
query48	446	354	360	354
query49	1232	341	345	341
query50	756	372	375	372
query51	6630	6645	6625	6625
query52	97	92	95	92
query53	355	275	274	274
query54	333	252	246	246
query55	87	77	79	77
query56	242	233	233	233
query57	1239	1158	1138	1138
query58	239	210	216	210
query59	2767	2685	2595	2595
query60	268	249	251	249
query61	118	115	117	115
query62	659	457	451	451
query63	301	280	272	272
query64	6715	3941	4013	3941
query65	3142	3036	3035	3035
query66	1343	377	361	361
query67	15517	14911	14685	14685
query68	9031	516	541	516
query69	634	387	386	386
query70	1409	1221	1180	1180
query71	502	257	261	257
query72	6440	2740	2558	2558
query73	1691	319	307	307
query74	6932	6411	6449	6411
query75	3886	2244	2212	2212
query76	5520	869	830	830
query77	644	269	259	259
query78	11084	10124	10155	10124
query79	9933	525	520	520
query80	1760	392	377	377
query81	523	218	210	210
query82	612	90	85	85
query83	221	145	142	142
query84	286	85	77	77
query85	1379	342	322	322
query86	395	290	285	285
query87	3746	3553	3564	3553
query88	4442	2326	2289	2289
query89	490	383	371	371
query90	1998	179	177	177
query91	168	137	137	137
query92	60	49	47	47
query93	6673	499	489	489
query94	1239	180	178	178
query95	440	329	333	329
query96	617	273	266	266
query97	2652	2498	2492	2492
query98	236	227	213	213
query99	1188	929	897	897
Total cold run time: 315869 ms
Total hot run time: 181392 ms

@doris-robot
Copy link

TeamCity be ut coverage result:
Function Coverage: 35.24% (8741/24802)
Line Coverage: 27.03% (71559/264691)
Region Coverage: 26.28% (37127/141287)
Branch Coverage: 23.18% (18988/81912)
Coverage Report: http://coverage.selectdb-in.cc/coverage/9319f1c79b70a6c837744461df3bd3e7f0906c5c_9319f1c79b70a6c837744461df3bd3e7f0906c5c/report/index.html

@doris-robot
Copy link

Load test result on machine: 'aliyun_ecs.c7a.8xlarge_32C64G'

Load test result on commit 9319f1c79b70a6c837744461df3bd3e7f0906c5c with default session variables
Stream load json:         18 seconds loaded 2358488459 Bytes, about 124 MB/s
Stream load orc:          59 seconds loaded 1101869774 Bytes, about 17 MB/s
Stream load parquet:      32 seconds loaded 861443392 Bytes, about 25 MB/s
Insert into select:       13.7 seconds inserted 10000000 Rows, about 729K ops/s

Copy link
Contributor

@xinyiZzz xinyiZzz left a comment

Choose a reason for hiding this comment

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

LGTM

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

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

@github-actions
Copy link
Contributor

PR approved by anyone and no changes requested.

Copy link
Contributor

@kaka11chen kaka11chen left a comment

Choose a reason for hiding this comment

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

LGTM

@morningman morningman merged commit 39d695c into apache:master Mar 28, 2024
morningman added a commit to morningman/doris that referenced this pull request Mar 28, 2024
In previously, when enabling FQDN, Doris will call dns resolver to get IP from hostname
each time when 1) FE gets BE's grpc client. 2) BE gets other BE's brpc client.
So when in high concurrency case, the dns resolver be overloaded and failed to resolve hostname.

This PR mainly changes:

1. Add DNSCache for both FE and BE.
    The DNSCache will run on every FE and BE node. It has a cache, key is hostname and value is IP.
    Caller can get IP by hostname from this cache, and if hostname does not exist, it will try to resolve it
    and update the cache.
    In addition, DNSCache has a daemon thread to refresh the cache every 1 min, in case that the IP may
    be changed at anytime.

There are other implements of this dns cache:

1.  kaka11chen@36fed13
    This is for BE side, but it does not handle the IP change case.

3. apache#28479
    This is for FE side, but it can only work with Master FE. Other FE node will not be aware of the IP change.
    And there are a bunch of BackendServiceProxy, this PR only handle cache in one of them.

DNSCache::DNSCache() {
refresh_thread = std::thread(&DNSCache::_refresh_cache, this);
refresh_thread.detach();
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.

I will fix it


DNSCache::~DNSCache() {
stop_refresh = true;
if (refresh_thread.joinable()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

not joinable, so DNECache will be destoried immediately

std::unordered_set<std::string> keys;
{
std::shared_lock<std::shared_mutex> lock(mutex);
std::transform(cache.begin(), cache.end(), std::inserter(keys, keys.end()),
Copy link
Contributor

Choose a reason for hiding this comment

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

it is very likely that object cache has already been destroyed, if main thread has already exited with --grace enabled.

void DNSCache::_refresh_cache() {
while (!stop_refresh) {
// refresh every 1 min
std::this_thread::sleep_for(std::chrono::minutes(1));
Copy link
Contributor

Choose a reason for hiding this comment

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

btw, after _refresh_cache thread is joinable, when we stop BE with grace enabled, we will wait at least 1 min ...

morningman added a commit to morningman/doris that referenced this pull request Apr 7, 2024
In previously, when enabling FQDN, Doris will call dns resolver to get IP from hostname
each time when 1) FE gets BE's grpc client. 2) BE gets other BE's brpc client.
So when in high concurrency case, the dns resolver be overloaded and failed to resolve hostname.

This PR mainly changes:

1. Add DNSCache for both FE and BE.
    The DNSCache will run on every FE and BE node. It has a cache, key is hostname and value is IP.
    Caller can get IP by hostname from this cache, and if hostname does not exist, it will try to resolve it
    and update the cache.
    In addition, DNSCache has a daemon thread to refresh the cache every 1 min, in case that the IP may
    be changed at anytime.

There are other implements of this dns cache:

1.  kaka11chen@36fed13
    This is for BE side, but it does not handle the IP change case.

3. apache#28479
    This is for FE side, but it can only work with Master FE. Other FE node will not be aware of the IP change.
    And there are a bunch of BackendServiceProxy, this PR only handle cache in one of them.
@yiguolei yiguolei mentioned this pull request Apr 8, 2024
mongo360 pushed a commit to mongo360/doris 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/2.0.8-merged dev/2.1.2-merged reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants