Abacn commented on code in PR #30696: URL: https://github.com/apache/beam/pull/30696#discussion_r1534080187
########## sdks/python/apache_beam/runners/worker/sdk_worker.py: ########## @@ -1272,14 +1277,40 @@ def _lazy_iterator( :return A generator which returns the next element if advanced. """ while True: - data, continuation_token = ( - self._underlying.get_raw(state_key, continuation_token)) - input_stream = coder_impl.create_InputStream(data) + input_stream, continuation_token = self._get_raw( + state_key, continuation_token) + while input_stream.size() > 0: yield coder.decode_from_stream(input_stream, True) if not continuation_token: break + def _get_raw(self, state_key, continuation_token): + """Call underlying get_raw with performance statistics and detection.""" + start_time = time.time() + + data, continuation_token = ( + self._underlying.get_raw(state_key, continuation_token)) + + input_stream = coder_impl.create_InputStream(data) + + self._retrieval_time += time.time() - start_time + self._get_raw_called += 1 + + if self._retrieval_time > self._warn_interval: + _LOGGER.warning( + f"Retrieving state {self._get_raw_called} times costed " + f"{self._retrieval_time:.0f} seconds. It may be due to insufficient " + "state cache size and/or frequent direct access of states.\n" Review Comment: phrased to more specific message. There is a INFO worker log like "Creating state cache with size 26214400" for every harness started -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@beam.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org