You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "tvalentyn (via GitHub)" <gi...@apache.org> on 2023/08/31 00:35:01 UTC

[GitHub] [beam] tvalentyn opened a new issue, #28246: [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.50.0 SDKs.

tvalentyn opened a new issue, #28246:
URL: https://github.com/apache/beam/issues/28246

   ### What happened?
   
   We have identified a memory leak that affects Beam Python SDK versions 2.47.0 and above. We expect the leak to be fully remediated in Beam 2.51.0.
   
   **Mitigation**
   
   Until Beam 2.51.0 is released, consider any of the following workarounds:
   
   * Use apache-beam==2.46.0 or below.
   * Install protobuf 3.x in the submission and runtime environment. For example, you can use a `--requirements_file` pipeline option with a file that includes:   
     ```
     protobuf==3.20.3
     grpcio-status==1.48.2
     ```
     For more information, see: https://beam.apache.org/documentation/sdks/python-pipeline-dependencies/
   
   * Use a python implementation of protobuf by setting a `PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python` environment variable in the runtime environment. For example, you could create a custom Beam SDK container from a Dockerfile that looks like the following:
   
     ```
     FROM gcr.io/cloud-dataflow/v1beta3/python310-fnapi:2.47.0
     ENV PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
     ```
     For more information, see: https://beam.apache.org/documentation/runtime/environments/
   
   
   * Install an updated version of protobuf dependency once released (see below).
   
   **Additional details**
   
   The leak can be reproduced by a pipeline:
   
   ```
     with beam.Pipeline(options=pipeline_options) as p:
       # duplicate reads to increase throughput
       inputs = []
       for i in range(32):
         inputs.append(
             p | f"Read pubsub{i}" >> ReadFromPubSub(topic='projects/pubsub-public-data/topics/taxirides-realtime', with_attributes=True)
         )
   
       inputs | beam.Flatten()
   ```
   
   The leak was triggered by Beam switching default `protobuf` package version from 3.19.x to 4.22.x in https://github.com/apache/beam/pull/24599. The new versions of `protobuf` also switched the default protobuf implemetation to a `upb` implementation.  The `upb` implementation had two known leaks that have since been mitigated by protobuf team in: https://github.com/protocolbuffers/protobuf/issues/10088, https://github.com/protocolbuffers/upb/issues/1243 . The latest available `protobuf==4.24.2` does not yet have the fix, but we have confirmed that using a patched  version built in https://github.com/protocolbuffers/upb/actions/runs/6028136812 fixes the leak.
   
   
   
   
   
   ### Issue Priority
   
   Priority: 2 (default / most bugs should be filed as P2)
   
   ### Issue Components
   
   - [X] Component: Python SDK
   - [ ] Component: Java SDK
   - [ ] Component: Go SDK
   - [ ] Component: Typescript SDK
   - [ ] Component: IO connector
   - [ ] Component: Beam examples
   - [ ] Component: Beam playground
   - [ ] Component: Beam katas
   - [ ] Component: Website
   - [ ] Component: Spark Runner
   - [ ] Component: Flink Runner
   - [ ] Component: Samza Runner
   - [ ] Component: Twister2 Runner
   - [ ] Component: Hazelcast Jet Runner
   - [ ] Component: Google Cloud Dataflow Runner


-- 
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-unsubscribe@beam.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] chleech commented on issue #28246: [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.50.0 SDKs.

Posted by "chleech (via GitHub)" <gi...@apache.org>.
chleech commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1710852446

   I'm trying to install [protobuf version 4.24.3](https://pypi.org/project/protobuf/4.24.3/) which contains the fixed based on [](https://github.com/protocolbuffers/protobuf/releases/tag/v24.3)
   
   ```
   Added malloc_trim() calls to Python allocator so RSS will decrease when memory is freed (https://github.com/protocolbuffers/upb/commit/b0f5d5d94d9faafed2ab0fcaa9396cb4a984a2c1)
   ```
   
   However, apache beam 2.50.0 depends on protobuf (>=3.20.3,<4.24.0). Is this [comment](https://github.com/apache/beam/issues/28246#issuecomment-1710504445) meant to address that?


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] chleech commented on issue #28246: [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.50.0 SDKs.

Posted by "chleech (via GitHub)" <gi...@apache.org>.
chleech commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1711020535

   > @chleech note that you need to install the new version of protobuf also in the runtime environment.
   
   Got it thank you! Actually, is it possible to only install it in the runtime env and not the build time one?


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] tvalentyn commented on issue #28246: [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.50.0 SDKs.

Posted by "tvalentyn (via GitHub)" <gi...@apache.org>.
tvalentyn commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1714779169

   @chleech which Python version are you using by chance? I encourage you to try other mitigations above in the meantime.


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] tvalentyn commented on issue #28246: [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.50.0 SDKs.

Posted by "tvalentyn (via GitHub)" <gi...@apache.org>.
tvalentyn commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1730305147

   i meant the leak might carry over to 2.51.0 unless i find a fix before the release and CP it.


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] chleech commented on issue #28246: [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.50.0 SDKs.

Posted by "chleech (via GitHub)" <gi...@apache.org>.
chleech commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1711802360

   @tvalentyn I'm trying to build a runtime image using `FROM apache/beam_python3.9_sdk:2.50.0` but I'm getting this error when I run `pip check`
   
   ```
   Step #1 - "Build runtime container image":   Attempting uninstall: typing-extensions
   Step #1 - "Build runtime container image":     Found existing installation: typing_extensions 4.5.0
   Step #1 - "Build runtime container image":     Uninstalling typing_extensions-4.5.0:
   Step #1 - "Build runtime container image":       Successfully uninstalled typing_extensions-4.5.0
   ```
   
   is this a known issue?


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] tvalentyn commented on issue #28246: [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.50.0 SDKs.

Posted by "tvalentyn (via GitHub)" <gi...@apache.org>.
tvalentyn commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1712376412

   Unfortunately I am still seeing a leak on `protobuf==4.24.3`, asked in https://github.com/protocolbuffers/protobuf/issues/10088#issuecomment-1712375991 . 


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] tvalentyn commented on issue #28246: [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.50.0 SDKs.

Posted by "tvalentyn (via GitHub)" <gi...@apache.org>.
tvalentyn commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1716514452

   > were you able to get this to work with beam 2.48.0? the last I tried it didn't change anything
   
   Yes, I tried that couple of times, it has an effect in the pipelines I run. The memory growth decreases significantly.


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] tvalentyn commented on issue #28246: [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.50.0 SDKs.

Posted by "tvalentyn (via GitHub)" <gi...@apache.org>.
tvalentyn commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1710861944

   > However, apache beam 2.50.0 depends on protobuf (>=3.20.3,<4.24.0). Is this comment meant to address that?
   
   you should be able to force-install the newer version without adverse effects in this case.
   
   Beam community produces a release roughly every 6 weeks.  
   


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.50.0 SDKs. [beam]

Posted by "tvalentyn (via GitHub)" <gi...@apache.org>.
tvalentyn commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1762257690

   The memory appears to be lost when creating a references here: https://github.com/apache/beam/blob/47d0fd566f86aaad35d26709c52ee555381823a4/sdks/python/apache_beam/runners/worker/bundle_processor.py#L1189C1-L1190C32 , even if we don't collect any metrics.
   
   Filed https://github.com/protocolbuffers/upb/issues/1526 with a repro for protobuf folks to take a further look.


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] tvalentyn commented on issue #28246: [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.50.0 SDKs.

Posted by "tvalentyn (via GitHub)" <gi...@apache.org>.
tvalentyn commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1730102388

   It's not yet fixed and we don't have a cherry-pick yet unfortunately, it will likely carry over to 2.51.0


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.51.0 SDKs. [beam]

Posted by "damccorm (via GitHub)" <gi...@apache.org>.
damccorm commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1791483268

   It will be in version 2.52.0, which should be released in the next few weeks.


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] kennknowles commented on issue #28246: [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.50.0 SDKs.

Posted by "kennknowles (via GitHub)" <gi...@apache.org>.
kennknowles commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1729825978

   What is the status of this? The release branch is cut but we can cherry pick a fix if it would otherwise make 2.51.0 unusable.


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.51.0 SDKs. [beam]

Posted by "damccorm (via GitHub)" <gi...@apache.org>.
damccorm closed issue #28246: [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.51.0 SDKs.  
URL: https://github.com/apache/beam/issues/28246


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] tvalentyn commented on issue #28246: [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.50.0 SDKs.

Posted by "tvalentyn (via GitHub)" <gi...@apache.org>.
tvalentyn commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1707398088

   Users of Beam 2.50.0 SDK should additionally follow mitigation options for https://github.com/apache/beam/issues/28246. (also mentioned in the description).


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.50.0 SDKs. [beam]

