A proof of concept asynchronous actions for PySpark using concurent.futures
Project description
A proof of concept asynchronous actions for PySpark using concurent.futures Originally developed as proof-of-concept solution for SPARK-20347
How does it work?
The package patches RDD, DataFrame and DataFrameWriter classes by adding thin wrappers to the commonly used action methods.
Methods are patched by retrieving shared ThreadPoolExecutor (attached to SparkContext) and applying its submit method:
def async_action(f):
def async_action_(self, *args, **kwargs):
executor = get_context(self)._get_executor()
return executor.submit(f, self, *args, **kwargs)
return async_action_
The naming convention for the patched methods is methodNameAsync, for example:
RDD.count ⇒ RDD.countAsync
DataFrame.take ⇒ RDD.takeAsync
DataFrameWriter.save ⇒ DataFrameWriter.saveAsync
Number of threads is determined as follows:
spark.driver.cores is set.
2 otherwise.
Usage
To patch existing classes just import the package:
>>> import asyncactions
>>> from pyspark.sql import SparkSession
>>>
>>> spark = SparkSession.builder.getOrCreate()
All *Async methods return concurrent.futures._base.Future:
>>> rdd = spark.sparkContext.range(100)
>>> f = rdd.countAsync()
>>> f
<Future at ... state=running>
>>> type(f)
concurrent.futures._base.Future
and can be used when Future is expected.
Installation
The package is available on PYPI:
pip install pyspark-asyncactions
Installation is required only on the driver node.
Dependencies
The package supports Python 3.5 or later with a common codebase and requires no external dependencies.
It is also possible, but not supported, to use it with Python 2.7, using concurent.futures backport.
Disclaimer
Apache Spark, Spark, Apache, and the Spark logo are trademarks of The Apache Software Foundation. This project is not owned, endorsed, or sponsored by The Apache Software Foundation.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pyspark-asyncactions-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f88be2cda8f549b7deab42b84e51f13058bc3d6950a74f72905561215204a6a |
|
MD5 | c4e97ea0b690d114826e05c0bebb7b98 |
|
BLAKE2b-256 | 58ff3b3e09c8f74f0893b33bc0b5dfbdba76199808139cb2e9e2696d8f098a47 |
Hashes for pyspark_asyncactions-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13d6348fa52524a0ce1ed53e4a761cad9c769471a0286a5961d93feff6c94ed3 |
|
MD5 | cbaeaaf60459def766a32372dd53afd7 |
|
BLAKE2b-256 | 37a4b4acdb3928a2fa42df88af80e3398cfa8f85a0f5bb5e00692cc581494d10 |