riteshghorse commented on code in PR #30696:
URL: https://github.com/apache/beam/pull/30696#discussion_r1534029897
##########
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:
I think current cache size could be fetched with `self._state_cache.size()`
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]