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

[FLASH-572] Use jemalloc instead of tcmalloc by default #424

Merged
merged 11 commits into from
Feb 12, 2020

Conversation

JaySon-Huang
Copy link
Contributor

@JaySon-Huang JaySon-Huang commented Feb 10, 2020

  • Possible tcmalloc have bugs and make tiflash stuck to refuse connections. We have happened to to this twice
  • Clickhouse use jemalloc instead of tcmalloc, since jemalloc have better performance without tuning special params. And tcmalloc is no longer supported. Using jemalloc instead of tcmalloc. ClickHouse/ClickHouse#2773

This PR

  • Port contrib/jemalloc,contrib/jemalloc-cmake from clickhouse and use jemalloc under Linux by default
  • Use tcmalloc under MacOS by default (jemalloc will cause compile error under MacOS)
  • Fix bugs: use after free
    • TMTContext should be free before background_pool.
      Some background handlers need to be removed in TMTContext's BackgroundService and Storages
      Context.cpp:L148
    • Use of invalid iterator in AlterCommand
      AlterCommands.cpp:L186

@JaySon-Huang
Copy link
Contributor Author

/run-integration-tests

@JaySon-Huang
Copy link
Contributor Author

/run-integration-tests

2 similar comments
@JaySon-Huang
Copy link
Contributor Author

/run-integration-tests

@JaySon-Huang
Copy link
Contributor Author

/run-integration-tests

Copy link
Contributor

@ilovesoup ilovesoup left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -137,8 +141,10 @@ StorageDeltaMerge::StorageDeltaMerge(const String & path_,
void StorageDeltaMerge::drop()
{
shutdown();
#if USE_TCMALLOC
// Reclaim memory.
MallocExtension::instance()->ReleaseFreeMemory();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why jemalloc does not need this?

Copy link
Contributor Author

@JaySon-Huang JaySon-Huang Feb 11, 2020

Choose a reason for hiding this comment

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

For tcmalloc, clickhouse have to tune "tcmalloc.aggressive_memory_decommit" to be false to get better performance.
This piece of code is just for tcmalloc, after drop table, remind tcmalloc to reclaim free memory, or it acts like to be leak. See ClickHouse/ClickHouse#1742 for details.

But with jemalloc, no tuning is required:

When using jemalloc, there are no such issues even ** without any tuning. **
Some queries will run faster up to 20%.
Memory usage (RSS) is about 10% lower and is more stable.

@JaySon-Huang
Copy link
Contributor Author

/run-integration-tests

@JaySon-Huang
Copy link
Contributor Author

/run-integration-tests

3 similar comments
@JaySon-Huang
Copy link
Contributor Author

/run-integration-tests

@JaySon-Huang
Copy link
Contributor Author

/run-integration-tests

@JaySon-Huang
Copy link
Contributor Author

/run-integration-tests

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.

2 participants