README.md 1.9 KB
Newer Older
R
russelltao 已提交
1 2 3 4 5 6 7 8
### 1 在栈中分配内存速度更快
heap_stack.java验证在栈中分配内存比堆中更快
#### 1.1 编译
javac heap_stack.java
#### 1.2 运行
java heap_stack
### 2 编译tcmalloc库
使用TCMalloc库前,需要下载编译它
R
russelltao 已提交
9 10 11 12
#### 预安装库
autoconf、automake、libtool
CentOS下安装:yum install autoconf automake libtool
Ubuntu下安装:apt-get install autoconf、automake、libtool
R
russelltao 已提交
13
#### 2.1 下载gperftool
R
russelltao 已提交
14
https://github.com/gperftools/gperftools.git
R
russelltao 已提交
15
#### 2.2 生成configure文件
R
russelltao 已提交
16
./autogen.sh
R
russelltao 已提交
17
#### 2.3 生成Makefile文件
R
russelltao 已提交
18 19 20 21
./configure

*配置选项通过--help查询*

R
russelltao 已提交
22
#### 2.4 编译
R
russelltao 已提交
23
make
R
russelltao 已提交
24
#### 2.5 安装
R
russelltao 已提交
25 26
make install

R
russelltao 已提交
27 28 29
### 3 benchmark性能测试
对比测试tcmalloc与ptmalloc2的性能
#### 3.1 编译benchmark文件
R
russelltao 已提交
30 31
g++ benchmark.cpp -o benchmark -lpthread

R
russelltao 已提交
32
#### 3.2 benchmark命令行选项
R
russelltao 已提交
33 34 35 36
1. -s: 分配内存块大小,单位字节
2. -t: 线程数
3. -n: 每个线程循环分配内存的次数

R
russelltao 已提交
37 38
#### 3.3 基于ptmalloc2测试

R
russelltao 已提交
39 40 41 42 43 44 45 46 47 48
##### 单线程分配256KB
export LD_PRELOAD=""; ./benchmark -s 262144 -t 1
##### 2线程分配256KB
export LD_PRELOAD=""; ./benchmark -s 262144 -t 2
##### 40线程分配256KB
export LD_PRELOAD=""; ./benchmark -s 262144 -t 40
##### 单线程分配256KB+1字节
export LD_PRELOAD=""; ./benchmark -s 262145 -t 1
##### 10线程分配256KB+1字节
export LD_PRELOAD=""; ./benchmark -s 262145 -t 10
R
russelltao 已提交
49

R
russelltao 已提交
50
#### 3.4 基于TcMalloc测试
R
russelltao 已提交
51
*根据configure生成的libtcmalloc.so文件的位置填写LD_PRELOAD*
R
russelltao 已提交
52 53 54 55 56 57 58 59 60 61
##### 单线程分配256KB
export LD_PRELOAD="/lib64/libtcmalloc.so"; ./benchmark -s 262144 -t 1
##### 2线程分配256KB
export LD_PRELOAD="/lib64/libtcmalloc.so"; ./benchmark -s 262144 -t 2
##### 40线程分配256KB
export LD_PRELOAD="/lib64/libtcmalloc.so"; ./benchmark -s 262144 -t 40 
##### 单线程分配256KB+1字节
export LD_PRELOAD="/lib64/libtcmalloc.so"; ./benchmark -s 262145 -t 1
##### 10线程分配256KB+1字节
export LD_PRELOAD="/lib64/libtcmalloc.so"; ./benchmark -s 262145 -t 10 -n 100000