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

Init benchmarks module with multi-projects structure #147

Merged
merged 1 commit into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ jobs:
- uses: olafurpg/setup-scala@v10
- name: Test
run: sbt -Dspark.testVersion=${{ matrix.spark }} +test
- name: Benchmark
run: sbt -Dspark.testVersion=${{ matrix.spark }} +benchmarks/Jmh/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.github.mrpowers.spark.fast.tests

import org.apache.spark.sql.SparkSession
import org.openjdk.jmh.annotations._
import org.openjdk.jmh.infra.Blackhole

import java.util.concurrent.TimeUnit
import scala.util.Try

private class MyBenchmark extends DataFrameComparer {
@Benchmark
@BenchmarkMode(Array(Mode.AverageTime, Mode.SingleShotTime))
@Fork(value = 2)
@Warmup(iterations = 10)
@Measurement(iterations = 10)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
def assertApproximateDataFrameEqualityWithPrecision(blackHole: Blackhole): Boolean = {
val spark = SparkSession
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also import core project test dependency to reuse some of the already defined test utility?

.builder()
.master("local")
.appName("spark session")
.config("spark.sql.shuffle.partitions", "1")
.getOrCreate()
spark.sparkContext.setLogLevel("ERROR")

import spark.implicits._
val ds1 = Seq(
("1", "10/01/2019", 26.762499999999996),
("1", "11/01/2019", 26.762499999999996)
).toDF("col_B", "col_C", "col_A")

val ds2 = Seq(
("1", "10/01/2019", 26.762499999999946),
("1", "11/01/2019", 26.76249999999991)
).toDF("col_B", "col_C", "col_A")
val result = Try(assertApproximateDataFrameEquality(ds1, ds2, precision = 0.0000001, orderedComparison = false))

blackHole.consume(result)
result.isSuccess
}
}
44 changes: 31 additions & 13 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,50 @@ version := "1.10.1"

val versionRegex = """^(.*)\.(.*)\.(.*)$""".r

val sparkVersion = settingKey[String]("Spark version")

val scala2_13 = "2.13.14"
val scala2_12 = "2.12.20"

sparkVersion := System.getProperty("spark.testVersion", "3.5.1")
val sparkVersion = System.getProperty("spark.testVersion", "3.5.1")
crossScalaVersions := {
sparkVersion.value match {
sparkVersion match {
case versionRegex("3", m, _) if m.toInt >= 2 => Seq(scala2_12, scala2_13)
case versionRegex("3", _, _) => Seq(scala2_12)
}
}

scalaVersion := crossScalaVersions.value.head

libraryDependencies += "org.apache.spark" %% "spark-sql" % sparkVersion.value % "provided"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.18" % "test"
Test / fork := true

credentials += Credentials(Path.userHome / ".sbt" / "sonatype_credentials")
lazy val commonSettings = Seq(
javaOptions ++= {
Seq("-Xms512M", "-Xmx2048M", "-Duser.timezone=GMT") ++ (if (System.getProperty("java.version").startsWith("1.8.0"))
Seq("-XX:+CMSClassUnloadingEnabled")
else Seq.empty)
},
libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-sql" % sparkVersion % "compile",
"org.scalatest" %% "scalatest" % "3.2.18" % "test"
),
)

Test / fork := true
javaOptions ++= {
Seq("-Xms512M", "-Xmx2048M", "-Duser.timezone=GMT") ++ (if (System.getProperty("java.version").startsWith("1.8.0"))
Seq("-XX:+CMSClassUnloadingEnabled")
else Seq.empty)
}
lazy val core = (project in file("core"))
.settings(
commonSettings,
name := "core",
)

lazy val benchmarks = (project in file("benchmarks"))
.dependsOn(core)
.settings(commonSettings)
.settings(
libraryDependencies ++= Seq(
"org.openjdk.jmh" % "jmh-generator-annprocess" % "1.37" //required for jmh IDEA plugin. Make sure this version matches sbt-jmh version!
),
name := "benchmarks",
).enablePlugins(JmhPlugin)

credentials += Credentials(Path.userHome / ".sbt" / "sonatype_credentials")

licenses := Seq("MIT" -> url("http://opensource.org/licenses/MIT"))
homepage := Some(url("https://github.com/mrpowers-io/spark-fast-tests"))
Expand Down
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.6.1")

addSbtPlugin("org.typelevel" % "laika-sbt" % "1.2.0")

addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3")
Loading