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/22 02:40:11 UTC

[GitHub] [spark] LuciferYang opened a new pull request, #37604: [DON'T MERGE] Try to replace all json4s with Jackson

LuciferYang opened a new pull request, #37604:
URL: https://github.com/apache/spark/pull/37604

   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error type or message, please read the guideline first in
        'core/src/main/resources/error/README.md'.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   


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


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

Posted by GitBox <gi...@apache.org>.
plokhotnyuk commented on code in PR #37604:
URL: https://github.com/apache/spark/pull/37604#discussion_r964942791


##########
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:
   I'm happy to see this PR!
   
   [Jackson is much safer than json4s]https://github.com/json4s/json4s/search?q=Denial+of+Service&state=open&type=issues)
   
   Could you, please, check [jsoniter-scala](https://github.com/plokhotnyuk/jsoniter-scala) with your benchmarks if it worth to have an official integration with Spark ;)



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


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

Posted by GitBox <gi...@apache.org>.
plokhotnyuk commented on PR #37604:
URL: https://github.com/apache/spark/pull/37604#issuecomment-1286732347

   > [Jackson is much safer than json4s](https://github.com/json4s/json4s/search?q=Denial+of+Service&state=open&type=issues)
   > 
   
   I was wrong, it seems that jackson-core is vulnerable too: https://github.com/FasterXML/jackson-module-scala/issues/609


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


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

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on PR #37604:
URL: https://github.com/apache/spark/pull/37604#issuecomment-1221759512

   cc @JoshRosen FYI


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


[GitHub] [spark] LuciferYang closed pull request #37604: [DON'T MERGE] Try to replace all `json4s` with `Jackson`

Posted by "LuciferYang (via GitHub)" <gi...@apache.org>.
LuciferYang closed pull request #37604: [DON'T MERGE] Try to replace all `json4s` with `Jackson`
URL: https://github.com/apache/spark/pull/37604


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


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

Posted by GitBox <gi...@apache.org>.
LuciferYang commented on PR #37604:
URL: https://github.com/apache/spark/pull/37604#issuecomment-1241543683

   @plokhotnyuk Let me learn about [jsoniter-scala](https://github.com/plokhotnyuk/jsoniter-scala) first
   
   


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


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

Posted by GitBox <gi...@apache.org>.
LuciferYang commented on PR #37604:
URL: https://github.com/apache/spark/pull/37604#issuecomment-1225165035

   [2ea9dcf](https://github.com/apache/spark/pull/37604/commits/2ea9dcf8d41d1bf44ddba496707e696d50ce1cc9) add a simple benchmark, will update result later
   
   


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


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

Posted by GitBox <gi...@apache.org>.
LuciferYang commented on PR #37604:
URL: https://github.com/apache/spark/pull/37604#issuecomment-1221769895

   It seems that the main problem is that `JValue` is used as an input parameter or a return value, which will cause some forward incompatibility. I'm not sure whether we will change these APIs.
   
   If the above problem is not a problem, I think spark may can replace `Json4s` with `Jackson`
   
   


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


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

Posted by GitBox <gi...@apache.org>.
plokhotnyuk commented on PR #37604:
URL: https://github.com/apache/spark/pull/37604#issuecomment-1239493608

   I'm happy to see this PR!
   
   [Jackson is much safer than json4s]https://github.com/json4s/json4s/search?q=Denial+of+Service&state=open&type=issues)
   
   Could you, please, check [jsoniter-scala](https://github.com/plokhotnyuk/jsoniter-scala) with your benchmarks if it worth to have an official integration with Spark ;)


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


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

Posted by GitBox <gi...@apache.org>.
LuciferYang commented on PR #37604:
URL: https://github.com/apache/spark/pull/37604#issuecomment-1221765844

   @JoshRosen I am not sure whether this draft is helpful for future work, but I hope it is useful to a certain extent.
   
   This draft pr does not focus on forward compatibility, I use Jackson `JsonNode` instead of Json4s `JValue`, includes method parameters type and return value type, also includes objects used to serialize and deserialize Json. The test code still using json4s to test compatibility and all test should passed.
   
   The change involves 5 modules `core`, `catalyst`, `sql`, `mllib`, `kafka`, except that `sql` is directly used for `Row.jsonValue` in `catalyst`, other modules are relatively independent.
   
   For exporting HTTP APIs, `JsonNode` is also used, and `jsonResponderToServlet` method in `JettyUtils` is adapted. Of course, we can also return a custom `JsonResult` object instead of relying on `JsonNode`
   
   A problem found in the rewriting process is that `Json4s` has `JNothing`, but Jackson does not, I used `MissingNode` in Jackson instead and made special processing, for example:
   
   ```scala
   if (!jsonNode.isMissingNode) {
     node.set[JsonNode](name, jsonNode)
   }
   ```
   
   mima checks the following forward incompatibilities:
   
   ```
    ProblemFilters.exclude[IncompatibleMethTypeProblem]("org.apache.spark.deploy.DeployMessages#RequestExecutors.apply"),
    ProblemFilters.exclude[IncompatibleMethTypeProblem]("org.apache.spark.sql.types.DataType#JSortedObject.unapplySeq"),
    ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.spark.sql.expressions.MutableAggregationBuffer.jsonValue"),
    ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.spark.sql.streaming.SafeJsonSerializer.safeMapToJValue"),
    ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.spark.sql.streaming.SafeJsonSerializer.safeDoubleToJValue"),
    ProblemFilters.exclude[IncompatibleMethTypeProblem]("org.apache.spark.ml.param.FloatParam.jValueDecode"),
    ProblemFilters.exclude[IncompatibleResultTypeProblem]("org.apache.spark.ml.param.FloatParam.jValueEncode"),
    ProblemFilters.exclude[IncompatibleMethTypeProblem]("org.apache.spark.mllib.tree.model.TreeEnsembleModel#SaveLoadV1_0.readMetadata")
   ```
   
   This is similar to the problem described in SPARK-39658, `JValue` is directly used in the API.
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   


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


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

Posted by GitBox <gi...@apache.org>.
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