contributed by <Shaoyu-Chen
>
為了讓程式有更好的可讀性,避免放置一堆 #define
,目前實做介面如下:
void *init();
void *readFile(void *);
void *append(char [], void *);
void *findName(char [], void *);
void memory_free(void *);
size of entry : 136 bytes
execution time of append() : 0.077778 +- 0.000892 sec
execution time of findName() : 0.004927 +- 0.000030 sec
(95% 信賴區間)
Performance counter stats for './phonebook_orig' (100 runs):
2,010,723 cache-misses #87.332% of all cache refs ( +- 0.13% )
2,302,381 cache-references ( +- 0.07% )
387,959,515 instructions #1.51 insns per cycle ( +- 0.01% )
256,717,122 cycles ( +- 0.13% )
0.070331387 seconds time elapsed ( +- 1.31% )
假設: 若將所有 lastName 放置於一連續記憶體會提昇整體效能。
實做:
typedef struct __PHONE_BOOK_ENTRY {
char *lastName;
struct __PHONE_BOOK_DETAIL *pDetail;
struct __PHONE_BOOK_ENTRY *pNext;
} entry;
結果: 相對原版 append 時間減少了 0.03 秒,但相對重要的 findName 時間卻增加了 0.001 秒
size of entry : 24 bytes
execution time of append() : 0.043081 +- 0.000606 sec
execution time of findName() : 0.006310 +- 0.000031 sec
(95% 信賴區間)
假設: 將各 entry 其 lastName 放置連續空間能夠提昇搜尋效能
實做:
typedef struct __PHONE_BOOK_ENTRY {
char lastName[MAX_LAST_NAME_SIZE];
struct __PHONE_BOOK_DETAIL *pDetail;
struct __PHONE_BOOK_ENTRY *pNext;
} entry;
結果: 相對原版 append 時間減少 0.02 秒,且 findName 時間減少 0.0015 秒
size of entry : 32 bytes
execution time of append() : 0.057684 +- 0.000508 sec
execution time of findName() : 0.003563 +- 0.000017 sec
(95% 信賴區間)
需要用統計方法,取出 95% 信賴區間,最好還能用 perf 分析效能 hotspot jserv
收到!Shaoyu-Chen
echo 3 > /proc/sys/vm/drop_caches
(to free pagecache, dentries and *inodes),否則因為 page cache 的原因,append 時間會因為不須真正做 I/O 而加速很多static struct Pool_Cont
{
struct Entry_Pool *pHead;
struct Entry_Pool *pCurrent;
struct Entry_Pool *pTail;
} ppool_cont;
static struct Entry_Pool
{
uint64_t bitmap;
entry *pPool;
struct Entry_Pool *pNext;
};
size of entry : 32 bytes
execution time of append() : 0.072752 +- 0.000958 sec
execution time of findName() : 0.003801 +- 0.000018 sec
(95% 信賴區間)
Source of this article: https://hackmd.io/s/BJlPwHmA