Created
May 19, 2015 02:11
-
-
Save timotta/0eb996159936c2da48bb to your computer and use it in GitHub Desktop.
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
object KryoExperiment { | |
case class SomeClass(x: String, v: String) | |
case class BigClass(x: String, v: Long, k: Double) | |
def main(args: Array[String]): Unit = { | |
val sparkConf1 = new SparkConf() | |
.set("spark.serializer", "org.apache.spark.serializer.KryoSerializer") | |
.registerKryoClasses(Array()) | |
val kryo1 = new KryoSerializer(sparkConf1) | |
test(kryo1) | |
val sparkConf2 = new SparkConf() | |
.set("spark.serializer", "org.apache.spark.serializer.KryoSerializer") | |
.registerKryoClasses(Array(classOf[(String, String)], classOf[SomeClass], classOf[BigClass])) | |
val kryo2 = new KryoSerializer(sparkConf2) | |
test(kryo2) | |
} | |
def test(kryo: KryoSerializer) { | |
val inst = kryo.newInstance() | |
val k2 = inst.serialize(("Ok", "ok")) | |
val l2 = inst.serialize(("Ok", 10000L, 0.1827383D)) | |
val m2 = inst.serialize(SomeClass("Ok", "ok")) | |
val n2 = inst.serialize(BigClass("Ok", 10000L, 0.1827383D)) | |
println("tuple=" + k2.array().length + | |
", bigTuple=" + l2.array().length + | |
", class=" + m2.array().length + | |
", bigClass=" + n2.array().length) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment