简体   繁体   English

REST API设计-提取多个(1000)记录

[英]REST API Design - Fetching multiple(1000) records

I have a web application and have to fetch 1000 records using a REST API. 我有一个Web应用程序,必须使用REST API提取1000条记录。 Each record is around 500 bytes. 每条记录约为500个字节。

What is the best way to do it from the following and why? 以下是实现此目的的最佳方法是什么,为什么? Is there another better way to do it? 还有另一种更好的方法吗?

1>Fetch one record at a time. 1>一次获取一个记录。 Trigger 1000 calls in parallel. 并行触发1000个呼叫。

2>Fetch in groups of 20. Trigger 50 calls in parallel. 2>以20为一组获取。并行触发50个调用。

3>Fetch in groups of 100. Trigger 10 calls in parallel. 3>以100为一组提取。并行触发10个调用。

4>Fetch all 1000 records together. 4>一起提取所有1000条记录。

As @Dima said in the comments, it really depends on what you are trying to do. 正如@Dima在评论中所说,这实际上取决于您要执行的操作。

How are the records being consumed? 记录如何被使用?

  • Is it a back end process to process or program to program communication? 是要处理的程序还是要进行程序编程的后端程序? If so, then it depends on the difficulty of processing once the client receives it. 如果是这样,则取决于客户收到后处理的难度。 Is it going to take them a long time to process each record? 他们需要很长时间来处理每条记录吗? 1 ms per record, or 100ms per record? 每条记录1毫秒还是每条记录100毫秒? This option depends entirely on possible processing time per record. 此选项完全取决于每个记录可能的处理时间。

  • Is there a front end consuming this for human users? 有没有前端供人类用户使用? If so, batch requesting would be good for reasons like paginating results. 如果是这样,由于分页结果之类的原因,批量请求将是很好的。 In such cases, I would go with option 2 or 3 personally. 在这种情况下,我个人会选择选项2或3。

In general though, depending upon the sheer volume of records, I would recommend considering batching requests (by triggering fewer calls). 但总的来说,根据记录的数量,我建议考虑批量请求(通过触发较少的调用)。 Heuristically speaking, you are likely to get better overall network throughput that way. 试探性地讲,您可能会以这种方式获得更好的整体网络吞吐量。

If you add more specifics, I'll happily update my answer, but until then, general will have to do! 如果您添加更多细节,我会很乐意更新我的答案,但是在那之前,一般将不得不做!

Best for what case? 最适合什么情况? What are you trying to optimize? 您要优化什么?

I did some tests a while back on a similar situation, with slightly larger payloads (images), where my goal was to utilize network efficiently on a high-latency setup (across continents). 我在类似的情况下做了一些测试,有效载荷(图像)稍大,我的目标是在高延迟设置(跨大洲)上有效地利用网络。

My results were that after a minimal amount of parallelism (like 3-4 threads), the network was almost perfectly saturated. 我的结果是,经过最少的并行处理(例如3-4个线程),网络几乎完全饱和。 We compared it to specific (proprietary) UDP-based transfer protocols, and there was no measurable difference. 我们将其与基于UDP的特定(专有)传输协议进行了比较,并且没有可测量的差异。

Anyway, it may be not what you are looking for, but sometimes having a "dumb" http endpoint is good enough. 无论如何,它可能不是您要查找的内容,但有时具有一个“哑” http端点就足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM