From e5993efcede3ad9812f2f4a4125010aeef8a8324 Mon Sep 17 00:00:00 2001 From: dave-fl Date: Fri, 31 Aug 2018 11:57:09 -0400 Subject: [PATCH] Minor performance tweaks (showed as hotspots when testing). --- .../cloud/gateway/handler/FilteringWebHandler.java | 10 ++++++---- .../gateway/handler/RoutePredicateHandlerMapping.java | 5 ++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/FilteringWebHandler.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/FilteringWebHandler.java index 53ea26231..b330aa508 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/FilteringWebHandler.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/FilteringWebHandler.java @@ -23,7 +23,10 @@ import java.util.stream.Collectors; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import reactor.core.publisher.Mono; + import org.springframework.cloud.gateway.filter.GatewayFilter; +import org.springframework.cloud.gateway.filter.GatewayFilterChain; import org.springframework.cloud.gateway.filter.GlobalFilter; import org.springframework.cloud.gateway.filter.OrderedGatewayFilter; import org.springframework.cloud.gateway.filter.factory.GatewayFilterFactory; @@ -31,13 +34,10 @@ import org.springframework.cloud.gateway.route.Route; import org.springframework.core.Ordered; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.web.server.ServerWebExchange; -import org.springframework.cloud.gateway.filter.GatewayFilterChain; import org.springframework.web.server.WebHandler; import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR; -import reactor.core.publisher.Mono; - /** * WebHandler that delegates to a chain of {@link GlobalFilter} instances and * {@link GatewayFilterFactory} instances then to the target {@link WebHandler}. @@ -82,7 +82,9 @@ public class FilteringWebHandler implements WebHandler { //TODO: needed or cached? AnnotationAwareOrderComparator.sort(combined); - logger.debug("Sorted gatewayFilterFactories: "+ combined); + if (logger.isDebugEnabled()) { + logger.debug("Sorted gatewayFilterFactories: "+ combined); + } return new DefaultGatewayFilterChain(combined).filter(exchange); } diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMapping.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMapping.java index bcbe5d295..2b1d9ac0e 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMapping.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMapping.java @@ -61,7 +61,7 @@ public class RoutePredicateHandlerMapping extends AbstractHandlerMapping { if (managmentPort != null && exchange.getRequest().getURI().getPort() == managmentPort.intValue()) { return Mono.empty(); } - exchange.getAttributes().put(GATEWAY_HANDLER_MAPPER_ATTR, getClass().getSimpleName()); + exchange.getAttributes().put(GATEWAY_HANDLER_MAPPER_ATTR, getSimpleName()); return lookupRoute(exchange) // .log("route-predicate-handler-mapping", Level.FINER) //name this @@ -146,4 +146,7 @@ public class RoutePredicateHandlerMapping extends AbstractHandlerMapping { protected void validateRoute(Route route, ServerWebExchange exchange) { } + protected String getSimpleName() { + return "RoutePredicateHandlerMapping"; + } }