mirror of
https://github.com/apache/rocketmq.git
synced 2026-09-24 16:04:00 +08:00
[ISSUE 3585] [Part C] cache the result of parseChannelRemoteAddr() and eliminate this method in flame graph. (used 4.84% cpu before this commit in producer side) (#3589)
This commit is contained in:
@@ -17,6 +17,9 @@
|
||||
package org.apache.rocketmq.remoting.common;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.util.Attribute;
|
||||
import io.netty.util.AttributeKey;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
@@ -35,6 +38,7 @@ public class RemotingHelper {
|
||||
public static final String DEFAULT_CHARSET = "UTF-8";
|
||||
|
||||
private static final InternalLogger log = InternalLoggerFactory.getLogger(ROCKETMQ_REMOTING);
|
||||
private static final AttributeKey<String> REMOTE_ADDR_KEY = AttributeKey.valueOf("RemoteAddr");
|
||||
|
||||
public static String exceptionSimpleDesc(final Throwable e) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@@ -156,6 +160,20 @@ public class RemotingHelper {
|
||||
if (null == channel) {
|
||||
return "";
|
||||
}
|
||||
Attribute<String> att = channel.attr(REMOTE_ADDR_KEY);
|
||||
if (att == null) {
|
||||
// mocked in unit test
|
||||
return parseChannelRemoteAddr0(channel);
|
||||
}
|
||||
String addr = att.get();
|
||||
if (addr == null) {
|
||||
addr = parseChannelRemoteAddr0(channel);
|
||||
att.set(addr);
|
||||
}
|
||||
return addr;
|
||||
}
|
||||
|
||||
private static String parseChannelRemoteAddr0(final Channel channel) {
|
||||
SocketAddress remote = channel.remoteAddress();
|
||||
final String addr = remote != null ? remote.toString() : "";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user