Jun
Jun
## PyObject_Malloc 我们再回到上一篇的`PyObject_Malloc`(`_PyObject_Alloc`)函数。 ```c static void * _PyObject_Alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize) { ... // 小块内存分配 if ((nbytes - 1) < SMALL_REQUEST_THRESHOLD) { // [A] 从 usedpools...
## 创建 ```c // 5.0.3/src/dict.c /* Create a new hash table */ dict *dictCreate(dictType *type, void *privDataPtr) { dict *d = zmalloc(sizeof(*d)); _dictInit(d,type,privDataPtr); return d; } /* Initialize the hash...
## 查找 ```c // 5.0.3/src/dict.c dictEntry *dictFind(dict *d, const void *key) { dictEntry *he; uint64_t h, idx, table; if (d->ht[0].used + d->ht[1].used == 0) return NULL; /* dict is empty...
## 添加 ```c // 5.0.3/src/dict.c /* Add an element to the target hash table */ int dictAdd(dict *d, void *key, void *val) { dictEntry *entry = dictAddRaw(d,key,NULL); if (!entry) return...
## 删除 ```c // 5.0.3/src/dict.c /* Search and remove an element. This is an helper function for * dictDelete() and dictUnlink(), please check the top comment * of those functions....
## 更新 ```c // 5.0.3/src/dict.c /* Add or Overwrite: * Add an element, discarding the old value if the key already exists. * Return 1 if the key was added...
## 渐进式 rehash 对大字典的 rehash 是比较耗时的,所以 Redis 中采用了渐进式的 rehash,将整个 rehash 过程所需的计算工作均摊到对字典的每个增删改查操作上。 在进行渐进式 rehash 的过程中,字典会同时使用 ht[0] 和 ht[1] 两个哈希表,所以在渐进式 rehash 进行期间,字典的删除、查找、更新等操作会在两个哈希表上进行。新添加到字典的键值对一律会被保存到 ht[1] 里面,而 ht[0] 则不再进行任何添加操作。 除了增删改查的操作外,Redis 还会定时对特殊的字典进行主动迁移,避免没有操作的情况下暂停 rehash。 ```c // 5.0.3/src/server.c...
@wenbochang888 其实重点是渐进式rehash的过程,每次保证rehash一个slot
> crontab 线程处理 rehash 没明白这个的意思?
@mozillazg 在线 demo 挂了