Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DGS-7103 Optimize instantiation of lists of schemas #2614

Merged
merged 3 commits into from May 16, 2023

Conversation

rayokota
Copy link
Member

@rayokota rayokota commented Apr 18, 2023

Various memory optimizations:

  • For compatibility checks, use List<ParsedSchemaHolder> instead of List<ParsedSchema>. This is to allow the schema to be parsed lazily.
  • For retrieval methods, use List<SchemaKey> instead of List<Schema> or List<SchemaValue>, since keys use less memory
  • For the /schemas endpoint, add config params for schema.search.default.limit and schema.search.max.limit to limit number of schemas retrieved in memory, which both default to 1000

Copy link
Member

@ericwush ericwush left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @rayokota for the optimization

int newVersion = MIN_VERSION;
for (SchemaValue schemaValue : allVersions) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my understanding, this is the root cause for the OOM since all the schema versions are referenced and can only be potentially GC'ed after this method. Now SchemaKey is used which itself has a smaller memory footprint and SchemaValues can be GC'ed even in middle of the call due to the use of SoftReference. Is this correct?

Copy link
Member Author

@rayokota rayokota May 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you are correct. Plus we explicitly call schemaHolder.clear to release references to the SchemaValue instances.

@rayokota rayokota merged commit ff28406 into confluentinc:7.4.x May 16, 2023
4 checks passed
@rayokota rayokota deleted the DGS-7103 branch May 16, 2023 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants