incubator-fury: Performance problem ??

I’ ve test fury and kryo performance benchmark, and found kryo performance is better. Why???

The code as follows:

/**
 * Copyright © 2023 shopenhe (shopen.he@gmail.com)
 *
 * Licensed 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 com.github.shopenhe.benchmarks;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import io.fury.Fury;
import io.fury.Language;
import io.fury.ThreadLocalFury;
import io.fury.ThreadSafeFury;
import lombok.Data;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Serialize framework benchmarks, about Fury, Kryo.
 *
 * @author shopenhe
 */
public class SerializeBenchmark {

    @Benchmark
    public void testFurySerialize(FuryOperation operation) {
        operation.serialize();
    }

    @Benchmark
    public void testFuryDeserialize(FuryOperation operation) {
        operation.deserialize();
    }

    @Benchmark
    public void testKryoSerialize(KryoOperation operation) {
        operation.serialize();
    }

    @Benchmark
    public void testKryoDeserialize(KryoOperation operation) {
        operation.deserialize();
    }

    public static void main(String[] args) throws RunnerException {
        Options opt = new OptionsBuilder()
                .include(SerializeBenchmark.class.getSimpleName())
                .threads(2)
                .forks(1)
                .build();
        new Runner(opt).run();
    }

    @State(Scope.Benchmark)
    public static class FuryOperation {

        ThreadSafeFury fury = new ThreadLocalFury(classLoader -> {
            Fury f = Fury.builder().withLanguage(Language.JAVA)
                    .withRefTracking(true).withClassLoader(classLoader).build();
            f.register(SomeClass.class);
            f.register(Item.class);
            return f;
        });
        byte[] dataSerialized;

        public FuryOperation() {
            dataSerialized = serialize();
        }

        public byte[] serialize() {
            SomeClass someClass = new SomeClass();
            for (int i = 0; i < 8000; i++) {
                {
                    Item item = new Item();
                    item.setId(123456789L + i);
                    item.setName("itemName" + i);
                    item.setType(1 + i);
                    item.setScore(12345.6789F + i);
                    someClass.getItemList().add(item);
                }
                {
                    Item item = new Item();
                    item.setId(987654321L + i);
                    item.setName("itemName" + i);
                    item.setType(1 + i);
                    item.setScore(98765.4321F + i);
                    someClass.getItemMap().put(i, item);
                }
            }
            return fury.serialize(someClass);
        }

        public SomeClass deserialize() {
            return (SomeClass) fury.deserialize(dataSerialized);
        }

    }

    @State(Scope.Benchmark)
    public static class KryoOperation {

        ThreadLocal<Kryo> kryoTL = ThreadLocal.withInitial(() -> {
            Kryo kryo = new Kryo();
            kryo.register(SomeClass.class);
            kryo.register(Item.class);
            kryo.register(ArrayList.class);
            kryo.register(HashMap.class);
            return kryo;
        });
        byte[] dataSerialized;

        public KryoOperation() {
            dataSerialized = serialize();
        }

        public byte[] serialize() {
            SomeClass someClass = new SomeClass();
            for (int i = 0; i < 8000; i++) {
                {
                    Item item = new Item();
                    item.setId(123456789L + i);
                    item.setName("itemName" + i);
                    item.setType(1 + i);
                    item.setScore(12345.6789F + i);
                    someClass.getItemList().add(item);
                }
                {
                    Item item = new Item();
                    item.setId(987654321L + i);
                    item.setName("itemName" + i);
                    item.setType(1 + i);
                    item.setScore(98765.4321F + i);
                    someClass.getItemMap().put(i, item);
                }
            }
            Output output = new Output(1024, -1);
            kryoTL.get().writeObject(output, someClass);
            return output.getBuffer();
        }

        public SomeClass deserialize() {
            Input input = new Input(dataSerialized);
            return kryoTL.get().readObject(input, SomeClass.class);
        }

    }

    @Data
    static class SomeClass {

        long updateTime = 1L;
        List<Item> itemList = new ArrayList<>();
        Map<Integer, Item> itemMap = new HashMap<>();

    }

    @Data
    static class Item {

        long id;
        String name;
        int type;
        float score;

    }

}

The benchmark result:

Benchmark Mode Cnt Score Error Units SerializeBenchmark.testFuryDeserialize thrpt 5 1435.578 ± 37.215 ops/s SerializeBenchmark.testFurySerialize thrpt 5 735.145 ± 13.027 ops/s SerializeBenchmark.testKryoDeserialize thrpt 5 1929.386 ± 19.501 ops/s SerializeBenchmark.testKryoSerialize thrpt 5 1272.712 ± 29.032 ops/s

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 19 (1 by maintainers)

Most upvoted comments

@shopenhe I see, you are using kryo5, which disabled references by default: image

image

Please disable fury references too, or enable kryo references tracking by com.esotericsoftware.kryo.Kryo#setReferences