masesgroup / KNet

KNet is a comprehensive .NET suite for Apache Kafka™ providing all features: Producer, Consumer, Admin, Streams, Connect, backends (ZooKeeper and Kafka).
https://knet.masesgroup.com/
Apache License 2.0
32 stars 6 forks source link

The information traverse the CLR-JVM boundary many times reducing the speed #435

Closed masesdevelopers closed 4 months ago

masesdevelopers commented 4 months ago
          The information traverse the CLR-JVM boundary many times reducing the speed.

The local serializers stub invokes remote serializers: each time there is a conversion the JVM is impacted like in https://github.com/masesgroup/KNet/blob/721fe074212d4e221630853368beaab6a11bf120/src/net/KNet/Specific/Serialization/KNetSerialization.cs#L240 or https://github.com/masesgroup/KNet/blob/721fe074212d4e221630853368beaab6a11bf120/src/net/KNet/Specific/Serialization/KNetSerialization.cs#L347

Each conversion moves data between CLR and JVM:

The same happens in opposite with ConsumerRecord:

Originally posted by @masesdevelopers in https://github.com/masesgroup/KNet/issues/53#issuecomment-1984765101

masesdevelopers commented 4 months ago

It is possible to add a property, named UseKafkaClassForSupportedTypes with default value set to false, to decide which kind of serializer use:

Apache Kafka CLR (source from GitHub)
```java public class IntegerSerializer implements Serializer { public byte[] serialize(String topic, Integer data) { if (data == null) return null; return new byte[] { (byte) (data >>> 24), (byte) (data >>> 16), (byte) (data >>> 8), data.byteValue() }; } } ``` ```c# public static byte[] GetBytes(int value) { byte[] bytes = new byte[sizeof(int)]; Unsafe.As(ref bytes[0]) = value; return bytes; } ```

Meanwhile on the property UseHeaders will be added the public setter to give to users of subclasses of SerDes, e.g. JSonSerDes, to remove the constraint imposed by the code in case of needs.