-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HADOOP-17861. improve YARN Registry DNS Server qps #8106
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
Open
eubnara
wants to merge
1
commit into
apache:trunk
Choose a base branch
from
eubnara:HADOOP-17861
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+115
−62
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -126,6 +126,7 @@ public class RegistryDNS extends AbstractService implements DNSOperations, | |
|
|
||
| static final int FLAG_DNSSECOK = 1; | ||
| static final int FLAG_SIGONLY = 2; | ||
| private static final int DEFAULT_NUM_THREADS = 4; | ||
|
|
||
| private static final Logger LOG = | ||
| LoggerFactory.getLogger(RegistryDNS.class); | ||
|
|
@@ -167,7 +168,12 @@ public class RegistryDNS extends AbstractService implements DNSOperations, | |
| */ | ||
| public RegistryDNS(String name) { | ||
| super(name); | ||
| executor = HadoopExecutors.newCachedThreadPool( | ||
| int nThreads = Runtime.getRuntime().availableProcessors() / 4; | ||
| if (nThreads < DEFAULT_NUM_THREADS) { | ||
| nThreads = DEFAULT_NUM_THREADS; | ||
| } | ||
| executor = HadoopExecutors.newFixedThreadPool( | ||
| nThreads, | ||
| new ThreadFactory() { | ||
| private AtomicInteger counter = new AtomicInteger(1); | ||
|
|
||
|
|
@@ -180,6 +186,27 @@ public Thread newThread(Runnable r) { | |
| }); | ||
| } | ||
|
|
||
| public RegistryDNS(String name, Configuration conf) { | ||
| super(name); | ||
| int nThreads = conf.getInt(KEY_NUM_THREADS, Runtime.getRuntime().availableProcessors() / 4); | ||
| if (nThreads < DEFAULT_NUM_THREADS) { | ||
| nThreads = DEFAULT_NUM_THREADS; | ||
| } | ||
| LOG.info("using {} threads for serving dns query", nThreads); | ||
| executor = HadoopExecutors.newFixedThreadPool( | ||
| nThreads, | ||
| new ThreadFactory() { | ||
| private AtomicInteger counter = new AtomicInteger(1); | ||
|
|
||
| @Override | ||
| public Thread newThread(Runnable r) { | ||
| return new Thread(r, | ||
| "RegistryDNS " | ||
| + counter.getAndIncrement()); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| public void initializeChannels(Configuration conf) throws Exception { | ||
| if (channelsInitialized) { | ||
| return; | ||
|
|
@@ -805,6 +832,65 @@ public void nioTCPClient(SocketChannel ch) throws IOException { | |
|
|
||
| } | ||
|
|
||
| /** | ||
| * Process a UDP request. | ||
| * | ||
| * @param channel the datagram channel for the request. | ||
| * @param remoteAddress the socket address of client. | ||
| * @param input the input ByteBuffer. | ||
| * @throws IOException if the udp processing generates an issue. | ||
| */ | ||
| public void nioUDPClient(DatagramChannel channel, SocketAddress remoteAddress, ByteBuffer input) throws IOException { | ||
| ByteBuffer output = ByteBuffer.allocate(4096); | ||
| byte[] in = null; | ||
| byte[] response = null; | ||
| Message query = null; | ||
| try { | ||
| try { | ||
| int position = input.position(); | ||
| in = new byte[position]; | ||
| input.flip(); | ||
| input.get(in); | ||
| query = new Message(in); | ||
| LOG.info("{}: received UDP query {}", remoteAddress, | ||
| query.getQuestion()); | ||
| response = generateReply(query, null); | ||
| if (response.length > output.capacity()) { | ||
| LOG.warn("{}: Response of UDP query {} exceeds limit {}", | ||
| remoteAddress, query.getQuestion(), output.limit()); | ||
| query.getHeader().setFlag(Flags.TC); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the response of UDP query exceeds limit, TC(truncated) flag should be set in order for the client to request again with TCP query. |
||
| response = query.toWire(); | ||
| } | ||
| if (response == null) { | ||
| return; | ||
| } | ||
| } catch (IOException e) { | ||
| response = formErrorMessage(in); | ||
| if (response == null) { | ||
| LOG.debug("Error during create an error message." | ||
| + " Failed to parse a header", e); | ||
| return; | ||
| } | ||
| } | ||
| output.clear(); | ||
| output.put(response); | ||
| output.flip(); | ||
|
|
||
| LOG.debug("{}: sending response", remoteAddress); | ||
| channel.send(output, remoteAddress); | ||
| } catch (Exception e) { | ||
| if (e instanceof IOException && remoteAddress != null) { | ||
| throw NetUtils.wrapException(channel.socket().getInetAddress().getHostName(), | ||
| channel.socket().getPort(), | ||
| ((InetSocketAddress) remoteAddress).getHostName(), | ||
| ((InetSocketAddress) remoteAddress).getPort(), | ||
| (IOException) e); | ||
| } else { | ||
| throw e; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Calculate the inbound message length, which is related in the message as an | ||
| * unsigned short value. | ||
|
|
@@ -832,9 +918,8 @@ private int getMessgeLength(ByteBuffer buf) throws EOFException { | |
| */ | ||
| public void serveNIOTCP(ServerSocketChannel serverSocketChannel, | ||
| InetAddress addr, int port) throws Exception { | ||
| try { | ||
|
|
||
| while (true) { | ||
| while (true) { | ||
| try { | ||
| final SocketChannel socketChannel = serverSocketChannel.accept(); | ||
| if (socketChannel != null) { | ||
| executor.submit(new Callable<Boolean>() { | ||
|
|
@@ -848,10 +933,9 @@ public Boolean call() throws Exception { | |
| } else { | ||
| Thread.sleep(500); | ||
| } | ||
| } catch (Exception e) { | ||
| LOG.error("Error during accept", e); | ||
| } | ||
| } catch (IOException e) { | ||
| throw NetUtils.wrapException(addr.getHostName(), port, | ||
| addr.getHostName(), port, e); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -868,7 +952,7 @@ private ServerSocketChannel openTCPChannel(InetAddress addr, int port) | |
| ServerSocketChannel serverSocketChannel = ServerSocketChannel.open(); | ||
| try { | ||
| serverSocketChannel.socket().bind(new InetSocketAddress(addr, port)); | ||
| serverSocketChannel.configureBlocking(false); | ||
| serverSocketChannel.configureBlocking(true); | ||
| } catch (IOException e) { | ||
| throw NetUtils.wrapException(null, 0, | ||
| InetAddress.getLocalHost().getHostName(), | ||
|
|
@@ -917,7 +1001,7 @@ public void addNIOUDP(final InetAddress addr, final int port) | |
| @Override | ||
| public Boolean call() throws Exception { | ||
| try { | ||
| serveNIOUDP(udpChannel, addr, port); | ||
| serveNIOUDP(udpChannel); | ||
| } catch (Exception e) { | ||
| LOG.error("Error initializing DNS UDP listener", e); | ||
| throw e; | ||
|
|
@@ -931,60 +1015,22 @@ public Boolean call() throws Exception { | |
| * Process an inbound UDP request. | ||
| * | ||
| * @param channel the UDP datagram channel. | ||
| * @param addr local host address. | ||
| * @param port local port. | ||
| * @throws IOException if the UDP processing fails. | ||
| */ | ||
| private synchronized void serveNIOUDP(DatagramChannel channel, | ||
| InetAddress addr, int port) throws Exception { | ||
| SocketAddress remoteAddress = null; | ||
| try { | ||
|
|
||
| ByteBuffer input = ByteBuffer.allocate(4096); | ||
| ByteBuffer output = ByteBuffer.allocate(4096); | ||
| byte[] in = null; | ||
|
|
||
| while (true) { | ||
| private synchronized void serveNIOUDP(DatagramChannel channel) { | ||
| while (true) { | ||
| try { | ||
| ByteBuffer input = ByteBuffer.allocate(4096); | ||
| input.clear(); | ||
| try { | ||
| remoteAddress = channel.receive(input); | ||
| } catch (IOException e) { | ||
| LOG.debug("Error during message receipt", e); | ||
| continue; | ||
| } | ||
| Message query; | ||
| byte[] response = null; | ||
| try { | ||
| int position = input.position(); | ||
| in = new byte[position]; | ||
| input.flip(); | ||
| input.get(in); | ||
| query = new Message(in); | ||
| LOG.info("{}: received UDP query {}", remoteAddress, | ||
| query.getQuestion()); | ||
| response = generateReply(query, null); | ||
| if (response == null) { | ||
| continue; | ||
| SocketAddress remoteAddress = channel.receive(input); | ||
| executor.submit(new Callable<Boolean>() { | ||
| @Override | ||
| public Boolean call() throws Exception { | ||
| nioUDPClient(channel, remoteAddress, input); | ||
| return true; | ||
| } | ||
| } catch (IOException e) { | ||
| response = formErrorMessage(in); | ||
| } | ||
| output.clear(); | ||
| output.put(response); | ||
| output.flip(); | ||
|
|
||
| LOG.debug("{}: sending response", remoteAddress); | ||
| channel.send(output, remoteAddress); | ||
| } | ||
| } catch (Exception e) { | ||
| if (e instanceof IOException && remoteAddress != null) { | ||
| throw NetUtils.wrapException(addr.getHostName(), | ||
| port, | ||
| ((InetSocketAddress) remoteAddress).getHostName(), | ||
| ((InetSocketAddress) remoteAddress).getPort(), | ||
| (IOException) e); | ||
| } else { | ||
| throw e; | ||
| }); | ||
| } catch (Exception e) { | ||
| LOG.debug("Error during message receive", e); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -1392,7 +1438,7 @@ byte addAnswer(Message response, Name name, int type, int dclass, | |
| } | ||
| } else if (sr.isSuccessful()) { | ||
| List<RRset> rrsets = sr.answers(); | ||
| LOG.info("found answers {}", rrsets); | ||
| LOG.debug("found answers {}", rrsets); | ||
| for (RRset rrset : rrsets) { | ||
| addRRset(name, response, rrset, Section.ANSWER, flags); | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two nested try is generally considered a code smell. Sonar will tell you to design differently like using a method etc