kafka-rest icon indicating copy to clipboard operation
kafka-rest copied to clipboard

Reuse serializers

Open fbad opened this issue 2 years ago • 0 comments

Hi!

I have profiled Kafka Rest v7.5.0 under some test load (2rps on Produce V2 endpoint with Avro format and schemas registered in Schema Registry, using schema id) and it looks like most of the time inside RecordSerializerFacade.serialize is actually spent reinstantiating the three serializers (Avro, JsonSchema, Protobuf) (you can see how small is the portion spent actually serializing in this profiling).

image

It seems this is due to io/confluent/kafka/serializers/AbstractKafkaSchemaSerDe.addRuleObjectsFromServiceLoader.

  1. Am I interpreting this right? Are serializers reinstantiated for each request?
  2. Would it be possible to reuse the same serializers for different requests? Are they thread-safe? If yes, can we maybe bind SchemaRecordSerializerFactory with singleton scope?

Thank you!

fbad avatar Sep 14 '23 15:09 fbad