Skip to content

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

Signed-off-by: JaySon-Huang <jayson.hjs@gmail.com>
Signed-off-by: JaySon-Huang <jayson.hjs@gmail.com>
@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

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

@JaySon-Huang JaySon-Huang merged commit af17e0d into pingcap:master Feb 12, 2020
@JaySon-Huang JaySon-Huang deleted the FLASH-572 branch February 12, 2020 03:39
yongman added a commit to yongman/tiflash that referenced this pull request Jun 18, 2025
Signed-off-by: yongman <yming0221@gmail.com>
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