Skip to content

Commit

Permalink
delete tcmalloc in Pika (OpenAtomFoundation#1472)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixficsol authored and ForestLH committed May 10, 2023
1 parent 2df9bd2 commit 99f12bb
Show file tree
Hide file tree
Showing 13 changed files with 4 additions and 143 deletions.
12 changes: 2 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,9 @@ set(ZSTD_INCLUDE_DIR ${INSTALL_INCLUDEDIR})
ExternalProject_Add(fmt
DEPENDS
URL
https://github.com/fmtlib/fmt/archive/refs/heads/master.tar.gz
https://github.com/fmtlib/fmt/archive/refs/tags/7.1.0.tar.gz
URL_HASH
MD5=27e54411fce14de11624994b3ebf3c48
MD5=32af902636d373641f4ef9032fc65b3a
DOWNLOAD_NO_PROGRESS
1
UPDATE_COMMAND
Expand Down Expand Up @@ -467,14 +467,6 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(LIBGPERF_NAME gperftools)
endif()

if(${OS_VERSION} MATCHES "CentOS")
set(TCMALLOC_LIBRARY ${INSTALL_LIBDIR_64}/liblibtcmalloclz4.a)
else()
set(TCMALLOC_LIBRARY ${INSTALL_LIBDIR}/libtcmalloc.a)
endif()

set(TCMALLOC_INCLUDE_DIR ${INSTALL_INCLUDEDIR})

if(CMAKE_SYSTEM_NAME MATCHES "Linux")
ExternalProject_Add(jemalloc
DEPENDS
Expand Down
20 changes: 0 additions & 20 deletions detect_environment
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,6 @@ if test -z "$CXX"; then
CXX=g++
fi

# Test whether tcmalloc is available
if echo 'int main() {}' | $CXX $CFLAGS -x c++ - -o /dev/null \
-ltcmalloc 2>/dev/null; then
TCMALLOC_LDFLAGS=" -ltcmalloc"
fi

# Test whether malloc_extension is available
$CXX $CFLAGS -x c++ - -o /dev/null -ltcmalloc 2>/dev/null <<EOF
#include <gperftools/malloc_extension.h>
int main() {
MallocExtension::instance()->Initialize();;
return 0;
}
EOF
if [ "$?" = 0 ]; then
TCMALLOC_EXTENSION_FLAGS=" -DTCMALLOC_EXTENSION"
fi

# Test whether Snappy library is installed
# http://code.google.com/p/snappy/
$CXX $CFLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF
Expand Down Expand Up @@ -107,6 +89,4 @@ fi
PROCESSOR_NUMS=$(cat /proc/cpuinfo | grep processor | wc -l)

echo "ROCKSDB_LDFLAGS=$ROCKSDB_LDFLAGS" >> "$OUTPUT"
echo "TCMALLOC_EXTENSION_FLAGS=$TCMALLOC_EXTENSION_FLAGS" >> "$OUTPUT"
echo "TCMALLOC_LDFLAGS=$TCMALLOC_LDFLAGS" >> "$OUTPUT"
echo "PROCESSOR_NUMS=$PROCESSOR_NUMS" >> "$OUTPUT"
4 changes: 2 additions & 2 deletions docs/ops/bestPractice.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pika的性能和IO性能息息相关,我们不建议在机械盘上部署耗

**pika最佳实践之八:**

pika的内存占用主要集中在sst文件的cache和连接申请内存,而通常连接申请内存会比sst的cache要大很多,pika目前已支持连接申请内存的动态调整、回收,因此连接占用的总内存大小是可以粗略估算的,如果你的pika内存占用远超预估或大于10g,那么可能是内存泄漏了,尝试依次执行命令`client kill all``tcmalloc free`来对连接内存进行强制回收,如果效果不好请升级到最新版本
pika的内存占用主要集中在sst文件的cache和连接申请内存,而通常连接申请内存会比sst的cache要大很多,pika目前已支持连接申请内存的动态调整、回收,因此连接占用的总内存大小是可以粗略估算的,如果你的pika内存占用远超预估或大于10g,那么可能是内存泄漏了,尝试依次执行命令`client kill all``tcmalloc free`(tcmalloc目前已移除)来对连接内存进行强制回收,如果效果不好请升级到最新版本

**pika最佳实践之九:**

Expand Down Expand Up @@ -149,4 +149,4 @@ Pika从3.0.5开始提供了更细致的compact策略,该策略允许对key的
在建立主从的时候发现从库反复的进行全同步很可能是由于主库写入量太大,在全同步完毕期间清理掉了原先dumpdb时的binlog点位,导致从库在替换了db之后重新trysync发现点位又找不到,然后重新触发全同步,陷入了循环,这种场景下可以动态将主库的expire-logs-nums调大,让其保留尽量多的binlog, 建立主从成功之后再调节回来即可

---
_不断更新_
_不断更新_
3 changes: 0 additions & 3 deletions docs/ops/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,3 @@ $ make
```
$ ./output/bin/pika -c ./conf/pika.conf
```

## 注意
启动出现 Attempt to free invalid pointer 问题请尝试升级tcmalloc 版本,建议使用gperftools 2.7 版本包含的tcmalloc。
7 changes: 0 additions & 7 deletions docs/ops/memoryUsage.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
### Pika内存占用
1. rocksdb 内存占用
2. pika 内存占用(tcmalloc 占用)

#### 1. rocksdb 内存占用
命令行命令 info data
Expand All @@ -21,9 +20,3 @@ https://github.com/facebook/rocksdb/wiki/Setup-Options-and-Basic-Tuning

https://github.com/facebook/rocksdb/wiki/Memory-usage-in-RocksDB

#### 2. pika 内存占用
如果使用tcmalloc,绝大多数情况下是tcmalloc暂时占用内存。

命令行命令:tcmalloc stats

命令行命令:tcmalloc free 释放tcmalloc 占用内存
16 changes: 0 additions & 16 deletions include/pika_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,22 +388,6 @@ class PaddingCmd : public Cmd {
uint64_t offset) override;
};

#ifdef TCMALLOC_EXTENSION
class TcmallocCmd : public Cmd {
public:
TcmallocCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
virtual void Do(std::shared_ptr<Partition> partition = nullptr);
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new TcmallocCmd(*this); }

private:
int64_t type_;
int64_t rate_;
virtual void DoInitial() override;
};
#endif

class PKPatternMatchDelCmd : public Cmd {
public:
PKPatternMatchDelCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {}
Expand Down
3 changes: 0 additions & 3 deletions include/pika_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ const std::string kCmdNameEcho = "echo";
const std::string kCmdNameScandb = "scandb";
const std::string kCmdNameSlowlog = "slowlog";
const std::string kCmdNamePadding = "padding";
#ifdef TCMALLOC_EXTENSION
const std::string kCmdNameTcmalloc = "tcmalloc";
#endif
const std::string kCmdNamePKPatternMatchDel = "pkpatternmatchdel";
const std::string kCmdDummy = "dummy";
const std::string kCmdNameQuit = "quit";
Expand Down
2 changes: 0 additions & 2 deletions pika-tools/pika-port/pika_port_2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ THIRD_PATH = ../../third

# ROCKSDB_LDFLAGS= -lsnappy -lz -lbz2 -llz4 -lzstd
ROCKSDB_LDFLAGS= -lsnappy -lgflags -lz -lbz2
TCMALLOC_EXTENSION_FLAGS=
TCMALLOC_LDFLAGS=
PROCESSOR_NUMS=2

NEMO_PATH=$(THIRD_PATH)/nemo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ const std::string kCmdNameDbsize = "dbsize";
const std::string kCmdNameTime = "time";
const std::string kCmdNameDelbackup = "delbackup";
const std::string kCmdNameEcho = "echo";
#ifdef TCMALLOC_EXTENSION
const std::string kCmdNameTcmalloc = "tcmalloc";
#endif

// Migrate slot
const std::string kCmdNameSlotsMgrtSlot = "slotsmgrtslot";
Expand Down
3 changes: 0 additions & 3 deletions pika-tools/pika-port/pika_port_3/pika_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ const std::string kCmdNameDelbackup = "delbackup";
const std::string kCmdNameEcho = "echo";
const std::string kCmdNameScandb = "scandb";
const std::string kCmdNameSlowlog = "slowlog";
#ifdef TCMALLOC_EXTENSION
const std::string kCmdNameTcmalloc = "tcmalloc";
#endif

// Migrate slot
const std::string kCmdNameSlotsMgrtSlot = "slotsmgrtslot";
Expand Down
6 changes: 0 additions & 6 deletions src/pika.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
#include "include/pika_version.h"
#include "pstd/include/env.h"

#ifdef TCMALLOC_EXTENSION
# include <gperftools/malloc_extension.h>
#endif

PikaConf* g_pika_conf;
PikaServer* g_pika_server;
Expand Down Expand Up @@ -156,9 +153,6 @@ int main(int argc, char* argv[]) {
usage();
exit(-1);
}
#ifdef TCMALLOC_EXTENSION
MallocExtension::instance()->Initialize();
#endif
PikaConfInit(path);

rlimit limit;
Expand Down
64 changes: 0 additions & 64 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
#include "include/pika_version.h"
#include "pstd/include/rsync.h"

#ifdef TCMALLOC_EXTENSION
# include <gperftools/malloc_extension.h>
#endif

extern PikaServer* g_pika_server;
extern PikaConf* g_pika_conf;
extern PikaReplicaManager* g_pika_rm;
Expand Down Expand Up @@ -2226,66 +2222,6 @@ std::string PaddingCmd::ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t
argv_[1].size() + BINLOG_ITEM_HEADER_SIZE + PADDING_BINLOG_PROTOCOL_SIZE + SPACE_STROE_PARAMETER_LENGTH);
}

