-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
138 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/scala/uk/co/gresearch/spark/dgraph/connector/PartitionMetrics.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package uk.co.gresearch.spark.dgraph.connector | ||
|
||
import org.apache.spark.SparkContext | ||
import org.apache.spark.sql.SparkSession | ||
import org.apache.spark.util.{DoubleAccumulator, LongAccumulator} | ||
|
||
trait PartitionMetrics { | ||
|
||
def incReadBytes(bytes: Long): Unit | ||
|
||
def incReadUids(uids: Long): Unit | ||
|
||
def incReadChunks(chunks: Long): Unit | ||
|
||
def incChunkTime(time: Double): Unit | ||
|
||
} | ||
|
||
case class AccumulatorPartitionMetrics(readBytes: LongAccumulator, | ||
readUids: LongAccumulator, | ||
readChunks: LongAccumulator, | ||
chunkTime: DoubleAccumulator) | ||
extends PartitionMetrics with Serializable { | ||
|
||
override def incReadBytes(bytes: Long): Unit = { | ||
println(s"increment accum $readBytes") | ||
readBytes.add(bytes) | ||
} | ||
|
||
override def incReadUids(uids: Long): Unit = readUids.add(uids) | ||
|
||
override def incReadChunks(chunks: Long): Unit = readChunks.add(chunks) | ||
|
||
override def incChunkTime(time: Double): Unit = chunkTime.add(time) | ||
|
||
} | ||
|
||
object AccumulatorPartitionMetrics { | ||
def apply(): AccumulatorPartitionMetrics = AccumulatorPartitionMetrics(SparkSession.builder().getOrCreate()) | ||
|
||
def apply(spark: SparkSession): AccumulatorPartitionMetrics = AccumulatorPartitionMetrics(spark.sparkContext) | ||
|
||
def apply(context: SparkContext): AccumulatorPartitionMetrics = | ||
AccumulatorPartitionMetrics( | ||
context.longAccumulator("Dgraph Bytes"), | ||
context.longAccumulator("Dgraph Uids"), | ||
context.longAccumulator("Dgraph Chunks"), | ||
context.doubleAccumulator("Dgraph Time") | ||
) | ||
} | ||
|
||
case class NoPartitionMetrics() extends PartitionMetrics with Serializable { | ||
override def incReadBytes(bytes: Long): Unit = { } | ||
|
||
override def incReadUids(uids: Long): Unit = { } | ||
|
||
override def incReadChunks(chunks: Long): Unit = { } | ||
|
||
override def incChunkTime(time: Double): Unit = { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters