在大型数据集上执行会话窗口时,Apache Beam作业失败

时间:2019-06-10 18:41:49

标签: python google-cloud-platform window google-cloud-dataflow apache-beam

我正在处理Python Apache Beam作业,并在有限数据集上进行会话窗口处理。它适用于小型数据集,但是当我增加输入数据的大小时,这项工作就会死掉。

工作ID为2019-06-10_07_28_32-2942508228086251217

elements = (p | 'IngestData' >> beam.io.Read(big_query_source))

        elements | 'AddEventTimestamp' >> beam.ParDo(AddTimestampDoFn()) \
                        | 'SessionWindow' >> beam.WindowInto(window.Sessions(10 * 60)) \
                        | 'CreateTuple' >> beam.Map(lambda row: (row['id'], {'attribute1': row['attribute1'], 'date': row['date']})) \
                        | 'GroupById1' >> beam.GroupByKey() \
                        | 'AggregateSessions' >> beam.ParDo(AggregateTransactions()) \
                        | 'MergeWindows' >> beam.WindowInto(window.GlobalWindows()) \
                        | 'GroupById2' >> beam.GroupByKey() \
                        | 'MapSessionsToLists' >> beam.Map(lambda x: (x[0], [y for y in x[1]])) \
                        | 'BiggestSession' >> beam.ParDo(MaximumSession()) \
                        | "PrepForWrite" >> beam.Map(lambda x: x[1].update({"id": x[0]}) or x[1]) \
                        | 'WriteResult' >> WriteToText(known_args.output)

使用DoFn类

class AddTimestampDoFn(beam.DoFn):
    def process(self, element):
        date = datetime.datetime.strptime(element['date'][:-4], '%Y-%m-%d %H:%M:%S.%f')
        unix_timestamp = float(date.strftime('%s'))
        yield beam.window.TimestampedValue(element, unix_timestamp)


class AggregateTransactions(beam.DoFn):
    def process(self, element, window=beam.DoFn.WindowParam):
        session_count = len(element[1])
        attributes = list(map(lambda row: row['attribute1'], element[1]))
        std = np.std(amounts)

        return [(element[0], {'session_count': session_count, 'session_std': std, 'window_start': window.start
                                                                                    .to_utc_datetime()
                                                                                    .strftime('%d-%b-%Y %H:%M:%S')})]


class MaximumSession(beam.DoFn):
    def process(self, element):
        sorted_counts = sorted(element[1], key = lambda x: x['session_count'], reverse=True)

        return [(element[0], {'session_count': sorted_counts[0]['session_count'], 
                                        'session_std': sorted_counts[0]['session_std'], 
                                        'window_start_time': sorted_counts[0]['window_start']})]

工作失败,并给我这个错误:The job failed because a work item has failed 4 times. Look in previous log entries for the cause of each one of the 4 failures. For more information, see https://cloud.google.com/dataflow/docs/guides/common-errors. The work item was attempted on these workers:

登录栈驱动程序的特定工作人员没有任何提示。我只是得到这些条目的组合:

processing lull for over 431.44 seconds in state process-msecs in step s5

Refusing to split <dataflow_worker.shuffle.GroupedShuffleRangeTracker object at 0x7f82e970cbd0> at '\n\xaaG\t\x00\x01': proposed split position is out of range

Retry with exponential backoff: waiting for 4.69305060273 seconds before retrying lease_work because we caught exception: SSLError: ('The read operation timed out',)

其余条目仅供参考。

该特定工作线程的最新内存使用为43413 MB。由于我使用的是n1-highmem-32机器,因此我认为这里的内存可能不是问题。

在客户端,Cloud Shell,在我触发该工作的地方,我得到了很多

INFO:oauth2client.transport:Refreshing due to a 401 (attempt 1/2)
INFO:oauth2client.transport:Refreshing due to a 401 (attempt 2/2)
INFO:oauth2client.transport:Refreshing due to a 401 (attempt 1/2)
INFO:oauth2client.transport:Refreshing due to a 401 (attempt 1/2)
INFO:oauth2client.transport:Refreshing due to a 401 (attempt 2/2)
INFO:oauth2client.transport:Refreshing due to a 401 (attempt 2/2)
INFO:oauth2client.transport:Refreshing due to a 401 (attempt 1/2)
INFO:oauth2client.transport:Refreshing due to a 401 (attempt 2/2)

作业崩溃之前。

有什么想法吗?

谢谢

1 个答案:

答案 0 :(得分:0)

默认情况下,如果在BATCH模式下出现任何错误,则Dataflow重试管道4次,而在STREAM模式下运行时,无限期重试管道。

请在用于管道的计算引擎计算机的堆栈驱动程序中创建仪表板,以分析正在发生的内存,CPU消耗和IO操作量。在仔细分析上述因素后,应提高管道的配置。

请确保根据您提供的数据进行所有转换,并进行异常处理。