#ifdef TCMALLOC_EXTENSION
void TcmallocCmd::DoInitial() {
if (argv_.size() != 2 && argv_.size() != 3) {
res_.SetRes(CmdRes::kWrongNum, kCmdNameTcmalloc);
return;
}
rate_ = 0;
std::string type = argv_[1];
if (!strcasecmp(type.data(), "stats")) {
type_ = 0;
} else if (!strcasecmp(type.data(), "rate")) {
type_ = 1;
if (argv_.size() == 3) {
if (!pstd::string2int(argv_[2].data(), argv_[2].size(), &rate_)) {
res_.SetRes(CmdRes::kSyntaxErr, kCmdNameTcmalloc);
}
}
} else if (!strcasecmp(type.data(), "list")) {
type_ = 2;
} else if (!strcasecmp(type.data(), "free")) {
type_ = 3;
} else {
res_.SetRes(CmdRes::kInvalidParameter, kCmdNameTcmalloc);
return;
}
}

void TcmallocCmd::Do(std::shared_ptr<Partition> partition) {
std::vector<MallocExtension::FreeListInfo> fli;
std::vector<std::string> elems;
switch (type_) {
case 0:
char stats[1024];
MallocExtension::instance()->GetStats(stats, 1024);
pstd::StringSplit(stats, '\n', elems);
res_.AppendArrayLen(elems.size());
for (auto& i : elems) {
res_.AppendString(i);
}
break;
case 1:
if (rate_) {
MallocExtension::instance()->SetMemoryReleaseRate(rate_);
}
res_.AppendInteger(MallocExtension::instance()->GetMemoryReleaseRate());
break;
case 2:
MallocExtension::instance()->GetFreeListSizes(&fli);
res_.AppendArrayLen(fli.size());
for (auto& i : fli) {
res_.AppendString("type: " + std::string(i.type) + ", min: " + std::to_string(i.min_object_size) + ", max: " +
std::to_string(i.max_object_size) + ", total: " + std::to_string(i.total_bytes_free));
}
break;
case 3:
MallocExtension::instance()->ReleaseFreeMemory();
res_.SetRes(CmdRes::kOk);
}
}
#endif

void PKPatternMatchDelCmd::DoInitial() {
if (!CheckArg(argv_.size())) {
Expand Down
4 changes: 0 additions & 4 deletions src/pika_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ void InitCmdTable(std::unordered_map<std::string, Cmd*>* cmd_table) {
// Cluster related
Cmd* pkclusterinfoptr = new PkClusterInfoCmd(kCmdNamePkClusterInfo, -3, kCmdFlagsRead | kCmdFlagsAdmin);
cmd_table->insert(std::pair<std::string, Cmd*>(kCmdNamePkClusterInfo, pkclusterinfoptr));
#ifdef TCMALLOC_EXTENSION
Cmd* tcmallocptr = new TcmallocCmd(kCmdNameTcmalloc, -2, kCmdFlagsRead | kCmdFlagsAdmin);
cmd_table->insert(std::pair<std::string, Cmd*>(kCmdNameTcmalloc, tcmallocptr));
#endif

// Kv
////SetCmd
Expand Down

0 comments on commit 99f12bb

Please sign in to comment.