Add log level check simply before logging. (#10080)

Motivation:

In general, we will close the debug log in a product environment. However, logging without external level check may still affect performance as varargs will need to allocate an array.

Modification:

Add log level check simply before logging.

Result:

Improve performance slightly in a product environment.
This commit is contained in:
Norman Maurer 2020-03-05 14:38:57 +01:00
parent 3537dc79b9
commit 118e1c66dc
5 changed files with 24 additions and 11 deletions

View File

@ -289,7 +289,10 @@ public final class NetUtil {
} }
} }
} catch (Exception e) { } catch (Exception e) {
logger.debug("Failed to get SOMAXCONN from sysctl and file {}. Default: {}", file, somaxconn, e); if (logger.isDebugEnabled()) {
logger.debug("Failed to get SOMAXCONN from sysctl and file {}. Default: {}",
file, somaxconn, e);
}
} finally { } finally {
if (in != null) { if (in != null) {
try { try {

View File

@ -138,10 +138,12 @@ public final class NativeLibraryLoader {
return; return;
} catch (Throwable ex) { } catch (Throwable ex) {
suppressed.add(ex); suppressed.add(ex);
if (logger.isDebugEnabled()) {
logger.debug( logger.debug(
"{} cannot be loaded from java.library.path, " "{} cannot be loaded from java.library.path, "
+ "now trying export to -Dio.netty.native.workdir: {}", name, WORKDIR, ex); + "now trying export to -Dio.netty.native.workdir: {}", name, WORKDIR, ex);
} }
}
String libname = System.mapLibraryName(name); String libname = System.mapLibraryName(name);
String path = NATIVE_RESOURCE_HOME + libname; String path = NATIVE_RESOURCE_HOME + libname;

View File

@ -1167,11 +1167,13 @@ public class SslHandler extends ByteToMessageDecoder {
return true; return true;
} }
} catch (Throwable cause) { } catch (Throwable cause) {
if (logger.isDebugEnabled()) {
logger.debug("Unexpected exception while loading class {} classname {}", logger.debug("Unexpected exception while loading class {} classname {}",
getClass(), classname, cause); getClass(), classname, cause);
} }
} }
} }
}
return false; return false;
} }

View File

@ -72,7 +72,9 @@ public final class UnixResolverDnsServerAddressStreamProvider implements DnsServ
return nameServerCache.mayOverrideNameServers() ? nameServerCache return nameServerCache.mayOverrideNameServers() ? nameServerCache
: DefaultDnsServerAddressStreamProvider.INSTANCE; : DefaultDnsServerAddressStreamProvider.INSTANCE;
} catch (Exception e) { } catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("failed to parse {} and/or {}", ETC_RESOLV_CONF_FILE, ETC_RESOLVER_DIR, e); logger.debug("failed to parse {} and/or {}", ETC_RESOLV_CONF_FILE, ETC_RESOLVER_DIR, e);
}
return DefaultDnsServerAddressStreamProvider.INSTANCE; return DefaultDnsServerAddressStreamProvider.INSTANCE;
} }
} }
@ -256,10 +258,12 @@ public final class UnixResolverDnsServerAddressStreamProvider implements DnsServ
DnsServerAddresses existingAddresses = domainToNameServerStreamMap.put(domainName, addresses); DnsServerAddresses existingAddresses = domainToNameServerStreamMap.put(domainName, addresses);
if (existingAddresses != null) { if (existingAddresses != null) {
domainToNameServerStreamMap.put(domainName, existingAddresses); domainToNameServerStreamMap.put(domainName, existingAddresses);
if (logger.isDebugEnabled()) {
logger.debug("Domain name {} already maps to addresses {} so new addresses {} will be discarded", logger.debug("Domain name {} already maps to addresses {} so new addresses {} will be discarded",
domainName, existingAddresses, addresses); domainName, existingAddresses, addresses);
} }
} }
}
/** /**
* Parse a file of the format <a href="https://linux.die.net/man/5/resolver">/etc/resolv.conf</a> and return the * Parse a file of the format <a href="https://linux.die.net/man/5/resolver">/etc/resolv.conf</a> and return the

View File

@ -175,8 +175,10 @@ final class ChannelHandlerMask {
try { try {
m = handlerType.getMethod(methodName, paramTypes); m = handlerType.getMethod(methodName, paramTypes);
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
if (logger.isDebugEnabled()) {
logger.debug( logger.debug(
"Class {} missing method {}, assume we can not skip execution", handlerType, methodName, e); "Class {} missing method {}, assume we can not skip execution", handlerType, methodName, e);
}
return false; return false;
} }
return m != null && m.isAnnotationPresent(Skip.class); return m != null && m.isAnnotationPresent(Skip.class);