-
-
Notifications
You must be signed in to change notification settings - Fork 15.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DnsNameResolver query server address stream feature (#13873)
Motivation: The DnsNameResolver does instantiate an instance FastThreadLocal for each instance of the resolver that is created. This can have an impact on the InternalThreadLocalMap static index an the size of allocated arrays for FastThreadLocal. In addition this FastThreadLocal is only used by the DnsNameResolver query methods and not the resolve methods. Common usage of the DnsNameResolver by Netty (i.e. by a Bootstrap) only uses resolves and queries are not performed. Modification: This encapsulate the usage of the FastThreadLocal/dnsServerAddressStreamProvider in a specific implementation of DnsServerAddressStream that is instantiated by the DnsNameResolverBuilder by default to keep the current behavior. The builder now does provide a QueryServerAddressStream property that can be set prior calling build in order to provide a specific implementation of the stream for use case that do not whish to sustain the cost of instantiating a non static FastThreadLocal. Result: DnsNameResolver that do not use FastThreadLocal can now be created. This provides a possible solution for #9884 --------- Co-authored-by: Norman Maurer <norman_maurer@apple.com>
- Loading branch information
1 parent
3cc67f2
commit 45a7543
Showing
5 changed files
with
133 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
resolver-dns/src/main/java/io/netty/resolver/dns/ThreadLocalNameServerAddressStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2024 The Netty Project | ||
* | ||
* The Netty Project licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package io.netty.resolver.dns; | ||
|
||
import io.netty.util.concurrent.FastThreadLocal; | ||
|
||
import java.net.InetSocketAddress; | ||
|
||
/** | ||
* A thread local based address stream for a specific hostname. | ||
*/ | ||
final class ThreadLocalNameServerAddressStream implements DnsServerAddressStream { | ||
|
||
private final String hostname; | ||
private final DnsServerAddressStreamProvider dnsServerAddressStreamProvider; | ||
private final FastThreadLocal<DnsServerAddressStream> threadLocal = new FastThreadLocal<DnsServerAddressStream>() { | ||
@Override | ||
protected DnsServerAddressStream initialValue() { | ||
return dnsServerAddressStreamProvider.nameServerAddressStream(hostname); | ||
} | ||
}; | ||
|
||
ThreadLocalNameServerAddressStream(DnsServerAddressStreamProvider dnsServerAddressStreamProvider) { | ||
this(dnsServerAddressStreamProvider, ""); | ||
} | ||
|
||
ThreadLocalNameServerAddressStream(DnsServerAddressStreamProvider dnsServerAddressStreamProvider, String hostname) { | ||
this.dnsServerAddressStreamProvider = dnsServerAddressStreamProvider; | ||
this.hostname = hostname; | ||
} | ||
|
||
@Override | ||
public InetSocketAddress next() { | ||
return threadLocal.get().next(); | ||
} | ||
|
||
@Override | ||
public DnsServerAddressStream duplicate() { | ||
return new ThreadLocalNameServerAddressStream(dnsServerAddressStreamProvider, hostname); | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return threadLocal.get().size(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters