因此,在进一步调查后,在
Spring-Data组件中发现了问题。
为了克服这个问题,我们必须转向 非阻塞机制 。
我们做了两件事:
- 从控制器层到服务和存储库层的所有调用已更改为
CompleteableFuture<Cat>
为了绕过Spring-Data与Couchbase的连接,我们使用实现代码创建了自己的存储库类,该实现代码如下所示:
Statement statement = select("*") .from(i(bucket.name())) .where(x("name").eq(s(name)) .and(x("ownerId").eq(s(ownerId))) .and(x("color").eq(s(color))) .and(x("_class").eq(s("com.example.Cat"))));CompletableFuture
completableFuture = new CompletableFuture();
bucket.async().query(statement)
…
完成此操作后,即使在大约数百个并发请求期间,延迟问题也消失了,查询性能约为 2毫秒 。



