You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/08/24 13:43:02 UTC

[GitHub] [spark] LuciferYang commented on a diff in pull request #37604: [DON'T MERGE] Try to replace all `json4s` with `Jackson`

LuciferYang commented on code in PR #37604:
URL: https://github.com/apache/spark/pull/37604#discussion_r953820533


##########
core/src/test/scala/org/apache/spark/JsonSerDeBenchmark.scala:
##########
@@ -0,0 +1,220 @@
+/*
+ * 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
+
+import org.json4s.JsonDSL._
+import org.json4s.jackson.JsonMethods.{compact, parse, render}
+
+import org.apache.spark.benchmark.{Benchmark, BenchmarkBase}
+import org.apache.spark.util.JacksonUtils
+
+/**
+ * Benchmark for Json4s vs Jackson serialization and deserialization.
+ * 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/JsonSerDeBenchmark-results.txt".
+ * }}}
+ * */
+object JsonSerDeBenchmark extends BenchmarkBase {

Review Comment:
   ```
   OpenJDK 64-Bit Server VM 1.8.0_345-b01 on Linux 5.15.0-1017-azure
   Intel(R) Xeon(R) Platinum 8272CL CPU @ 2.60GHz
   Test to Json with out nested:             Best Time(ms)   Avg Time(ms)   Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
   ------------------------------------------------------------------------------------------------------------------------
   Use Json4s                                          111            170          58          0.9        1105.5       1.0X
   Use Scala object                                    175            177           2          0.6        1748.0       0.6X
   Use JsonNode                                         60             61           2          1.7         597.7       1.8X
   Use Json Generator                                   55             56           1          1.8         552.8       2.0X
   
   OpenJDK 64-Bit Server VM 1.8.0_345-b01 on Linux 5.15.0-1017-azure
   Intel(R) Xeon(R) Platinum 8272CL CPU @ 2.60GHz
   Test to Json with nested:                 Best Time(ms)   Avg Time(ms)   Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
   ------------------------------------------------------------------------------------------------------------------------
   Use Json4s                                         1574           1575           1          0.1       15739.5       1.0X
   Use Scala object                                    395            398           2          0.3        3952.5       4.0X
   Use JsonNode                                        285            288           2          0.4        2854.5       5.5X
   Use Json Generator                                  151            153           2          0.7        1511.1      10.4X
   
   OpenJDK 64-Bit Server VM 1.8.0_345-b01 on Linux 5.15.0-1017-azure
   Intel(R) Xeon(R) Platinum 8272CL CPU @ 2.60GHz
   Test from Json without nested:            Best Time(ms)   Avg Time(ms)   Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
   ------------------------------------------------------------------------------------------------------------------------
   Use Json4s                                          103            104           2          1.0        1032.5       1.0X
   Use Jackson                                          95             96           1          1.0         954.2       1.1X
   
   OpenJDK 64-Bit Server VM 1.8.0_345-b01 on Linux 5.15.0-1017-azure
   Intel(R) Xeon(R) Platinum 8272CL CPU @ 2.60GHz
   Test from Json with nested:               Best Time(ms)   Avg Time(ms)   Stdev(ms)    Rate(M/s)   Per Row(ns)   Relative
   ------------------------------------------------------------------------------------------------------------------------
   Use Json4s                                         1258           1260           2          0.1       12584.5       1.0X
   Use Jackson                                         539            541           2          0.2        5394.5       2.3X
   ```
   
   From the results of `JsonSerDeBenchmark`:
   
   - `Jackson` is faster than `Json4s`, and `Jackson` has greater advantages when the data is nested
   - Using `JsonGenerator` for serialization is more efficient than building a `JsonNode` first and then serializing it
   



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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