Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-12717][PYTHON][BRANCH-2.1] Adding thread-safe broadcast pickle registry #18825

Conversation

BryanCutler
Copy link
Member

What changes were proposed in this pull request?

When using PySpark broadcast variables in a multi-threaded environment, SparkContext._pickled_broadcast_vars becomes a shared resource. A race condition can occur when broadcast variables that are pickled from one thread get added to the shared _pickled_broadcast_vars and become part of the python command from another thread. This PR introduces a thread-safe pickled registry using thread local storage so that when python command is pickled (causing the broadcast variable to be pickled and added to the registry) each thread will have their own view of the pickle registry to retrieve and clear the broadcast variables used.

How was this patch tested?

Added a unit test that causes this race condition using another thread.

added regression test for multithreaded broadcast pickle
@BryanCutler
Copy link
Member Author

backport for 2.1

@HyukjinKwon
Copy link
Member

LGTM if it passes the tests.

@BryanCutler BryanCutler changed the title [SPARK-12717][PYTHON] Adding thread-safe broadcast pickle registry [SPARK-12717][PYTHON][BRANCH-2.1] Adding thread-safe broadcast pickle registry Aug 2, 2017
@BryanCutler
Copy link
Member Author

Since it seemed like some users in the JIRA might be using 2.1, I made this PR too. I think this is pretty low risk also, and it went in without any conflicts. But up to you if you're ok with this one also, as long as tests pass.

@SparkQA
Copy link

SparkQA commented Aug 3, 2017

Test build #80181 has finished for PR 18825 at commit cc239a4.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • class BroadcastPickleRegistry(threading.local):

asfgit pushed a commit that referenced this pull request Aug 3, 2017
… registry

## What changes were proposed in this pull request?

When using PySpark broadcast variables in a multi-threaded environment,  `SparkContext._pickled_broadcast_vars` becomes a shared resource.  A race condition can occur when broadcast variables that are pickled from one thread get added to the shared ` _pickled_broadcast_vars` and become part of the python command from another thread.  This PR introduces a thread-safe pickled registry using thread local storage so that when python command is pickled (causing the broadcast variable to be pickled and added to the registry) each thread will have their own view of the pickle registry to retrieve and clear the broadcast variables used.

## How was this patch tested?

Added a unit test that causes this race condition using another thread.

Author: Bryan Cutler <cutlerb@gmail.com>

Closes #18825 from BryanCutler/pyspark-bcast-threadsafe-SPARK-12717-2_1.
@HyukjinKwon
Copy link
Member

Merged into branch-2.1.

@BryanCutler BryanCutler closed this Aug 3, 2017
@BryanCutler BryanCutler deleted the pyspark-bcast-threadsafe-SPARK-12717-2_1 branch November 19, 2018 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants