如何处理来自REST服务的大量数据 [英] How to handle huge data from a REST service

查看:287
本文介绍了如何处理来自REST服务的大量数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用返回大量数据的REST服务。
在生产中,服务器硬件可以处理它。
我需要通过获取本地计算机上的数据来测试REST服务,
无法处理大量数据。
我的本地机器是4G i5。
我每次点击服务时都会出现内存异常。

We are using a REST service that returns huge data. In production, the server hardware can handle it. I need to test the REST service by getting the data on my local machine, which cannot handle the huge data. My local machine is a 4G i5. I am getting out of memory exception every time I hit the service.

response.getStatus()返回200状态。
但是在使用输入流阅读器收集数据时,我得到了内存不足的异常。

response.getStatus() returns 200 status. But while collecting the data using input stream reader, I get an out of memory exception.

BufferedReader br = new BufferedReader(new
InputStreamReader(newByteArrayInputStream(response.getEntity().getBytes())));

有没有其他方法来收集数据而不会遇到内存异常?

Is there any other way to collect the data without hitting the memory exception?

我尝试将我的VM大小推到2G,但仍然无效。

I tried pushing my VM size to 2G but, it still doesn't work.

推荐答案

如果服务支持,请使用请求的HTTP标准方法在整个响应内容有效负载范围内的块

If the service supports it, use the HTTP standard approach of requesting chunks within the range of the entire response content payload.

另一种方法(再次,假设API支持它)是分页

Another approach (again, assuming the API supports it) is pagination.

这篇关于如何处理来自REST服务的大量数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