-
Notifications
You must be signed in to change notification settings - Fork 28.3k
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-3721] [PySpark] broadcast objects larger than 2G #2659
Conversation
QA tests have started for PR 2659 at commit
|
QA tests have finished for PR 2659 at commit
|
Test FAILed. |
QA tests have started for PR 2659 at commit
|
QA tests have finished for PR 2659 at commit
|
Test PASSed. |
SQL changes LGTM. |
Conflicts: python/run-tests
QA tests have started for PR 2659 at commit
|
QA tests have finished for PR 2659 at commit
|
Test PASSed. |
@@ -357,16 +357,23 @@ private[spark] object PythonRDD extends Logging { | |||
} | |||
} | |||
|
|||
def readBroadcastFromFile(sc: JavaSparkContext, filename: String): Broadcast[Array[Byte]] = { | |||
def readBroadcastFromFile(sc: JavaSparkContext, | |||
filename: String): Broadcast[Array[Array[Byte]]] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def readBroadcastFromFile(
sc: JavaSparkContext,
filename: String): Broadcast[...] = {
...
}
QA tests have started for PR 2659 at commit
|
QA tests have finished for PR 2659 at commit
|
Test PASSed. |
""" | ||
Compress the serialized data | ||
Read at most `limit` bytes from underline stream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
underline -> underlying
These changes look pretty good to me. Give me some time to try it out locally with a huge broadcast variable and to double-check that the index arithmetic is right. |
Do you have a script that I can run to test this? We should have a test that creates a huge broadcast variable, serializes it, then checks that the deserialized object contains the same data. This would catch any off-by-one errors in the chunking code that could otherwise lead to silent corruption of binary data. |
>>> rio.read() | ||
'Hello world' | ||
""" | ||
MAX_BATCH = 1 << 20 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment next to this line saying "1 megabyte"?
The code in the JIRA could be used for test this. |
Conflicts: python/pyspark/context.py
Test FAILed. |
QA tests have started for PR 2659 at commit
|
Tests timed out for PR 2659 at commit |
QA tests have started for PR 2659 at commit
|
QA tests have finished for PR 2659 at commit
|
Test build #23042 has started for PR 2659 at commit
|
Test build #23042 has finished for PR 2659 at commit
|
Test PASSed. |
@JoshRosen There are several people hit the problem with large broadcast in Python, could we make this into 1.2 release? |
Jenkins, retest this please. |
Test build #23275 has started for PR 2659 at commit
|
I guess this seems fine to me, since I think I reviewed it previously and it doesn't look like much has changed. It would be nice if there were more explanatory comments so that someone who knows nothing about this JIRA / code can figure out what's going on. On the other hand, PythonRDD already suffers from poor documentation, so I don't mind fixing this up myself in a subsequent pull request to add lots of comments / developer docs. Therefore, I'll probably merge this after Jenkins passes. |
Actually, one question: could you check some tests into |
Test build #23275 has finished for PR 2659 at commit
|
Test PASSed. |
@JoshRosen I will do that, we can verify it by checksum. |
@JoshRosen I add one more test for broadcast, will do more tests in scale in spark-perf. |
Test build #23331 has started for PR 2659 at commit
|
Test build #23331 has finished for PR 2659 at commit
|
Test PASSed. |
Going to merge this into (@davies is running large-scale |
This patch will bring support for broadcasting objects larger than 2G. pickle, zlib, FrameSerializer and Array[Byte] all can not support objects larger than 2G, so this patch introduce LargeObjectSerializer to serialize broadcast objects, the object will be serialized and compressed into small chunks, it also change the type of Broadcast[Array[Byte]]] into Broadcast[Array[Array[Byte]]]]. Testing for support broadcast objects larger than 2G is slow and memory hungry, so this is tested manually, could be added into SparkPerf. Author: Davies Liu <davies@databricks.com> Author: Davies Liu <davies.liu@gmail.com> Closes apache#2659 from davies/huge and squashes the following commits: 7b57a14 [Davies Liu] add more tests for broadcast 28acff9 [Davies Liu] Merge branch 'master' of github.com:apache/spark into huge a2f6a02 [Davies Liu] bug fix 4820613 [Davies Liu] Merge branch 'master' of github.com:apache/spark into huge 5875c73 [Davies Liu] address comments 10a349b [Davies Liu] address comments 0c33016 [Davies Liu] Merge branch 'master' of github.com:apache/spark into huge 6182c8f [Davies Liu] Merge branch 'master' into huge d94b68f [Davies Liu] Merge branch 'master' of github.com:apache/spark into huge 2514848 [Davies Liu] address comments fda395b [Davies Liu] Merge branch 'master' of github.com:apache/spark into huge 1c2d928 [Davies Liu] fix scala style 091b107 [Davies Liu] broadcast objects larger than 2G
This patch will bring support for broadcasting objects larger than 2G. pickle, zlib, FrameSerializer and Array[Byte] all can not support objects larger than 2G, so this patch introduce LargeObjectSerializer to serialize broadcast objects, the object will be serialized and compressed into small chunks, it also change the type of Broadcast[Array[Byte]]] into Broadcast[Array[Array[Byte]]]]. Testing for support broadcast objects larger than 2G is slow and memory hungry, so this is tested manually, could be added into SparkPerf. Author: Davies Liu <davies@databricks.com> Author: Davies Liu <davies.liu@gmail.com> Closes #2659 from davies/huge and squashes the following commits: 7b57a14 [Davies Liu] add more tests for broadcast 28acff9 [Davies Liu] Merge branch 'master' of github.com:apache/spark into huge a2f6a02 [Davies Liu] bug fix 4820613 [Davies Liu] Merge branch 'master' of github.com:apache/spark into huge 5875c73 [Davies Liu] address comments 10a349b [Davies Liu] address comments 0c33016 [Davies Liu] Merge branch 'master' of github.com:apache/spark into huge 6182c8f [Davies Liu] Merge branch 'master' into huge d94b68f [Davies Liu] Merge branch 'master' of github.com:apache/spark into huge 2514848 [Davies Liu] address comments fda395b [Davies Liu] Merge branch 'master' of github.com:apache/spark into huge 1c2d928 [Davies Liu] fix scala style 091b107 [Davies Liu] broadcast objects larger than 2G (cherry picked from commit 4a377af) Signed-off-by: Josh Rosen <joshrosen@databricks.com>
merged. |
Re-implement the Python broadcast using file: 1) serialize the python object using cPickle, write into disks. 2) Create a wrapper in JVM (for the dumped file), it read data from during serialization 3) Using TorrentBroadcast or HttpBroadcast to transfer the data (compressed) into executors 4) During deserialization, writing the data into disk. 5) Passing the path into Python worker, read data from disk and unpickle it into python object, until the first access. It fixes the performance regression introduced in #2659, has similar performance as 1.1, but support object larger than 2G, also improve the memory efficiency (only one compressed copy in driver and executor). Testing with a 500M broadcast and 4 tasks (excluding the benefit from reused worker in 1.2): name | 1.1 | 1.2 with this patch | improvement ---------|--------|---------|-------- python-broadcast-w-bytes | 25.20 | 9.33 | 170.13% | python-broadcast-w-set | 4.13 | 4.50 | -8.35% | Testing with 100 tasks (16 CPUs): name | 1.1 | 1.2 with this patch | improvement ---------|--------|---------|-------- python-broadcast-w-bytes | 38.16 | 8.40 | 353.98% python-broadcast-w-set | 23.29 | 9.59 | 142.80% Author: Davies Liu <davies@databricks.com> Closes #3417 from davies/pybroadcast and squashes the following commits: 50a58e0 [Davies Liu] address comments b98de1d [Davies Liu] disable gc while unpickle e5ee6b9 [Davies Liu] support large string 09303b8 [Davies Liu] read all data into memory dde02dd [Davies Liu] improve performance of python broadcast (cherry picked from commit 6cf5076) Signed-off-by: Josh Rosen <joshrosen@databricks.com>
Re-implement the Python broadcast using file: 1) serialize the python object using cPickle, write into disks. 2) Create a wrapper in JVM (for the dumped file), it read data from during serialization 3) Using TorrentBroadcast or HttpBroadcast to transfer the data (compressed) into executors 4) During deserialization, writing the data into disk. 5) Passing the path into Python worker, read data from disk and unpickle it into python object, until the first access. It fixes the performance regression introduced in #2659, has similar performance as 1.1, but support object larger than 2G, also improve the memory efficiency (only one compressed copy in driver and executor). Testing with a 500M broadcast and 4 tasks (excluding the benefit from reused worker in 1.2): name | 1.1 | 1.2 with this patch | improvement ---------|--------|---------|-------- python-broadcast-w-bytes | 25.20 | 9.33 | 170.13% | python-broadcast-w-set | 4.13 | 4.50 | -8.35% | Testing with 100 tasks (16 CPUs): name | 1.1 | 1.2 with this patch | improvement ---------|--------|---------|-------- python-broadcast-w-bytes | 38.16 | 8.40 | 353.98% python-broadcast-w-set | 23.29 | 9.59 | 142.80% Author: Davies Liu <davies@databricks.com> Closes #3417 from davies/pybroadcast and squashes the following commits: 50a58e0 [Davies Liu] address comments b98de1d [Davies Liu] disable gc while unpickle e5ee6b9 [Davies Liu] support large string 09303b8 [Davies Liu] read all data into memory dde02dd [Davies Liu] improve performance of python broadcast
This patch will bring support for broadcasting objects larger than 2G.
pickle, zlib, FrameSerializer and Array[Byte] all can not support objects larger than 2G, so this patch introduce LargeObjectSerializer to serialize broadcast objects, the object will be serialized and compressed into small chunks, it also change the type of Broadcast[Array[Byte]]] into Broadcast[Array[Array[Byte]]]].
Testing for support broadcast objects larger than 2G is slow and memory hungry, so this is tested manually, could be added into SparkPerf.