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

Improving performance #117

Merged
merged 3 commits into from
Feb 29, 2024
Merged

Improving performance #117

merged 3 commits into from
Feb 29, 2024

Conversation

dutow
Copy link
Collaborator

@dutow dutow commented Feb 12, 2024

This commit tries to improve the performance of our encryption, based on the results reported in #89.

It contains two main changes which results in improvents:

  • Our pg_tde_crypt loop has several conditions to support all possible cornercases it might encounter. These conditions are not neccessary most of the time, but slow down our throughput considerably. This commit introduces a "simple" version of the function for smaller data sizes, which only has a simple one instruction for loop.
  • OpenSSL supports in place encryption when certain conditions are met - which is true for our zeroblocks function. The zero block function no longer uses an additional local array, and the filling of the input data is also simplified.

These changes together results in the following encryption overheads:

  • json testcase: 140% -> 120%
  • jsonb testcase: 230% -> 175%

Closes #89

@dutow dutow force-pushed the perffix2 branch 2 times, most recently from f8876c2 to b6af70c Compare February 12, 2024 21:35
Comment on lines 19 to 22
extern void
pg_tde_crypt_simple(const char* iv_prefix, uint32 start_offset, const char* data, uint32 data_len, char* out, RelKeysData* keys, const char* context);
extern void
pg_tde_crypt_complex(const char* iv_prefix, uint32 start_offset, const char* data, uint32 data_len, char* out, RelKeysData* keys, const char* context);
Copy link
Member

Choose a reason for hiding this comment

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

Just a minor thing - should those be "external" (I mean to it looks like rather "private" functions)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Originally I considered simply calling the simple function at some places, but it is safer to always call the main function and it doesn't matter that much. I'll remove these from the header.

This commit tries to improve the performance of our encryption, based on the results
reported in Percona-Lab#89.

It contains two main changes which results in improvents:

* Our pg_tde_crypt loop has several conditions to support all possible cornercases
it might encounter. These conditions are not neccessary most of the time, but slow
down our throughput considerably. This commit introduces a "simple" version of the
function for smaller data sizes, which only has a simple one instruction for loop.
* OpenSSL supports in place encryption when certain conditions are met - which is
true for our zeroblocks function. The zero block function no longer uses an
additional local array, and the filling of the input data is also simplified.

These changes together results in the following encryption overheads:

* json testcase: 140% -> 120%
* jsonb testcase: 230% -> 175%

Closes Percona-Lab#89
uint64 aes_block_no = start_offset % AES_BLOCK_SIZE;
char ivp_debug[33];
iv_prefix_debug(iv_prefix, ivp_debug);
ereport(LOG,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to log this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's inside an ENCRYPTION_DEBUG macro

@dutow dutow merged commit 665b580 into Percona-Lab:main Feb 29, 2024
8 checks passed
@dutow dutow deleted the perffix2 branch February 29, 2024 11:39
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.

Performance issue with JSONB and JSON fields
3 participants