Java 错误请求(服务异常)的响应时间较慢使用zuul进行spring引导

Java 错误请求(服务异常)的响应时间较慢使用zuul进行spring引导,java,spring,spring-boot,microservices,netflix-zuul,Java,Spring,Spring Boot,Microservices,Netflix Zuul,我使用zuul gateway和Eureka部署了spring boot micro服务,这些服务运行良好,但我注意到,当请求发出错误请求时,实际上会从服务类(无效的用户/客户Id)抛出异常,相关的错误响应耗时超过2秒。成功场景工作正常,响应时间可以接受。正如您在下面的日志中所看到的,错误花费了更多的时间。这些服务托管在AWS中,但在没有zuul集成的本地环境中运行良好 2020-04-03 04:14:38.102调试14156---[nio-8084-exec-9]c.t.book.filt

我使用zuul gateway和Eureka部署了spring boot micro服务,这些服务运行良好,但我注意到,当请求发出错误请求时,实际上会从服务类(无效的用户/客户Id)抛出异常,相关的错误响应耗时超过2秒。成功场景工作正常,响应时间可以接受。正如您在下面的日志中所看到的,错误花费了更多的时间。这些服务托管在AWS中,但在没有zuul集成的本地环境中运行良好

2020-04-03 04:14:38.102调试14156---[nio-8084-exec-9]c.t.book.filter.AuthorizationFilter:Auth-UserId-in-filter:uid-b7e9d6f7-f5bf-4e74-9ac1-1d1120ceb43f
2020-04-03 04:14:38.103调试14156---[nio-8084-exec-9]c.t.t.controller.TransactionController:创建事务输入:{“bookId”:“bid-1”,“customerId”:“cid-8”,“transactionType”:“credit”,“amount”:5000.0,“注”:“日期验证测试”,“dueDate”:1580026934,“imageUrl”:http://123.com,“customerBookType”:null,“requiredAvailable”:true},时区:亚洲/科伦坡
2020-04-03 04:14:39.884错误14156---[nio-8084-exec-9]c.t.t.controller.TransactionController:交易的无效客户id:{“bookId:”bid-1“,”交易类型“:”信用“,”金额“:”5000.0,“注”:“日期验证测试”,“dueDate:”1585261934,“imageUrl:”http://123.com,“customerBookType”:null,“requiredAvailable”:true}
com.book.exception.InvalidUserException:无效的客户id
我还尝试直接绕过zuul发送请求,但在这里我也得到了延迟。 请看这个,如果你需要更多的信息,让我知道

已更新

我注意到这种情况是间歇性的,比如第一次调用和第二次调用需要2秒以上,然后接下来的4到5个请求需要正常时间,然后一个请求需要更多时间。但在当地环境中,这种行为并不存在。(正如我前面提到的,这种情况只发生在错误场景中)

代码

服务等级

public Customer updateCustomer(CustomerUpdateRequestDto CustomerUpdateRequestDto){
试一试{
字符串customerId=customerUpdateRequestDto.getCustomerId().trim();
可选customerOptional=customerRepository
.findById(customerId);
if(customerOptional.isPresent()){
Customer=customerOptional.get();
customer.setDisplayName(customerUpdateRequestDto.getName().trim());
customer.setImageUrl(customerUpdateRequestDto.getImageUrl()==null?
null:customerUpdateRequestDto.getImageUrl().trim());
customer.setMobileNo(customerUpdateRequestDto.getMobileNo().getDisplayNumber());
customer.setUpdatedAt(新日期());
customerRepository.save(客户);
退货客户;
}否则{
抛出新的InvalidUserException(无效的客户ID);
}
}捕获(数据访问异常){
抛出新BookException(更新客户失败,e);
}
}
来自控制器的方法调用

private ResponseEntity updateCustomerAmerifValid(CustomerUpdateRequestDto CustomerUpdateRequestDto){
试一试{
Customer=customerService.updateCustomer(customerUpdateRequestDto);
CustomerResponseDto CustomerResponseDto=新CustomerResponseDto(客户);
debug(“更新客户:{}成功”,customerResponseDto.toLogJson());
响应包装器响应包装器=
新的ResponseWrapper(ResponseStatusType.SUCCESS、SUCCESS\u MESSAGE\u UPDATE、customerResponseDto);
返回新的ResponseEntity(responseWrapper,HttpStatus.OK);
}捕获(InvalidUserException){
错误(“更新客户:{},customerUpdateRequestDto.toLogJson(),e)的客户失败);
返回getBadRequestError(ErrorResponseStatusType.INVALID_CUSTOMER_ID);
}
}
受保护的ResponseEntity getBadRequestError(ErrorResponseStatusType ErrorResponseStatusType){
响应包装器响应包装器=
新的ErrorResponseWrapper(errorResponseStatusType,null);
返回新的ResponseEntity(responseWrapper,HttpStatus.BAD_请求);
}

谢谢

我发现了这个问题,上面微服务的扩展是.war,我没有注意到,在将它转换成一个jar之后,延迟不再是他们的问题。无论如何,我需要检查一下为什么会发生这种情况。战争扩展

如果你通过了zuul,那么还需要时间来响应的方式,应该不会出现zuul网关的问题。您可以添加exceptionHandler和相关代码吗?@techzone4all我已经添加了来自服务和控制器的代码,这里InvalidUserException是预期的场景。可能有一个库只供servlet使用,反之亦然。请检查您是否可以从中找到阳光:)