如何解决并发调用api时发生异常
单击一次可以正常工作,但是当日志增加时,所有请求开始失败
在每个请求中,我正在调用另一个应用程序,该应用程序以500ms的延迟进行响应,然后在获得响应后,我将从db中获取用户。
@RequestMapping(value = "/{userId}",method = RequestMethod.GET)
public Mono<User> getUser(@PathVariable String userId) {
return sendRequestWithApacheHttpClient(500)
.flatMap(s-> userRepository.findById(userId));
}
private Mono<String> sendRequestWithApacheHttpClient(long delay) {
WebClient client=WebClient.create(userServiceHost);
return client.get().uri("/other/?delay="+delay)
.accept(MediaType.TEXT_PLAIN)
.retrieve().bodyToMono(String.class);
}
处理并发请求时出错。
20-08-25 05:51:17.909 ERROR 15726 --- [or-http-epoll-3] a.w.r.e.AbstractErrorWebExceptionHandler : [a9f12668-3777] 500 Server Error for HTTP GET "/user/5f3e7c44465eca51
io.netty.channel.ChannelException: io.netty.channel.unix.Errors$NativeIoException: newSocketStream(..) failed: Too many open files
at io.netty.channel.unix.Socket.newSocketStream0(Socket.java:421) ~[netty-transport-native-unix-common-4.1.50.Final.jar:4.1.50.Final]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
|_ checkpoint ⇢ Handler com.user.reactive.controller.UserController#getUser(String) [DispatcherHandler]
|_ checkpoint ⇢ HTTP GET "/user/5f3e7c44465eca5131363d65" [ExceptionHandlingWebHandler]
Stack trace:
at io.netty.channel.unix.Socket.newSocketStream0(Socket.java:421) ~[netty-transport-native-unix-common-4.1.50.Final.jar:4.1.50.Final]
at io.netty.channel.epoll.LinuxSocket.newSocketStream(LinuxSocket.java:319) ~[netty-transport-native-epoll-4.1.50.Final-linux-x86_64.jar:4.1.50.Final]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。