I have a very simple aggregation code in pyflink :...
# troubleshooting
p
I have a very simple aggregation code in pyflink :
Copy code
aggregated_stream: DataStream = (signal_stream
    .key_by(lambda asset_metric: (asset_metric['turbine_id'],
                                  asset_metric['farm_id'],
                                  asset_metric['signal_name']))
    .window(TumblingProcessingTimeWindows.of(Time.seconds(30)))
    .aggregate(
        SignalAverageAggregateFunction(),
        AddWindowMetadata()
    ))
And my memory usage is continuously growing:
p
The first step is to find out where this leak is coming from. Based on the window size I think it is not related to it.
p
This is the second step in my code, and started the memory growth continuously. As you can see in the picture in the first step there was no grow
p
What is your second step doing?
p
First: signal_stream: DataStream = ( data_stream .flat_map(lambda record_list: json.loads(record_list)) .flat_map(FilterAndFlattenTurbineData(valid_temps)) ) Second: ------------------------------- aggregated_stream: DataStream = (signal_stream .key_by(lambda asset_metric: (asset_metric['turbine_id'], asset_metric['farm_id'], asset_metric['signal_name'])) .window(TumblingProcessingTimeWindows.of(Time.seconds(30))) .aggregate( SignalAverageAggregateFunction(), AddWindowMetadata() )) aggregated_stream.print() The methods: class SignalAverageAggregateFunction(AggregateFunction): def create_accumulator(self) -> (float, int): return 0.0, 0 # (sum, count) def add(self, value, accumulator) -> (float, int): return accumulator[0] + value['value'], accumulator[1] + 1 def get_result(self, accumulator) -> (float, int): return accumulator def merge(self, a, b) -> (float, int): return a[0] + b[0], a[1] + b[1] class AddWindowMetadata(WindowFunction): def apply(self, key: KEY, window: W, inputs) -> dict: turbine_id, farm_id, signal_name = key value, count = inputs[0] yield { 'turbine_id': turbine_id, 'farm_id': farm_id, 'signal_name': signal_name, 'value': value, 'count': count }
is it possible to this configuration is fixing my problem: env.enable_checkpointing(60000)
p
Nice! Did it work?
p
🙂 no it is not
p
p
I did a refactor and run a daily test: So the memory issue is not coming from the json parse.