球衣内存泄漏?



我有以下代码片段。 调用终结点时返回映像的简单服务。

@GET
@Path("/categories/{category}/image")
@Produces("image/jpeg")
@UnitOfWork
public StreamingOutput getCategoryImage(@PathParam("category")Category category){
//foo service will return an Optional
return fooService.getImage(category).map(new Function<InputStream, StreamingOutput>() {
@Override
public StreamingOutput apply(InputStream inputStream) {
return (StreamingOutput) output -> BarResource.this.copyAndClose(inputStream, output);
}
})
.orElseThrow(NotFoundException::new);
}

//Originally this method did not exist, but I am trying this to close the 'leak'
private long copyAndClose(InputStream inputStream, OutputStream outputStream) throws IOException{
try(InputStream temp = inputStream; OutputStream tempOut = outputStream) {
return IOUtils.copy(temp, tempOut);
}
}

然而,通过压力测试,我们调用了 1600 次/秒几秒钟,我们的 docker 容器中的内存使用量飙升(从大约 300 到超过一千演出(,我们将 Xmx 设置为 512,但内存继续攀升。

我在这里错过了什么吗? 我们正在使用Dropwizard和Jersey。

运行探查器后,我发现我们正在创建数千个对象来响应 FooService 中的此调用。 我们能够使它成为一个单例,这似乎已经解决了很多问题。

最新更新