ConeyLiu commented on a change in pull request #25470: [SPARK-28751][Core] 
Imporve java serializer deserialization performance
URL: https://github.com/apache/spark/pull/25470#discussion_r314571103
 
 

 ##########
 File path: 
core/src/test/scala/org/apache/spark/serializer/JavaSerializerBenchmark.scala
 ##########
 @@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.serializer
+
+import java.nio.ByteBuffer
+
+import scala.reflect.ClassTag
+import scala.util.Random
+
+import org.apache.spark.SparkConf
+import org.apache.spark.benchmark.{Benchmark, BenchmarkBase}
+import org.apache.spark.internal.config._
+
+/**
+ * Benchmark for Java Serializer Deserialization use vs not use Class Resolve 
Cache.
+ * To run this benchmark:
+ * {{{
+ *   1. without sbt:
+ *      bin/spark-submit --class <this class> --jars <spark core test jar>
+ *   2. build/sbt "core/test:runMain <this class>"
+ *   3. generate result:
+ *      SPARK_GENERATE_BENCHMARK_FILES=1 build/sbt "core/test:runMain <this 
class>"
+ *      Results will be written to 
"benchmarks/JavaSerializerBenchmark-results.txt".
+ * }}}
+ */
+object JavaSerializerBenchmark extends BenchmarkBase {
+
+  val N = 100000
+  override def runBenchmarkSuite(mainArgs: Array[String]): Unit = {
+    val name = "Benchmark Java Serializer Deserialization use vs not use Class 
Resolve Cache"
+    runBenchmark(name) {
+      val benchmark = new Benchmark(name, N, 10, output = output)
+      Seq(true, false).foreach(useUnsafe => run(useUnsafe, benchmark))
+      benchmark.run()
+    }
+  }
+
+  private def run(useCache: Boolean, benchmark: Benchmark): Unit = {
+    def createCase[T: ClassTag](name: String, size: Int, gen: () => T): Unit = 
{
+      lazy val ser = createSerializer(useCache)
+      val data: Array[ByteBuffer] = Array.fill(size)(ser.serialize(gen()))
+
+      benchmark.addCase(s"$name with cache:$useCache") { _ =>
+        var i = 0
+        var s: ByteBuffer = null
+        while (i < size) {
+          s = data(i)
+          s.rewind()
+          ser.deserialize(s)
 
 Review comment:
   The `JavaSerializer` can provide threadsafe. I think that's why we use it in 
closure, RPC, and others. To reuse `InputStream` may need to do some threadsafe 
protection, such as `ThreadLocal`.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to