lindong28 commented on code in PR #87:
URL: https://github.com/apache/flink-ml/pull/87#discussion_r861666211
##########
flink-ml-benchmark/src/main/java/org/apache/flink/ml/benchmark/Benchmark.java:
##########
@@ -71,37 +70,57 @@ public static void printHelp() {
System.out.println();
}
- @SuppressWarnings("unchecked")
public static void executeBenchmarks(CommandLine commandLine) throws
Exception {
String configFile = commandLine.getArgs()[0];
- Map<String, ?> benchmarks = BenchmarkUtils.parseJsonFile(configFile);
- System.out.println("Found benchmarks " + benchmarks.keySet());
+ Map<String, Map<String, Map<String, ?>>> benchmarks =
+ BenchmarkUtils.parseJsonFile(configFile);
+ System.out.println("Found " + benchmarks.keySet().size() + "
benchmarks.");
+ String saveFile =
commandLine.getOptionValue(OUTPUT_FILE_OPTION.getLongOpt());
StreamExecutionEnvironment env =
StreamExecutionEnvironment.getExecutionEnvironment();
StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
- List<BenchmarkResult> results = new ArrayList<>();
- for (Map.Entry<String, ?> benchmark : benchmarks.entrySet()) {
- LOG.info("Running benchmark " + benchmark.getKey() + ".");
-
- BenchmarkResult result =
- BenchmarkUtils.runBenchmark(
- tEnv, benchmark.getKey(), (Map<String, ?>)
benchmark.getValue());
-
- results.add(result);
- LOG.info(BenchmarkUtils.getResultsMapAsJson(result));
+ Map<String, Map<String, Map<String, ?>>> results = new HashMap<>();
+ String benchmarkResultsJson = "{}";
+ int index = 0;
+ for (String benchmarkName : benchmarks.keySet()) {
Review Comment:
Since we need to get both the key and the value of this entry, would it be
simpler to use `for (Map.Entry<String, Map<String, Map<String, ?>>> entry :
benchmarks.entrySet())` here?
Then we can use `entry.getKey()` and `entry.getValue()`, instead of
repeatedly calling `results.get(benchmarkName)` and
`benchmarks.get(benchmarkName)`, in the loop body.
##########
flink-ml-dist/src/main/flink-ml-bin/bin/benchmark-results-visualize.py:
##########
@@ -0,0 +1,68 @@
+################################################################################
+# 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.
+################################################################################
+import argparse
+import json
+import matplotlib.pyplot as plt
+import re
+
+
+def benchmark_results_visualize(filename, name_pattern, x_field, y_field):
+ def get_field(json, fieldnames):
Review Comment:
Would it be simpler to move this method outside
`benchmark_results_visualize`, to reduce the number of nesting?
##########
flink-ml-benchmark/src/main/java/org/apache/flink/ml/benchmark/Benchmark.java:
##########
@@ -71,37 +70,57 @@ public static void printHelp() {
System.out.println();
}
- @SuppressWarnings("unchecked")
public static void executeBenchmarks(CommandLine commandLine) throws
Exception {
String configFile = commandLine.getArgs()[0];
- Map<String, ?> benchmarks = BenchmarkUtils.parseJsonFile(configFile);
- System.out.println("Found benchmarks " + benchmarks.keySet());
+ Map<String, Map<String, Map<String, ?>>> benchmarks =
+ BenchmarkUtils.parseJsonFile(configFile);
+ System.out.println("Found " + benchmarks.keySet().size() + "
benchmarks.");
+ String saveFile =
commandLine.getOptionValue(OUTPUT_FILE_OPTION.getLongOpt());
StreamExecutionEnvironment env =
StreamExecutionEnvironment.getExecutionEnvironment();
StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
- List<BenchmarkResult> results = new ArrayList<>();
- for (Map.Entry<String, ?> benchmark : benchmarks.entrySet()) {
- LOG.info("Running benchmark " + benchmark.getKey() + ".");
-
- BenchmarkResult result =
- BenchmarkUtils.runBenchmark(
- tEnv, benchmark.getKey(), (Map<String, ?>)
benchmark.getValue());
-
- results.add(result);
- LOG.info(BenchmarkUtils.getResultsMapAsJson(result));
+ Map<String, Map<String, Map<String, ?>>> results = new HashMap<>();
+ String benchmarkResultsJson = "{}";
+ int index = 0;
+ for (String benchmarkName : benchmarks.keySet()) {
+ LOG.info(
+ String.format(
+ "Running benchmark %d/%d: %s",
+ index++, benchmarks.keySet().size(),
benchmarkName));
+
+ results.put(benchmarkName, benchmarks.get(benchmarkName));
+ try {
+ BenchmarkResult result =
+ BenchmarkUtils.runBenchmark(
+ tEnv, benchmarkName,
benchmarks.get(benchmarkName));
+ results.get(benchmarkName).put("results", result.toMap());
+ LOG.info(
+ String.format(
+ "Benchmark %s finished.\n%s",
+ benchmarkName, results.get(benchmarkName)));
+ } catch (Exception e) {
+ results.get(benchmarkName).put("exception",
BenchmarkUtils.exceptionToMap(e));
+ LOG.info(String.format("Benchmark %s failed.\n%s",
benchmarkName, e));
+ }
+
+ benchmarkResultsJson =
+ ReadWriteUtils.OBJECT_MAPPER
+ .writerWithDefaultPrettyPrinter()
+ .writeValueAsString(results);
+
+ if (commandLine.hasOption(OUTPUT_FILE_OPTION.getLongOpt())) {
+ ReadWriteUtils.saveToFile(saveFile, benchmarkResultsJson,
true);
+ LOG.info("Benchmark results saved as json in " + saveFile +
".");
+ }
}
-
- String benchmarkResultsJson =
- BenchmarkUtils.getResultsMapAsJson(results.toArray(new
BenchmarkResult[0]));
System.out.println("Benchmarks execution completed.");
- System.out.println("Benchmark results summary:");
- System.out.println(benchmarkResultsJson);
if (commandLine.hasOption(OUTPUT_FILE_OPTION.getLongOpt())) {
- String saveFile =
commandLine.getOptionValue(OUTPUT_FILE_OPTION.getLongOpt());
- ReadWriteUtils.saveToFile(saveFile, benchmarkResultsJson, true);
System.out.println("Benchmark results saved as json in " +
saveFile + ".");
+ } else {
+ System.out.println("Benchmark results summary:");
+ System.out.println(benchmarkResultsJson);
Review Comment:
It seems that `printInvalidError()` is only called once in this class. Since
its logic is pretty straightforward, would it be simpler to remove this method?
If we choose to keep this method, could we mark it `private`?
##########
flink-ml-dist/src/main/flink-ml-bin/bin/benchmark-results-visualize.py:
##########
@@ -0,0 +1,68 @@
+################################################################################
+# 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.
+################################################################################
+import argparse
+import json
+import matplotlib.pyplot as plt
+import re
+
+
+def benchmark_results_visualize(filename, name_pattern, x_field, y_field):
+ def get_field(json, fieldnames):
+ field = json
Review Comment:
Would it be simpler to just rename the first function input parameter as
`field`?
##########
flink-ml-core/src/main/java/org/apache/flink/ml/util/ReadWriteUtils.java:
##########
@@ -71,9 +71,9 @@ private static <T> Object jsonEncodeHelper(Param<T> param,
Object value) throws
return param.jsonEncode((T) value);
}
- // Converts Map<Param<?>, Object> to Map<String, String> which maps the
parameter name to the
- // string-encoded parameter value.
- private static Map<String, Object> jsonEncode(Map<Param<?>, Object>
paramMap)
+ // Converts Map<Param<?>, Object> to Map<String, Object> which maps the
parameter name to the
+ // json-supported parameter value.
+ public static Map<String, Object> jsonEncode(Map<Param<?>, Object>
paramMap)
Review Comment:
Does this need to be `public`?
##########
flink-ml-dist/src/main/flink-ml-bin/bin/benchmark-results-visualize.py:
##########
@@ -0,0 +1,68 @@
+################################################################################
+# 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.
+################################################################################
+import argparse
+import json
+import matplotlib.pyplot as plt
+import re
+
+
+def benchmark_results_visualize(filename, name_pattern, x_field, y_field):
+ def get_field(json, fieldnames):
+ field = json
+ for fieldname in fieldnames.split("."):
+ field = field[fieldname]
+ return field
+
+ x_values = []
+ y_values = []
+ with open(filename, "r") as configfile:
+ for name, config in json.loads(configfile.read()).items():
Review Comment:
Following the python naming convention, should we change `configfile` to
`config_file`?
Same for `fieldnames` etc.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]