Posted by "tvalentyn (via GitHub)" <gi...@apache.org>.
tvalentyn commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1758607944

   I can confirm with fairly high confidence that memory is leaking during execution metrics collection in https://github.com/apache/beam/blob/104c10b3ee536a9a3ea52b4dbf62d86b669da5d9/sdks/python/apache_beam/runners/worker/bundle_processor.py#L1188-L1192 ; I should have more info soon. 


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] kennknowles commented on issue #28246: [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.50.0 SDKs.

Posted by "kennknowles (via GitHub)" <gi...@apache.org>.
kennknowles commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1730247357

   You mean 2.52.0?


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] chleech commented on issue #28246: [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.50.0 SDKs.

Posted by "chleech (via GitHub)" <gi...@apache.org>.
chleech commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1711846057

   I'm getting dependency conflict when trying to build a runtime image with
   ```
   FROM apache/beam_python3.9_sdk:2.50.0
   
   ARG WORKDIR=/dataflow/container
   ARG TEMPLATE_NAME=none
   RUN mkdir -p ${WORKDIR}
   WORKDIR ${WORKDIR}
   
   RUN pip install --no-cache-dir --upgrade pip \
     && pip install --no-cache-dir poetry \
     && pip check
   ```
   
   It's failing with 
   
   ```
   tensorflow 2.13.0 has requirement typing-extensions<4.6.0,>=3.6.6, but you have typing-extensions 4.7.1.
   ```
   
   is this a known issue?


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] chleech commented on issue #28246: [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.50.0 SDKs.

Posted by "chleech (via GitHub)" <gi...@apache.org>.
chleech commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1714014761

   > Unfortunately I am still seeing a leak on `protobuf==4.24.3`, asked in [protocolbuffers/protobuf#10088 (comment)](https://github.com/protocolbuffers/protobuf/issues/10088#issuecomment-1712375991) .
   
   Same here! I let the pipeline run for 3 days and still got this plot. Am glad that I am not the only one.
   
   My set up is
   - beam 2.50.0
   - `RUN pip install --force-reinstall -v "protobuf==4.24.3"`
   
   <img width="1317" alt="image" src="https://github.com/apache/beam/assets/106762739/c0d06f86-6074-43ef-88b2-5c61242cb7ad">
   


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] chleech commented on issue #28246: [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.50.0 SDKs.

Posted by "chleech (via GitHub)" <gi...@apache.org>.
chleech commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1716148681

   were you able to get this to work with beam 2.48.0? the last I tried it didn't change anything
   
   ```
   FROM apache/beam_python3.10_sdk:2.47.0
   ENV PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
   ```


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.51.0 SDKs. [beam]

Posted by "chleech (via GitHub)" <gi...@apache.org>.
chleech commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1791426919

   @tvalentyn which version of apache beam should we use to get the mem fix?


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] tvalentyn commented on issue #28246: [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.50.0 SDKs.

Posted by "tvalentyn (via GitHub)" <gi...@apache.org>.
tvalentyn commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1710504445

   Remaining work: updgrade protobuf lower bound once their fixes are released.


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] tvalentyn commented on issue #28246: [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.50.0 SDKs.

Posted by "tvalentyn (via GitHub)" <gi...@apache.org>.
tvalentyn commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1710874372

   @chleech note that you need to install the new version of protobuf also in the runtime environment.


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] tvalentyn commented on issue #28246: [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.50.0 SDKs.

Posted by "tvalentyn (via GitHub)" <gi...@apache.org>.
tvalentyn commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1712377743

   > I'm getting dependency conflict when trying to build a runtime image with
   > ...
   > is this a known issue?
   
   Must be side effects from poetry installation. See: https://beam.apache.org/documentation/sdks/python-pipeline-dependencies/#control-dependencies for tips on using constraint files that might help.
   
   ```
   docker run --rm -it --entrypoint=/bin/bash apache/beam_python3.9_sdk:2.50.0
   root@710cb268df2a:/# pip check
   No broken requirements found.
   ```


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] chleech commented on issue #28246: [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.50.0 SDKs.

Posted by "chleech (via GitHub)" <gi...@apache.org>.
chleech commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1736096338

   hey @tvalentyn - any luck fixing the mem issue in 2.51.0?


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug]: [Python SDK] Memory leak in 2.47.0 - 2.50.0 SDKs. [beam]

Posted by "chleech (via GitHub)" <gi...@apache.org>.
chleech commented on issue #28246:
URL: https://github.com/apache/beam/issues/28246#issuecomment-1758631398

   @tvalentyn that sounds really promising. thank you for your hard work, can't wait!


-- 
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-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org