Skip to content

Keeper memory optimization by not holding snapshot in memory - #34584

Merged
alesapin merged 9 commits into
ClickHouse:masterfrom
bigo-sg:keerpSnapMemOpt
Feb 18, 2022
Merged

alesapin merged 9 commits into
ClickHouse:masterfrom
bigo-sg:keerpSnapMemOpt

Conversation

@zhanglistar

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Don't hold the latest snapshot in memory, instead, reading the snapshot if needed, sequence reading is fast to 200+MBps even on HDD using mmap system call.
Writing snapshot data directly to disk using compression method without holding original data and compressed data in memory.

Effect: about 20% saving memory
client command: ./utils/keeper-bench/keeper-bench --host=127.0.0.1:12183 -c 128 --generator=create_small_data
new version:
image

master version(34092fa):
image

@robot-clickhouse robot-clickhouse added the pr-performance Pull request with some performance improvements label Feb 14, 2022
@alesapin alesapin added the can be tested Allows running workflows for external contributors label Feb 15, 2022
@alesapin alesapin self-assigned this Feb 15, 2022
Comment thread src/Coordination/KeeperStateMachine.cpp Outdated
return -1;
}
data_out = nuraft::buffer::clone(*latest_snapshot_buf);
int fd = ::open(latest_snapshot_path.c_str(), O_RDONLY);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's move this code into separate function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@alesapin alesapin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In general LGTM.

Comment thread src/Coordination/KeeperStateMachine.cpp Outdated
LOG_WARNING(log, "Error opening {}.", latest_snapshot_path);
return -1;
}
auto file_size = ::lseek(fd, 0, SEEK_END);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is used only on Linux, not suitable for mac os x.

Comment thread src/Coordination/KeeperStateMachine.cpp Resolved
Comment thread src/Coordination/KeeperStateMachine.cpp Resolved
return -1;
}
data_out = nuraft::buffer::clone(*latest_snapshot_buf);
if (bufferFromFile(log, latest_snapshot_path, data_out))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Print errno?

@zhanglistar zhanglistar Feb 15, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Errno has been printed in the inner function.

@alesapin

alesapin commented Feb 17, 2022 •

Copy link
Copy Markdown
Member

test_keeper_restore_from_snapshot/test.py::test_recover_from_snapshot failure looks related to changes.
@zhanglistar Can you run this integration test locally?

@zhanglistar

zhanglistar commented Feb 17, 2022 •

Copy link
Copy Markdown
Contributor Author

test_keeper_restore_from_snapshot/test.py::test_recover_from_snapshot failure looks related to changes. @zhanglistar Can you run this integration test locally?

@alesapin Yes, I fix it now in cd0f7d5

Comment thread src/Coordination/KeeperStateMachine.cpp Resolved
@zhanglistar

Copy link
Copy Markdown
Contributor Author

@alesapin Thanks for your review, can merge now?

@alesapin

Copy link
Copy Markdown
Member

image
How is it possible not to merge?)

@alesapin
alesapin merged commit efb9a6d into ClickHouse:master Feb 18, 2022
@antonio2368 antonio2368 mentioned this pull request May 25, 2023
4 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-performance Pull request with some performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants