-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
81adadd
commit e75ea47
Showing
16 changed files
with
666 additions
and
23 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,26 +1,30 @@ | ||
package benchmark.bench | ||
|
||
trait Bench { | ||
val RecordCount: Int = 1_000_000 | ||
val RecordCount: Int = 5_000_000 | ||
val StreamIterations: Int = 1 | ||
val SearchIterations: Int = 1 | ||
|
||
val tasks: List[Task] = List( | ||
Task("Insert Records", RecordCount, insertRecords), | ||
Task("Stream Records", StreamIterations, streamRecords), | ||
Task("Stream Records", StreamIterations * RecordCount, streamRecords), | ||
Task("Search Each Record", StreamIterations * RecordCount, searchEachRecord), | ||
Task("Search All Records", StreamIterations, searchAllRecords) | ||
Task("Search All Records", StreamIterations * RecordCount, searchAllRecords) | ||
) | ||
|
||
def name: String | ||
|
||
def init(): Unit | ||
|
||
protected def insertRecords(status: StatusCallback): Unit | ||
protected def insertRecords(status: StatusCallback): Int | ||
|
||
protected def streamRecords(status: StatusCallback): Int | ||
|
||
protected def streamRecords(status: StatusCallback): Unit | ||
protected def searchEachRecord(status: StatusCallback): Int | ||
|
||
protected def searchEachRecord(status: StatusCallback): Unit | ||
protected def searchAllRecords(status: StatusCallback): Int | ||
|
||
protected def searchAllRecords(status: StatusCallback): Unit | ||
def size(): Long | ||
|
||
def dispose(): 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package benchmark.bench | ||
|
||
case class Task(name: String, maxProgress: Double = 1.0, f: StatusCallback => Unit) | ||
case class Task(name: String, maxProgress: Double = 1.0, f: StatusCallback => Int) |
158 changes: 158 additions & 0 deletions
158
benchmark/src/main/scala/benchmark/bench/impl/DerbyBench.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,158 @@ | ||
package benchmark.bench.impl | ||
|
||
import benchmark.bench.{Bench, StatusCallback} | ||
import lightdb.util.Unique | ||
|
||
import java.io.File | ||
import java.sql.{Connection, DriverManager} | ||
import scala.collection.parallel.CollectionConverters._ | ||
|
||
object DerbyBench extends Bench { | ||
private lazy val connection: Connection = { | ||
val path = new File("db/derby").getCanonicalPath | ||
val c = DriverManager.getConnection(s"jdbc:derby:$path;create=true") | ||
c.setAutoCommit(false) | ||
c | ||
} | ||
|
||
override def name: String = "Derby" | ||
|
||
override def init(): Unit = { | ||
// executeUpdate("DROP TABLE IF EXISTS people") | ||
executeUpdate("CREATE TABLE people(id VARCHAR(255), name VARCHAR(255), age INTEGER)") | ||
executeUpdate("CREATE INDEX id_idx ON people(id)") | ||
executeUpdate("CREATE INDEX age_idx ON people(age)") | ||
} | ||
|
||
override protected def insertRecords(status: StatusCallback): Int = { | ||
val ps = connection.prepareStatement("INSERT INTO people(id, name, age) VALUES (?, ?, ?)") | ||
try { | ||
(0 until RecordCount) | ||
.foldLeft(0)((total, index) => { | ||
val person = Person( | ||
name = Unique(), | ||
age = index | ||
) | ||
ps.setString(1, person.id) | ||
ps.setString(2, person.name) | ||
ps.setInt(3, person.age) | ||
ps.addBatch() | ||
status.progress.set(index + 1) | ||
total + 1 | ||
}) | ||
} finally { | ||
ps.executeBatch() | ||
ps.close() | ||
connection.commit() | ||
} | ||
} | ||
|
||
private def countRecords(): Int = { | ||
val s = connection.createStatement() | ||
try { | ||
val rs = s.executeQuery("SELECT COUNT(*) FROM people") | ||
try { | ||
rs.next() | ||
rs.getInt(1) | ||
} finally { | ||
rs.close() | ||
} | ||
} finally { | ||
s.close() | ||
} | ||
} | ||
|
||
override protected def streamRecords(status: StatusCallback): Int = (0 until StreamIterations) | ||
.foldLeft(0)((total, iteration) => { | ||
val s = connection.createStatement() | ||
val rs = s.executeQuery("SELECT * FROM people") | ||
var count = 0 | ||
while (rs.next()) { | ||
count += 1 | ||
} | ||
rs.close() | ||
s.close() | ||
if (count != RecordCount) { | ||
scribe.warn(s"RecordCount was not $RecordCount, it was $count") | ||
} | ||
status.progress.set(iteration + 1) | ||
total + count | ||
}) | ||
|
||
override protected def searchEachRecord(status: StatusCallback): Int = { | ||
var counter = 0 | ||
(0 until StreamIterations) | ||
.foreach { iteration => | ||
val ps = connection.prepareStatement("SELECT * FROM people WHERE age = ?") | ||
(0 until RecordCount) | ||
.foreach { index => | ||
ps.setInt(1, index) | ||
val rs = ps.executeQuery() | ||
rs.next() | ||
val person = Person( | ||
name = rs.getString("name"), | ||
age = rs.getInt("age"), | ||
id = rs.getString("id") | ||
) | ||
if (person.age != index) { | ||
scribe.warn(s"${person.age} was not $index") | ||
} | ||
if (rs.next()) { | ||
scribe.warn(s"More than one result for $index") | ||
} | ||
rs.close() | ||
counter += 1 | ||
status.progress.set((iteration + 1) * (index + 1)) | ||
} | ||
ps.close() | ||
} | ||
counter | ||
} | ||
|
||
override protected def searchAllRecords(status: StatusCallback): Int = { | ||
var counter = 0 | ||
(0 until StreamIterations) | ||
.par | ||
.foreach { iteration => | ||
val s = connection.createStatement() | ||
val rs = s.executeQuery("SELECT * FROM people") | ||
var count = 0 | ||
while (rs.next()) { | ||
count += 1 | ||
counter += 1 | ||
} | ||
rs.close() | ||
s.close() | ||
if (count != RecordCount) { | ||
scribe.warn(s"RecordCount was not $RecordCount, it was $count") | ||
} | ||
status.progress.set(iteration + 1) | ||
} | ||
counter | ||
} | ||
|
||
override def size(): Long = { | ||
def recurse(file: File): Long = if (file.isDirectory) { | ||
file.listFiles().map(recurse).sum | ||
} else { | ||
file.length() | ||
} | ||
recurse(new File("db/derby")) | ||
} | ||
|
||
override def dispose(): Unit = { | ||
connection.commit() | ||
connection.close() | ||
} | ||
|
||
private def executeUpdate(sql: String): Unit = { | ||
val s = connection.createStatement() | ||
try { | ||
s.executeUpdate(sql) | ||
} finally { | ||
s.close() | ||
} | ||
} | ||
|
||
case class Person(name: String, age: Int, id: String = Unique()) | ||
} |
Oops, something went wrong.