Apache Fory™ Java Benchmark contains benchmarks for:
Part of benchmark data is based on Kryo benchmark. Kryo benchmark suite is based on Kryo benchmark. The msgpack's official provides msgpack-jackson lib, but the performance is relatively poor. So, generate a basic manually written code using qwen3(LLM). Then modify it.
This benchmark use jmh as benchmark tool. jmh is licensed under GPL V2 with CLASSPATH exception, the usage can't be included in apache source/binary release unless as an optional feature. So Apache Fory™ make it as an optional dependency and you must enable jmh profile to activate it.
# Install fory cd ../../java && mvn install -DskipTests -Dcheckstyle.skip -Dlicense.skip -Dmaven.javadoc.skip && cd - # build benchmark jar # use `-Pjmh` to download jmh dependencies, we mark it as optional # since jmh is licenced under GPL V2 andn not comply with the license policy of ASF. mvn package -Pjmh # run benchmark nohup java -jar target/benchmarks.jar -f 5 -wi 3 -i 5 -t 1 -w 3s -r 5s -rf csv >bench.log 2>&1 & java -jar target/benchmarks.jar "org.apache.fory.*UserTypeSerializeSuite.*" -f 1 -wi 1 -i 1 -t 1 -w 2s -r 2s -rf csv -p objectType=MEDIA_CONTENT -p bufferType=array -p references=false
Generate Protobuf/Flatbuffers code manually:
flatc -o src/main/java -j src/main/java/org/apache/fory/benchmark/state/bench.fbs flatc -o src/main/java -j src/main/flatbuffers/xlang_bench.fbs protoc -I=../proto --java_out=src/main/java ../proto/bench.proto
Use the flatc version matching flatbuffers-java in pom.xml. Protobuf code can be generated by maven plugin automatically. Flatbuffers generated code is short, so we added generated files to repo directly.
cd .. && mvn -T10 install -DskipTests -Dcheckstyle.skip -Dlicense.skip -Dmaven.javadoc.skip mvn exec:java -Dexec.args="-f 3 -wi 5 -i 15 -t 1 -w 2s -r 2s -rf csv"
See org.openjdk.jmh.runner.options.CommandLineOptions for more information about jmh options:
-f fork -wi Number of warmup iterations to do. -i Number of measurement iterations to do -t Number of worker threads to run with. -w Time to spend at each warmup iteration. -r Time to spend at each measurement iteration. -rf Result format type
Set FORY_BENCH_SCHEMA_MISMATCH=1 to run the Fory-only compatible-read schema-mismatch mode for XlangBenchmark. This mode is off by default. When enabled, run with --serializer fory; protobuf and FlatBuffers benchmark modes fail with a configuration error. Fory serialization uses the normal v1 benchmark classes, and Fory deserialization uses v2 classes registered with the same Fory type IDs where one int32 field is widened to int64.
Save benchmark data to specified dir, then run tool.py to plot graphs.
Apache Fory™ uses pandas to process the jmh data, and uses matplotlib for plotting.
pip install pandas matplotlib python analyze.py
Using async-profiler to generate flame graph.
export pic=s1.html nohup java -jar target/benchmarks.jar 'org.apache.fory.*Fory.*deserialize*' -f 1 -wi 1 -i 1 -t 1 -w 1s -r 35s -rf csv & profiler.sh -d 30 -f $pic `jps | grep ForkedMain | awk '{print $1}'`
-XX:+PrintCompilation -XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining to inspect JIT: java -XX:+PrintCompilation -XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining -jar target/benchmarks.jar org.apache.fory.*Fory.* UserTypeBenchmark.serialize -f 0 -wi 1 -i 1 -t 1 -w 1s -r 35s -rf csv > compile.logjava ${other_options} -XX:+PrintFlagsFinal -version, should include all other options on the command line because some options affect others, particularly when setting GC-related flags.jcmd $pid VM.flags -all -XX:FreqInlineSize= flag specifies the maximum number of bytecode instructions to inline for a method. The default value depends on the platform – for 64-bit Linux, it's 325.hot method too big need to be optimized.