[英]How to combine streaming data with large history data set in Dataflow/Beam
我正在调查通过 Google Dataflow/Apache Beam 处理来自网络用户会话的日志,并且需要将用户的日志(流式传输)与上个月的用户会话历史记录结合起来。
我研究了以下方法:
processElement(ProcessContext processContext)
给定element
的用户会话历史记录我的理解是通过.withSideInputs(pCollectionView)
加载的数据需要适合内存。 我知道我可以将单个用户的所有会话历史记录放入内存中,但不能将所有会话历史记录放入内存中。
我的问题是是否有办法从仅与当前用户会话相关的侧输入加载/流式传输数据?
我正在想象一个 parDo 函数,它将通过指定用户的 ID 从侧面输入加载用户的历史会话。 但只有当前用户的历史会话才能放入内存; 通过侧输入加载所有历史会话会太大。
一些伪代码来说明:
public static class MetricFn extends DoFn<LogLine, String> {
final PCollectionView<Map<String, Iterable<LogLine>>> pHistoryView;
public MetricFn(PCollectionView<Map<String, Iterable<LogLine>>> historyView) {
this.pHistoryView = historyView;
}
@Override
public void processElement(ProcessContext processContext) throws Exception {
Map<String, Iterable<LogLine>> historyLogData = processContext.sideInput(pHistoryView);
final LogLine currentLogLine = processContext.element();
final Iterable<LogLine> userHistory = historyLogData.get(currentLogLine.getUserId());
final String outputMetric = calculateMetricWithUserHistory(currentLogLine, userHistory);
processContext.output(outputMetric);
}
}
目前还没有一种方法可以访问流中的每个键侧输入,但它肯定会如您所描述的那样有用,而且我们正在考虑实施它。
一种可能的解决方法是使用侧输入来分发指向实际会话历史记录的指针。 生成 24 小时会话历史的代码可以将它们上传到 GCS/BigQuery/等,然后将位置作为附加输入发送到加入代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.