[英]Php - Symfony2 - Rest api - huge data
I have a quite conceptual question about working with APIs which handle huge amount of data. 关于使用处理大量数据的API,我有一个非常概念性的问题。
I have two web applications running: 我有两个正在运行的Web应用程序:
both use RESTful API to communicate with each other. 两者都使用RESTful API相互通信。
Now it comes to sending huge amounts of data (about 1 million rows) from A to B. 现在是从A到B发送大量数据(约100万行)的时候。
My concept is to select all data from database and ie create one main-array with 1 million subarrays. 我的概念是从数据库中选择所有数据,即创建一个具有100万个子阵列的主阵列。 Next iterate through the main-array to get every single row and send this specific row as Post-Request to System B.
接下来遍历主数组以获取每一行,并将此特定行作为“后请求”发送给系统B。
Code Sample: 代码示例:
$data = $sql-to-get-all-data;
$mainArray = $data->fetchAll();
foreach ($mainArray as $subArray) {
$row = $subArray;
// create post request and send $row to System B
}
Next I would need to check if the row already exists in System B. If it does, send an Update-Request instead of a Post-Request. 接下来,我将需要检查系统B中是否已存在该行。如果存在,则发送更新请求而不是后请求。 Also ... if there is a row which exists in System B, but does not exist in System A, it should be removed from System A.
另外...如果系统B中存在一行,但系统A中不存在,则应将其从系统A中删除。
My question is: 我的问题是:
Is this the right way to go with? 这是正确的方法吗? Should I think about concepts like parallel processing / multithreading?
我是否应该考虑诸如并行处理/多线程的概念?
You should use offset and limit in your db query. 您应该在数据库查询中使用offset和limit。 Storing entire dataset in a PHP array is a really bad idea.
将整个数据集存储在PHP数组中是一个非常糟糕的主意。
You can send subsets in batches and return id lists (added/updated/removed) within response. 您可以批量发送子集,并在响应中返回ID列表(添加/更新/删除)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.