pyspark-spy
Collect and aggregate on spark events for profitz. In 🐍 way!
Installation
pip install pyspark-spy
How to
You register a listener
import pyspark_spy
listener = pyspark_spy.PersistingSparkListener()
pyspark_spy.register_listener(spark_context, listener)
Execute your spark job as usual
spark_context.range(1, 100).count()
And you have all metrics collected!
print(listener.stage_output_metrics_aggregate())
OutputMetrics(bytesWritten=12861, recordsWritten=2426)
Look Ma, no actions!
Tested on python 3.5 - 3.7 and pyspark 2.3 - 3.0
Available listeners
-
pyspark_spy.interface.SparkListener- Base listener class. It defineson_spark_event(event_name, java_event)method that you can implement yourself for custom logic when any event is received. -
LoggingSparkListener- just logs event names received into supplied or automatically created logger. -
StdoutSparkListener- writes event names into stdout -
PersistingSparkListener- saves spark events into internal buffer -
ContextSparkListener- same as PersistingSparkListener but also allows you to record only events occured within python context manager scope. More on that later
PersistingSparkListener
Spark events collected (as java objects):
- applicationEnd
- applicationStart
- blockManagerRemoved
- blockUpdated
- environmentUpdate
- executorAdded
- executorMetricsUpdate
- executorRemoved
- jobEnd
- jobStart
- otherEvent
- stageCompleted
- stageSubmitted
- taskEnd
- taskGettingResult
- taskStart
- unpersistRDD
listener.java_events['executorMetricsUpdate'] # -> List of py4j java objects
View all possible spark events and their fields https://spark.apache.org/docs/2.3.1/api/java/org/apache/spark/scheduler/SparkListener.html
Events converted to python objects:
- jobEnd
- stageCompleted
listener.python_events['jobEnd'] # -> List of java events converted to typed namedtuples.
listener.jobEnd # same
Available aggregations
Only in PersistingSparkListener and ContextSparkListener
stage_input_metrics_aggregate- sums up allstageCompletedevent inputMetrics into one
print(listener.stage_input_metrics_aggregate())
InputMetrics(bytesRead=21574, recordsRead=584)
stage_output_metrics_aggregate- sums up allstageCompletedevent outputMetrics into one
print(listener.stage_output_metrics_aggregate())
OutputMetrics(bytesWritten=12861, recordsWritten=2426)
ContextSparkListener
To collect events from different actions and to build separate aggregations, use ContextSparkListener.
listener = ContextSparkListener()
register_listener(sc, listener)
with listener as events: # events is basically another listener
run_spark_job()
events.stage_output_metrics_aggregate() # events collected only within context manager
with listener as events_2:
run_other_spark_job()
events_2.stage_output_metrics_aggregate() # metrics collected during second job
listener.stage_output_metrics_aggregate() # metrics collected for all jobs
Metadata
Release files for pyspark-spy 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyspark-spy-1.0.2.tar.gz | 6.5 kB | Without provenance | Details for pyspark-spy-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyspark_spy-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for pyspark_spy-1.0.2-py3-none-any.whl |
Total release size: 13.6 kB
Release files / pyspark-spy-1.0.2.tar.gz
| Download URL | pyspark-spy-1.0.2.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6d74365dadd08828cf0f3f98aecd64653cb666d6fd514b618430278194d63787
|
|
BLAKE2b-256 checksum How to use checksums |
afab44488795622330da40eea8897fb907d05bd6cad1cd6059d69cd0b9449a3f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.5 CPython/3.8.2 Darwin/20.3.0
|
Release files / pyspark_spy-1.0.2-py3-none-any.whl
| Download URL | pyspark_spy-1.0.2-py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9071ea457b24fe3cb7b3a8ee45e3d2de98b085c28e60263b4afefc0e9c37e80f
|
|
BLAKE2b-256 checksum How to use checksums |
1a93958eca02ecca4ffadfcab41b16f084333681a2ce6ad8e712e754610b0793
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.5 CPython/3.8.2 Darwin/20.3.0
|
Security for pyspark-spy 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.