The CPU flame graph that that I analyzed yesterday does not seem to be available anymore. It looks like mtr_t::encrypt(), log_encrypt_buf() and encryption_crypt() need to be refactored so that MyCTX::init() would be invoked only once. It seems that encryption_crypt() is consuming over 6% of all CPU time, while MyCTX::update() (appending some data to the encrypted buffer) would only use 0.25%.
Based on the implementation of encryption_crypt(), it would seem that there is no need to refactor any encryption service interface. We could simply move parts of the inline function in such a way that encryption_ctx_init() and encryption_ctx_finish() will be invoked at most once per mtr_t::commit() or recv_sys_t::parse():
static inline int encryption_crypt(const unsigned char* src, unsigned int slen,
|
unsigned char* dst, unsigned int* dlen,
|
const unsigned char* key, unsigned int klen,
|
const unsigned char* iv, unsigned int ivlen,
|
int flags, unsigned int key_id, unsigned int key_version)
|
{
|
void *ctx= alloca(encryption_ctx_size(key_id, key_version));
|
int res1, res2;
|
unsigned int d1, d2;
|
if ((res1= encryption_ctx_init(ctx, key, klen, iv, ivlen, flags, key_id, key_version)))
|
return res1;
|
res1= encryption_ctx_update(ctx, src, slen, dst, &d1);
|
res2= encryption_ctx_finish(ctx, dst + d1, &d2);
|
*dlen= d1 + d2;
|
return res1 ? res1 : res2;
|
}
|
If we invoked encryption_ctx_update() multiple times using the initialization vector that is derived from the unencrypted part of the log records, the format of the encrypted log would be changed in an incompatible way with MDEV-14425. We could call this new format innodb_encrypt_log=fast and distinguish it with a new redo log format code.
Attachment MDEV-36024.pdf
shows the effect. The red and blue lines show the behavior with encryption turned off. The green and pink line with innodb-encrypt-log=ON. The performance seen in the green line (pre
MDEV-14425) is about 7.5% lower at 20 threads (compared to unencrypted). However the performance seen in the pink line (MDEV-14425) is about 26% lower at 20 threads.The tested commits are
MDEV-14425from 21 Jan 2022 (red & green)The first release of the MariaDB server which includes this regression is 10.8.1.
The full regression test results, including Flamegraphs are available from http://g5.xentio.lan/benchmark-archive/MDEV-36024/ (Sofia VPN access required)