[英]Spring webflux blocking another request
我正在研究 Spring webflux 並面臨我不理解的情況。
Spring 版本 = 2.2.4.RELEASE 我的電腦有 4 個核心。
我的 Class:
@RestController
@RequestMapping("rest/v1/")
public class RootController {
private final WebClient webClient =
WebClient.create("http://localhost:8081");
@GetMapping("/booking")
public Mono book() {
return Mono.just("A");
}
@GetMapping("/sleep")
public Mono<String> sleep(@RequestParam("time") long time) throws InterruptedException {
System.out.printf("Thread name is %s, date is %s. \n", Thread.currentThread().getName(), new Date());
String uri = "/rest/v1/sleep?time=" + time;
String uuid = UUID.randomUUID().toString();
System.out.println(">>>>>>>>>>>>" + uuid);
Mono<String> stringMono = webClient.get().uri(uri)
.retrieve()
.bodyToMono(String.class);
System.out.printf("Finish -> Thread name is %s, date is %s. \n", Thread.currentThread().getName(), new Date());
return stringMono;
}
}
我的機器上有另一個應用程序,在端口 8081 上運行。這個 endoint 只休眠一段時間,由 param 接收。
目標是測試調用慢速端點時 webflux 的行為如何。
我正在執行這樣的請求:
http://localhost:8082/rest/v1/sleep?time=20000
在這種情況下,響應將需要 20 秒。
當我在此期間執行另一個請求時,controller 不會處理該請求,它會一直等待該請求完成(20 秒)。
Spring 在等待網絡調用時是否應該處理另一個請求?
這是日志:
Thread name is reactor-http-epoll-3, date is Sat May 16 19:06:54 BRT 2020.
>>>>>>>>>>>>22b36a46-e36b-4104-981a-e132483a334e
Finish -> Thread name is reactor-http-epoll-3, date is Sat May 16 19:06:54 BRT 2020.
Thread name is reactor-http-epoll-3, date is Sat May 16 19:07:14 BRT 2020.
>>>>>>>>>>>>076a0eec-3bb1-485a-ab88-9b11c6b9a5bd
Finish -> Thread name is reactor-http-epoll-3, date is Sat May 16 19:07:14 BRT 2020.
問題是一個 chrome 問題,像“Martin Tarjányi”在他的評論中說的那樣,我的請求已經排隊:
您是否從 Chrome 瀏覽器訪問了端點? 我遇到了類似的問題,但不確定原因。 不過,我記得它在 Firefox 或 Edge 中運行良好。 您也可以從另一個應用程序以編程方式調用它。 編輯:stackoverflow.com/a/53236741/6051176
非常感謝@Martin Tarjányi
使用其他客戶端請求或更改參數效果很好。 相同的資源 chrome 會將請求排隊。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.