We've noticed that there's a lot of contention on get/set of schemas by ID
in CachedSchemaRegistryClient if that object is shared across threads. All
of the methods on CachedSchemaRegistryClient are synchronized and
getBySubjectAndId is called when deserializing a record:
https://github.com/confluentinc/schema-registry/blob/master/avro-serializer/src/main/java/io/confluent/kafka/serializers/AbstractKafkaAvroDeserializer.java#L122

It seems like a good idea to make a thread-local variant of this data
structure, or perhaps make the entire thing be backed by thread local
storage. The cost would be memory but it seems safe to do and would remove
contention on the registry object across threads. We've implemented a
simple thread local schema registry to do this but wanted to get community
feedback on the best way to factor this before submitting a PR.

Reply via email to